:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --ink: #1d2233;
  --muted: #667088;
  --line: #e1e4ee;
  --accent: #4263eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --ok: #2b8a3e;
  --ok-soft: #e3f6e8;
  --warn: #b35c00;
  --warn-soft: #fff1dc;
  --danger: #c92a2a;
  --danger-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(20, 30, 70, 0.06), 0 4px 16px rgba(20, 30, 70, 0.05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --card: #1b1e29;
    --ink: #e9ebf3;
    --muted: #9aa3ba;
    --line: #2d3245;
    --accent: #748ffc;
    --accent-ink: #10131f;
    --accent-soft: #252c4d;
    --ok: #69db7c;
    --ok-soft: #1c3324;
    --warn: #ffa94d;
    --warn-soft: #3a2b16;
    --danger: #ff8787;
    --danger-soft: #3d2124;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
a { color: var(--accent); }

.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 120px; }
.wrap.wide { max-width: 980px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease; }
button:active { transform: scale(0.95); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span.lbl { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }

input[type='text'], input[type='password'], input[type='number'], input[type='datetime-local'], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 42px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type='number'].num { width: 84px; text-align: center; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--line); color: var(--muted); }

.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s ease; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  max-width: calc(100vw - 32px);
  background: #232838;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: #b02a2a; }
.toast.toast-success { background: #2b8a3e; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 90;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.q-image { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 12px; cursor: zoom-in; object-fit: contain; background: var(--bg); }
