/* ── Abonent panel ───────────────────────────────────────────── */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --gold: #f59e0b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #121a2b;
    --surface-2: #182238;
    --border: #24304a;
    --text: #e8edf7;
    --muted: #94a3b8;
    --accent: #60a5fa;
    --accent-soft: #1e3a8a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--accent); }

/* ── layout ── */
.wrap { max-width: 1400px; margin: 0 auto; padding: 20px 20px 60px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; }
.brand .dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.topbar .spacer { flex: 1; }
.topbar .muted { color: var(--muted); font-size: 13px; }

/* ── cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); margin-bottom: 18px; }
.cols-2 { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 980px) { .cols-2 { grid-template-columns: 1fr; } }

.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.accent .value { color: var(--accent); }
.kpi.success .value { color: var(--success); }

/* ── controls ── */
button, .btn {
  font: inherit; cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 7px;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--accent); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
button:disabled { opacity: .45; cursor: not-allowed; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13.5px; }
.seg button.on { background: var(--accent); color: #fff; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; resize: vertical; margin-top: 10px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; }
.ok { color: var(--success); font-size: 13px; margin-top: 8px; }
.ok code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* ── employees ── */
.people { display: grid; gap: 8px; max-height: 420px; overflow: auto; }
.person { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.person.pending { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.person.blocked { opacity: .6; }
.person .who b { display: block; font-size: 14px; }
.person .who span { color: var(--muted); font-size: 12.5px; }
.person .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.person .acts button, .person .acts select { padding: 5px 9px; font-size: 12.5px; border-radius: 8px; }
.person .nums { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* ── mahalla chips ── */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips .chip { display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.chips .chip button { border: none; background: transparent; padding: 0 2px;
  color: var(--muted); font-size: 13px; line-height: 1; }
.chips .chip button:hover { color: var(--danger); background: transparent; }
.chips .chip i { font-style: normal; color: var(--muted); font-size: 11.5px;
  font-variant-numeric: tabular-nums; }
.chips .chip.off { opacity: .55; border-style: dashed; }

/* ── territory tree: district › sector › mahalla ── */
.tree { margin-top: 14px; display: grid; gap: 10px; }
.tree .node { border: 1px solid var(--border); border-radius: 12px; }
.tree .district > summary { list-style: none; cursor: pointer; padding: 11px 13px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tree .district > summary::-webkit-details-marker { display: none; }
.tree .district > summary::before { content: '▸'; color: var(--muted); }
.tree .district[open] > summary::before { content: '▾'; }
.tree .district > summary b { font-size: 14.5px; }
.tree .node.off { border-style: dashed; opacity: .7; }
.tree .sector { margin: 0 13px 10px; padding: 10px 12px; background: var(--surface-2); }
.tree .sector .head { display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 8px; }
.tree .muted { color: var(--muted); font-size: 12.5px; }
.tree .acts { margin-left: auto; display: flex; gap: 6px; }
.tree .acts button { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.tree .addrow { display: flex; gap: 7px; margin-top: 9px; }
.tree .addrow input { flex: 1; padding: 6px 10px; font-size: 13px; }
.tree .addrow button { padding: 6px 11px; font-size: 13px; }
.tree .sector-add { margin: 0 13px 13px; }

/* ── inline record editing ── */
.edit-grid { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px 14px;
  align-items: center; font-size: 14px; }
.edit-grid label { color: var(--muted); }
.edit-grid input, .edit-grid select { width: 100%; }
.edit-grid .bad input, .edit-grid .bad select { border-color: var(--danger); }
.edit-grid .fieldrow { display: contents; }
.edit-grid .msg { grid-column: 1 / -1; color: var(--danger); font-size: 12.5px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.filters .wide { grid-column: span 2; }
@media (max-width: 700px) { .filters .wide { grid-column: span 1; } }

/* ── table ── */
.table-scroll { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  text-align: left; font-weight: 600; color: var(--muted);
  padding: 10px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: var(--accent-soft);
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
}
.tag.gray { background: var(--surface-2); color: var(--muted); }
.tag.ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }

/* ── rating ── */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 4px; border-bottom: 1px dashed var(--border);
}
.rank li:last-child { border-bottom: none; }
.rank .place {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--surface-2); color: var(--muted);
}
.rank li:nth-child(1) .place { background: color-mix(in srgb, var(--gold) 25%, transparent); color: var(--gold); }
.rank li:nth-child(2) .place { background: color-mix(in srgb, #94a3b8 25%, transparent); color: #94a3b8; }
.rank li:nth-child(3) .place { background: color-mix(in srgb, #b45309 22%, transparent); color: #b45309; }
.rank .who { flex: 1; min-width: 0; }
.rank .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .who span { color: var(--muted); font-size: 12.5px; }
.rank .cnt { font-weight: 700; font-variant-numeric: tabular-nums; }
.rank .bar { height: 5px; border-radius: 999px; background: var(--accent); opacity: .85; margin-top: 5px; }

/* ── chart ── */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.chart .bar {
  width: 100%; border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent));
  min-height: 3px; transition: height .3s;
}
.chart .col .n { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart .col .d { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.chart .col.today .bar { background: linear-gradient(180deg, var(--success), color-mix(in srgb, var(--success) 45%, transparent)); }

.breakdown { display: grid; gap: 10px; }
.breakdown .row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.breakdown .track { grid-column: 1 / -1; height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.breakdown .fill { height: 100%; background: var(--accent); border-radius: 999px; }

/* ── modal ── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 6, 23, .55);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.open { display: flex; }
.modal .sheet {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  width: min(680px, 100%); max-height: 88vh; overflow: auto; padding: 22px;
}
.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; word-break: break-word; }
.modal img.shot { width: 100%; border-radius: 12px; margin-top: 14px; border: 1px solid var(--border); }

/* ── login ── */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: var(--bg);
}
.login .sheet { width: min(380px, 100%); text-align: center; }
.login .sheet .dot { margin: 0 auto 14px; width: 46px; height: 46px; font-size: 22px; }
.login input { width: 100%; margin: 16px 0 10px; text-align: center; }
.login button { width: 100%; justify-content: center; }
.login .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 13.5px; }
.hidden { display: none !important; }
