:root {
  --bg: #0f1115;
  --bg-card: #181b22;
  --bg-card-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --good: #3ecf8e;
  --bad: #ff5c7c;
  --warn: #ffb648;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #14171e, #0f1115);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; color: var(--accent); }
.title { font-weight: 700; font-size: 18px; }
.subtitle { color: var(--muted); font-size: 12px; }
.controls { display: flex; align-items: center; gap: 16px; }
.range button, .tabs button {
  background: var(--bg-card); color: var(--muted); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.range button.active, .tabs button.active { color: #fff; border-color: var(--accent); background: #1d2738; }
.range button + button { margin-left: 6px; }
.health { font-size: 16px; color: var(--muted); }
.health.live { color: var(--good); }
.health.stale { color: var(--bad); }
.export a { margin-left: 10px; font-size: 12px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; }
.mini-btn { margin-left: 10px; font-size: 12px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg-card); color: var(--text); cursor: pointer; }
.mini-btn:hover { border-color: var(--accent); }
.mobile-btn { background: #1d2738; color: #fff; border: 1px solid var(--accent); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.lang-sel { max-width: 120px; }
.device-sel { background: var(--bg-card); color: #fff; border: 1px solid var(--accent); padding: 6px 10px; border-radius: 8px; font-size: 13px; max-width: 220px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px; width: min(420px, 92vw); position: relative; text-align: center; }
.modal-box h3 { margin: 0 0 14px; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal .qr { width: 220px; height: 220px; background: #fff; border-radius: 10px; padding: 8px; }
.modal .link { word-break: break-all; font-size: 12px; color: var(--accent); margin: 12px 0 4px; }
.modal .token { font-family: monospace; font-size: 13px; color: var(--text); background: #20242d; padding: 6px 10px; border-radius: 6px; display: inline-block; margin-top: 6px; }
.modal .muted { color: var(--muted); font-size: 13px; }
.modal .warn { color: var(--warn); font-size: 13px; margin-top: 10px; }
.copy-btn { margin-top: 12px; background: #1d2738; color: #fff; border: 1px solid var(--accent); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }

/* admin modal */
.admin-box { text-align: left; width: min(620px, 95vw); max-height: 86vh; overflow-y: auto; }
.adm-row { display: grid; grid-template-columns: 16px 1fr 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid #21252e; }
.adm-row input { background: #20242d; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 13px; width: 100%; }
.adm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.adm-dot.on { background: var(--good); } .adm-dot.off { background: #555; }
.adm-seen { font-size: 11px; color: var(--muted); }
.adm-btn { font-size: 12px; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text); cursor: pointer; }
.adm-btn.del { border-color: var(--bad); color: var(--bad); }
.admin-purge { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.admin-purge h4 { margin: 0 0 6px; font-size: 13px; }
.admin-purge input { background: #20242d; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 10px; width: 110px; }
.audit { max-height: 200px; overflow-y: auto; font-size: 12px; }
.audit-row { padding: 5px 0; border-bottom: 1px solid #21252e; color: var(--text); }
.audit-meta { color: var(--muted); font-size: 11px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 18px 22px; }
.kpi { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.good .value { color: var(--good); }
.kpi.bad .value { color: var(--bad); }
.kpi.accent .value { color: var(--accent); }

/* tabs */
.tabs { display: flex; gap: 8px; padding: 0 22px 8px; }

/* panels */
main { padding: 8px 22px 40px; }
.panel { display: none; }
.panel.active { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.chartbox { position: relative; height: 300px; }
.chartbox canvas { position: absolute; inset: 0; }
.hint { color: var(--muted); font-size: 12px; margin: -6px 0 10px; }

/* fleet (hub umumiy ko'rinish) */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.fleet-card { background: var(--bg-card-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.fleet-card:hover { border-color: var(--accent); }
.fleet-card .fc-top { display: flex; align-items: center; gap: 8px; }
.fleet-card .fc-dot { width: 9px; height: 9px; border-radius: 50%; background: #555; flex: 0 0 auto; }
.fleet-card .fc-dot.on { background: var(--good); box-shadow: 0 0 7px var(--good); }
.fleet-card .fc-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fleet-card .fc-grp { color: var(--muted); font-size: 11px; }
.fleet-card .fc-stats { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; }
.fleet-card .fc-prod { font-weight: 700; }

/* goals */
.goal { margin-bottom: 12px; }
.goal:last-child { margin-bottom: 0; }
.goal-h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; color: var(--muted); }
.goal .track { height: 9px; background: #21252e; border-radius: 5px; overflow: hidden; }
.goal .track > i { display: block; height: 100%; border-radius: 5px; transition: width .3s; }

/* apps table */
.apps-table { width: 100%; border-collapse: collapse; }
.apps-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.apps-table td { padding: 8px 6px; border-bottom: 1px solid #21252e; vertical-align: middle; }
.apps-table tr:hover td { background: var(--bg-card-2); }
.cat-pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #232938; color: var(--muted); }
.bar-cell { width: 30%; }
.bar { height: 8px; border-radius: 4px; background: var(--accent); }

/* heatmap */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 14px); gap: 3px; overflow-x: auto; padding-bottom: 8px; }
.heatmap .cell { width: 14px; height: 14px; border-radius: 3px; background: #1c2029; }
.heatmap .cell.l1 { background: #0e4429; }
.heatmap .cell.l2 { background: #006d32; }
.heatmap .cell.l3 { background: #26a641; }
.heatmap .cell.l4 { background: #39d353; }
/* activity hafta×soat heatmap */
.acth { overflow-x: auto; }
.acth-grid { display: grid; grid-template-columns: 38px repeat(24, 1fr); gap: 3px; min-width: 600px; }
.acth-hh { font-size: 10px; color: var(--muted); text-align: center; }
.acth-wd { font-size: 11px; color: var(--muted); display: flex; align-items: center; }
.acth-cell { height: 16px; border-radius: 3px; background: #1c2029; }
.acth-cell.l1 { background: #0e4429; } .acth-cell.l2 { background: #006d32; }
.acth-cell.l3 { background: #26a641; } .acth-cell.l4 { background: #39d353; }

.heat-legend { color: var(--muted); font-size: 12px; margin-top: 10px; display: flex; align-items: center; gap: 4px; }
.hl { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.hl0 { background: #1c2029; } .hl1 { background: #0e4429; } .hl2 { background: #006d32; }
.hl3 { background: #26a641; } .hl4 { background: #39d353; }

.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 20px; border-top: 1px solid var(--border); word-break: break-word; }

/* ============ RESPONSIVE (planshet/telefon) ============ */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; position: static; }
  .controls { width: 100%; flex-wrap: wrap; gap: 8px 10px; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); padding: 14px 16px; }
  .tabs { padding: 0 16px 8px; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs button { white-space: nowrap; }
  main { padding: 8px 16px 40px; }
}
@media (max-width: 620px) {
  .topbar { padding: 10px 12px; }
  .brand .subtitle { display: none; }
  .logo { font-size: 24px; }
  .title { font-size: 16px; }
  .device-sel { flex: 1 1 100%; max-width: 100%; }
  .range { display: flex; flex: 1 1 100%; }
  .range button { flex: 1; }
  .range button + button { margin-left: 6px; }
  .export { display: flex; flex-wrap: wrap; gap: 6px; }
  .export a, .mini-btn, .mobile-btn { margin-left: 0; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 20px; }
  main { padding: 8px 12px 36px; }
  .card { padding: 14px 12px; }
  .chartbox { height: 260px; }
  /* jadval: kamroq muhim ustunlarni yashiramiz */
  .apps-table .bar-cell { display: none; }
  .apps-table th:nth-child(4), .apps-table td:nth-child(4) { display: none; }
  /* admin qatorini moslashtiramiz */
  .adm-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
  .adm-row .adm-name, .adm-row .adm-group { flex: 1 1 42%; min-width: 0; }
  .adm-btn { flex: 0 0 auto; }
  /* modal kengligi */
  .modal-box, .admin-box { width: 94vw; padding: 18px 16px; }
  .modal .qr { width: 200px; height: 200px; }
}
@media (max-width: 380px) {
  /* KPI 2 ustun qoladi (1fr 1fr) — 620px qoidasidan meros; faqat juda tor uchun font kichrayadi */
  .tabs button, .range button { font-size: 12px; padding: 6px 9px; }
  .kpi .value { font-size: 18px; }
}
@media (max-width: 300px) {
  .kpis { grid-template-columns: 1fr; }
}

/* ============ PRINT / PDF ============ */
@media print {
  .topbar, .tabs, .foot, .modal { display: none !important; }
  .panel { display: none !important; }
  .panel.active { display: block !important; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  main { padding: 0 !important; }
  .kpis { padding: 0 0 10px !important; }
  .card { break-inside: avoid; page-break-inside: avoid; }
  .chartbox { height: 300px; }
  @page { margin: 12mm; }
}
