:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f1f4; --border: #e2e4e9; --border-strong: #c9ccd4;
  --text: #16181d; --text-2: #5b606b; --text-3: #8a8f99;
  --accent: #2f6fde; --accent-bg: #e7effc; --on-accent: #ffffff;
  --ok: #1d7a46; --ok-bg: #e3f4ea; --warn: #8a5a00; --warn-bg: #fdf1d8; --bad: #b42318; --bad-bg: #fde8e6;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --tabbar-h: 56px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121418; --surface: #1b1e24; --surface-2: #23272f; --border: #2c3039; --border-strong: #3c414c;
  --text: #eceef2; --text-2: #a7acb6; --text-3: #7c818b;
  --accent: #5b93f0; --accent-bg: #1d2a44; --on-accent: #0d1220;
  --ok: #57c78a; --ok-bg: #16301f; --warn: #f0b952; --warn-bg: #352812; --bad: #f2776b; --bad-bg: #3a1a17;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ── Karkas ─────────────────────────────── */
#app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.top h1 { margin: 0; font-size: 17px; font-weight: 600; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; line-height: 1; display: grid; place-items: center;
}
#view { padding: 14px 16px; max-width: 1280px; margin: 0 auto; }
.loading, .empty { color: var(--text-3); text-align: center; padding: 40px 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--text-3); font-size: 10px; position: relative;
}
.tabbar button .ic { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.tabbar button.on .ic { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 5px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; line-height: 16px; font-weight: 600;
}

.side { display: none; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .main { padding-bottom: 24px; }
  .side {
    display: flex; flex-direction: column; gap: 2px; width: 200px; flex: none; padding: 14px 10px;
    background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh;
  }
  .side .brand { font-weight: 600; padding: 4px 10px 14px; }
  .side button {
    display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 9px 10px;
    border-radius: 8px; color: var(--text-2); text-align: left; font-size: 13px; position: relative;
  }
  .side button.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
  .side .badge { position: static; margin-left: auto; }
}

/* ── Elementlar ─────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.tiny { font-size: 11px; color: var(--text-3); }
.section-title { font-size: 12px; color: var(--text-2); margin: 16px 2px 8px; font-weight: 600; letter-spacing: .02em; }
.section-title:first-child { margin-top: 2px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 600px) { .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; text-align: left; }
.metric b { display: block; font-size: 22px; font-weight: 600; line-height: 1.2; }
.metric span { font-size: 12px; color: var(--text-2); }
.metric.hot b { color: var(--bad); }
button.metric { width: 100%; }

.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 9px;
  padding: 7px 12px; font-size: 13px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; padding: 10px; }
.btn:active { transform: scale(.98); }

input.field, select.field, textarea.field {
  width: 100%; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px;
  padding: 7px 9px; min-width: 0; outline: none;
}
input.field:focus, select.field:focus { border-color: var(--accent); }
label.lbl { display: block; font-size: 11px; color: var(--text-2); margin-bottom: 3px; }

.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 8px; border-radius: 7px; font-size: 13px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 12px; }
.chip.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.gray { background: var(--surface-2); color: var(--text-2); }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.full i { background: var(--ok); }

/* ── Vazifa yuklash ─────────────────────── */
.upload-defaults { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.urow { border: 1px solid var(--border); border-radius: 9px; padding: 8px; display: grid; gap: 6px; background: var(--surface); }
.urow.blank { border-style: dashed; }
.urow .top-line { display: grid; grid-template-columns: minmax(0, 1fr) 64px 28px; gap: 6px; }
.urow .link-line { display: flex; gap: 6px; align-items: center; }
.urow .x { border: 0; background: none; color: var(--text-3); font-size: 18px; padding: 0; }
@media (min-width: 900px) {
  .urow { grid-template-columns: 170px minmax(0, 1fr) 64px 92px 24px; align-items: center; padding: 6px 8px; }
  .urow .top-line, .urow .link-line { display: contents; }
  .urow .theme { order: 1; } .urow .link { order: 2; } .urow .lim { order: 3; } .urow .st { order: 4; } .urow .x { order: 5; }
  .uhead { display: grid !important; grid-template-columns: 170px minmax(0, 1fr) 64px 92px 24px; gap: 6px; padding: 0 9px; }
}
.uhead { display: none; font-size: 11px; color: var(--text-3); }

.tasks-layout { display: grid; gap: 14px; }
@media (min-width: 1100px) { .tasks-layout.two { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; } }

/* ── Vazifa kartasi ─────────────────────── */
.task { display: grid; gap: 7px; }
.task .head { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--text-3); }
.task .stats { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.task .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.edit-box { display: grid; grid-template-columns: minmax(0, 1fr) 80px auto; gap: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 900px) { .toast { bottom: 24px; } }

.gate { max-width: 420px; margin: 18vh auto 0; text-align: center; padding: 0 20px; }
.gate .big { font-size: 42px; }

/* ── So'rovlar, foydalanuvchi kartasi, oynalar ── */
.gated .side { display: none !important; }
.list-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 7px 10px; text-align: left;
}
.facts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); margin: 6px 0 2px; }
.warn-t { color: var(--warn); font-weight: 600; }
.bad-t { color: var(--bad); font-weight: 600; }
.alert { border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert a { color: inherit; font-weight: 600; }
.card-num { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.file-btn { display: inline-block; text-align: center; color: var(--text-2); border-style: dashed; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.receipt img { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.req-grid { display: grid; gap: 10px; }
@media (min-width: 1100px) { .req-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
.set-row { display: grid; gap: 4px; }
textarea.field { resize: vertical; }

body.noscroll { overflow: hidden; }
.sheet-bg {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  position: relative; background: var(--bg); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { .sheet-bg { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-x { position: sticky; top: 0; float: right; margin-left: 8px; }
.full-img { max-width: 100%; display: block; margin: 28px auto 0; border-radius: 8px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 28px; }
.compare img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
