:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #637083;
  --line: #e2e7ee;
  --nav: #0f2a44;
  --nav-text: #c9d6e3;
  --nav-active: #1d4f7c;
  --primary: #1f6fb2;
  --primary-soft: #e6f0f9;
  --red: #d64545;
  --red-soft: #fdecec;
  --green: #2f9e5b;
  --green-soft: #e7f6ed;
  --yellow: #d99a00;
  --yellow-soft: #fff6dc;
  --gray: #7b8794;
  --gray-soft: #eef1f4;
  --blue: #1f6fb2;
  --blue-soft: #e6f0f9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--nav); color: var(--nav-text); padding: 16px 12px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; color: #fff; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: #f59e0b; display: grid;
  place-items: center; font-weight: 700; color: #0f2a44; flex: none;
}
.brand-text { font-size: 12px; line-height: 1.3; }
.brand-text b { display: block; font-size: 13px; }
.nav-link {
  display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px;
  color: var(--nav-text); text-decoration: none !important;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--nav-active); color: #fff; }
.nav-icon { width: 18px; text-align: center; opacity: .9; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; padding: 14px 12px 4px; }
.sidebar-foot { margin-top: auto; font-size: 11px; opacity: .6; padding: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 20px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 900;
}
.topbar h1 { font-size: 18px; margin-right: auto; }
.menu-toggle { display: none; }
.periods { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px;
  cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.custom-dates { display: none; gap: 4px; align-items: center; }
.custom-dates.show { display: flex; }
.profile { display: flex; gap: 8px; align-items: center; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700;
}
.profile-name { font-size: 12px; line-height: 1.2; }
.profile-name small { color: var(--muted); display: block; }

.filterbar {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); align-items: center;
}
.filterbar label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.filterbar select { min-width: 150px; }
.period-label { font-size: 12px; color: var(--muted); margin-left: auto; }

