:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --top: #0f172a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #243045;
    --primary: #3b82f6;
    --top: #020617;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 96px;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0.25rem 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.text-danger { color: var(--danger); }
.pad { padding: 12px 16px; margin: 0; }

/* --- верхняя панель --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--top); color: #fff;
  padding: 8px 16px;
}
.brand { color: #fff; font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: #cbd5e1; padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 0.95rem; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.logout { display: flex; align-items: center; gap: 8px; margin: 0; }
.logout .muted { color: #94a3b8; }
@media (max-width: 640px) {
  .nav { order: 3; flex-basis: 100%; }
  .logout { margin-left: auto; }
}

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 480px; }

/* --- карточки, списки --- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.stack { display: flex; flex-direction: column; gap: 12px; padding: 16px; margin: 12px 0; }
.list { overflow: hidden; }
.list-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); color: inherit;
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: rgba(127,127,127,0.06); }
.list-row > :first-child { flex: 1 1 140px; }
.list-extra { flex-basis: 100%; font-size: 0.9rem; display: flex; flex-direction: column; gap: 4px; }
.row-link { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; margin-bottom: 8px; color: inherit; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 24px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* --- формы --- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=file], select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.checklist { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin: 0; }
.checklist legend { color: var(--muted); font-size: 0.9rem; padding: 0 4px; }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; padding: 8px 0; }
.check input { width: 22px; height: 22px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.filters > * { flex: 1 1 160px; width: auto; }
.filters .btn { flex: 0 0 auto; }

/* --- кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-lg { padding: 14px 18px; font-size: 1.05rem; }
.btn-xl { width: 100%; padding: 18px; font-size: 1.15rem; margin: 8px 0; }
.btn-block { width: 100%; margin-top: 8px; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,0.25); z-index: 20;
}

/* --- статусы --- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--border); color: var(--text); white-space: nowrap; }
.badge-lg { font-size: 0.95rem; padding: 6px 14px; }
.badge-new { background: #e0e7ff; color: #3730a3; }
.badge-in_progress, .badge-open { background: #fef3c7; color: #92400e; }
.badge-done, .badge-ok { background: #dcfce7; color: #166534; }
.badge-defect { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: var(--border); color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: inherit; }
.stat-v { font-size: 1.6rem; font-weight: 700; }
.stat-l { color: var(--muted); font-size: 0.85rem; }
.stat-done .stat-v { color: var(--success); }
.stat-defect .stat-v { color: var(--danger); }
.stat-in_progress .stat-v { color: var(--warn); }

.progress { display: inline-block; width: 90px; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.progress > span { display: block; height: 100%; background: var(--success); }

.alert { padding: 12px 16px; border-radius: 10px; margin: 0 0 12px; border: 1px solid transparent; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #e0f2fe; color: #075985; margin: 8px 0; }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:last-child td { border-bottom: 0; }
.tabs { display: flex; gap: 6px; margin: 8px 0 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); color: inherit; font-size: 0.9rem; }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0; }

/* --- карточка дрона --- */
.drone-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drone-head h1 { font-size: 1.6rem; margin: 0; }
.action { padding: 16px; margin: 16px 0; }
.action h2 { margin: 2px 0 6px; font-size: 1.3rem; }
.instructions { background: var(--bg); border-radius: 10px; padding: 12px; margin: 8px 0; font-size: 0.95rem; }
.plan { list-style: none; padding: 0; margin: 0; counter-reset: plan; }
.plan li { counter-increment: plan; padding: 8px 0 8px 40px; position: relative; color: var(--muted); }
.plan li::before {
  content: counter(plan); position: absolute; left: 0; top: 6px;
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700;
}
.plan-done { color: var(--text) !important; }
.plan-done::before { content: "✓" !important; background: var(--success); border-color: var(--success) !important; color: #fff; }
.plan-current { color: var(--text) !important; font-weight: 700; }
.plan-current::before { border-color: var(--primary) !important; color: var(--primary); }
.thumb { max-width: 160px; max-height: 120px; border-radius: 8px; margin-top: 4px; }
.qr-preview { width: 160px; height: 160px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }

/* --- сканер --- */
.reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 60px; }
.reader video { width: 100% !important; display: block; }

.login { max-width: 400px; margin: 10vh auto 0; }
.login h1 { text-align: center; }
.login > p { text-align: center; }