.content { padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 18px; }
.banner { padding: 10px 14px; border-radius: 8px; font-weight: 600; }
.banner.demo { background: #fde68a; color: #7c2d12; text-align: center; }
.banner.offline { background: var(--red-soft); color: var(--red); }

/* ---------- controls ---------- */
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  border: 1px solid #cfd6df; border-radius: 7px; padding: 6px 9px; background: #fff; min-height: 32px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #9cc3e6; outline-offset: 1px; }
.btn {
  border: 1px solid #cfd6df; background: #fff; border-radius: 7px; padding: 6px 12px; cursor: pointer;
  display: inline-flex; gap: 6px; align-items: center; min-height: 32px; text-decoration: none !important;
  color: var(--text);
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--red); }
.btn.small { padding: 3px 8px; min-height: 26px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.panel-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin-right: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px;
  border-left: 4px solid var(--gray); cursor: pointer; text-align: left; border-top: 0; border-right: 0; border-bottom: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.card:hover { box-shadow: 0 4px 12px rgba(16, 24, 40, .12); }
.card .value { font-size: 26px; font-weight: 700; }
.card .label { font-size: 12px; color: var(--muted); }
.card.red { border-left-color: var(--red); } .card.red .value { color: var(--red); }
.card.green { border-left-color: var(--green); } .card.green .value { color: var(--green); }
.card.yellow { border-left-color: var(--yellow); } .card.yellow .value { color: #a87700; }
.card.gray { border-left-color: var(--gray); }
.card.blue { border-left-color: var(--blue); } .card.blue .value { color: var(--blue); }

.rates { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.rate { padding: 12px 14px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.rate .value { font-size: 22px; font-weight: 700; }
.rate .bar { height: 6px; border-radius: 3px; background: var(--gray-soft); margin: 8px 0 6px; overflow: hidden; }
.rate .bar > span { display: block; height: 100%; background: var(--primary); }
.rate.good .bar > span { background: var(--green); } .rate.bad .bar > span { background: var(--red); }
.rate details { font-size: 11px; color: var(--muted); }
.rate summary { cursor: pointer; }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 380px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: #fafbfc; position: sticky; top: 0; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--primary); }
table.data tbody tr:hover { background: #f8fafc; }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--gray-soft); color: #4b5563; white-space: nowrap;
}
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: #8a6200; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 10px; }

.empty, .error-box, .loading { padding: 28px; text-align: center; color: var(--muted); }
.error-box { color: var(--red); }
.loading::after { content: " ⏳"; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: #fff; cursor: pointer; text-align: left; }
.tab b { display: block; font-size: 18px; }
.tab.active { border-color: var(--primary); box-shadow: inset 0 -3px 0 var(--primary); }
.tab.red b { color: var(--red); } .tab.green b { color: var(--green); } .tab.yellow b { color: #a87700; }

/* ---------- map ---------- */
.map-layout { display: grid; grid-template-columns: 1fr 320px; gap: 12px; }
.map { height: 520px; border-radius: 8px; border: 1px solid var(--line); z-index: 1; }
.map.full { height: calc(100vh - 260px); min-height: 460px; }
.map-side { max-height: 520px; overflow-y: auto; }
.map-side .mfy-row { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; cursor: pointer; gap: 8px; }
.map-side .mfy-row:hover, .map-side .mfy-row.active { background: var(--primary-soft); }
.legend { background: #fff; padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow); font-size: 12px; line-height: 1.6; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.sq { border-radius: 2px; }
.mfy-label { background: rgba(255, 255, 255, .85); border: 0; box-shadow: none; font-weight: 600; font-size: 11px; padding: 1px 4px; }
.map-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .4); z-index: 2000; display: flex; justify-content: flex-end; }
.drawer { background: #fff; width: min(620px, 100%); height: 100%; overflow-y: auto; padding: 20px; }
.modal-center { align-items: center; justify-content: center; }
.modal { background: #fff; width: min(520px, 94vw); border-radius: 12px; padding: 20px; max-height: 90vh; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 4px 0 12px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.check { flex-direction: row !important; align-items: center; gap: 6px !important; color: var(--text) !important; }

.toast {
  position: fixed; right: 16px; bottom: 16px; background: #1f2933; color: #fff; padding: 10px 14px;
  border-radius: 8px; z-index: 3000; max-width: 360px; box-shadow: var(--shadow);
}
.toast.error { background: var(--red); }
.reasons { margin: 0; padding-left: 16px; }
.reasons li { color: var(--red); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0f2a44, #1f6fb2); padding: 16px; }
.login-box { background: #fff; padding: 28px; border-radius: 14px; width: min(380px, 100%); box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.login-box h1 { font-size: 18px; margin-bottom: 4px; }
.login-box p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .map-layout { grid-template-columns: 1fr; }
  .map-side { max-height: 300px; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 2500; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 16px; }
  .filterbar, .content { padding-left: 12px; padding-right: 12px; }
  .filterbar select { min-width: 0; width: 100%; }
  .filterbar label { flex: 1 1 45%; }
  .map, .map.full { height: 420px; }
  .kv { grid-template-columns: 1fr; }
  .profile-name { display: none; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  .sidebar, .topbar, .filterbar { display: none; }
  .layout { display: block; }
}

/* Statistikadan ochiladigan murojaatlar ro'yxati */
.drawer.wide { width: min(1180px, 100%); }
.drill-head { margin: 8px 0 12px; gap: 6px; flex-wrap: wrap; }
.drill-total { font-weight: 700; font-size: 15px; }
.count-link { background: none; border: 0; padding: 0 2px; font: inherit; color: var(--primary, #1f6fb2); text-decoration: underline dotted; cursor: pointer; }
.count-link:hover { text-decoration: underline; }
.count-link .badge { cursor: pointer; }
.rate.clickable, .mfy-stat tr.clickable { cursor: pointer; }
.rate.clickable:hover { box-shadow: 0 0 0 2px rgba(31, 111, 178, .35); }
.rate-links { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
