/* ============================================================================
   ls.com.ge — ადმინ-პანელი
   ============================================================================ */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #5b6372;
  --muted-2: #8a92a1;
  --acc: #1f6fd1;
  --acc-ink: #ffffff;
  --acc-soft: #e7f0fc;
  --inc-ink: #0b7a43;
  --exp-ink: #b8430f;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --ok-soft: #e5f6ec;
  /* ჩარტი: შემოსავალი — ლურჯი, ხარჯი — ნარინჯისფერი (validated pair) */
  --s-inc: #2a78d6;
  --s-exp: #eb6834;
  --grid: #e9ebef;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111214;
    --surface: #1a1a19;
    --surface-2: #212224;
    --border: #2e3034;
    --text: #f0efec;
    --muted: #b4b6bd;
    --muted-2: #8a8d95;
    --acc: #4c93ea;
    --acc-ink: #0d1117;
    --acc-soft: #1b2a3e;
    --inc-ink: #4cc98a;
    --exp-ink: #f29a6e;
    --danger: #ff6b6b;
    --danger-soft: #3a1d1d;
    --warn: #f0b84a;
    --warn-soft: #3a2e14;
    --ok-soft: #173326;
    --s-inc: #3987e5;
    --s-exp: #d95926;
    --grid: #2a2c30;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Noto Sans Georgian", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
h1 { font-size: 1.25rem; margin: 6px 0 4px; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: .95rem; margin: 0 0 10px; }
a { color: var(--acc); }

/* ─── ეკრანები (შესვლა და სხვ.) ─── */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.narrow { width: 100%; max-width: 380px; padding: 28px 24px; }
.brand-logo { width: 52px; height: 52px; display: block; margin-bottom: 8px; }

/* ─── ფორმები ─── */
.field { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
.field > span { font-size: .78rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  background: var(--acc); color: var(--acc-ink); border-radius: 8px; padding: 8px 14px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-full { width: 100%; justify-content: center; margin-top: 8px; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: .95rem; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.msg { padding: 9px 12px; border-radius: 8px; font-size: .85rem; margin: 10px 0; }
.msg.err { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--acc-soft); color: var(--text); }

/* ─── ზედა ზოლი ─── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; max-width: 1280px; margin: 0 auto; }
.hdr-logo { width: 30px; height: 30px; }
.hdr-title { font-weight: 800; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); min-width: 0; }
.user-chip #userEmail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.role-tag { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--acc-soft); color: var(--acc); }
@media (max-width: 640px) { .user-chip #userEmail { display: none; } .hdr-title { display: none; } }

.tabs { display: flex; gap: 2px; padding: 0 12px; max-width: 1280px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { font: inherit; font-weight: 600; font-size: .85rem; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 10px 12px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--acc); border-bottom-color: var(--acc); }

main { max-width: 1280px; margin: 0 auto; padding: 18px 16px 60px; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── ფილტრები ─── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: .72rem; font-weight: 600; color: var(--muted); }
.filters input, .filters select { width: auto; min-width: 130px; padding: 6px 8px; font-size: .85rem; }
.filters .grow { flex: 1; min-width: 180px; }
.filters .grow input { width: 100%; }

/* ─── სტატ-ბარათები ─── */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 14px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .lbl { font-size: .76rem; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 1.45rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.stat .sub { font-size: .74rem; color: var(--muted-2); margin-top: 2px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; margin-top: 12px; }
.two-col > * { min-width: 0; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ─── ცხრილები ─── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .72rem; text-transform: none; font-weight: 700; color: var(--muted); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.act { text-align: right; white-space: nowrap; width: 1%; }
td.nowrap { white-space: nowrap; }
tfoot td { font-weight: 800; background: var(--surface-2); }
.inc { color: var(--inc-ink); font-weight: 700; }
.exp { color: var(--exp-ink); font-weight: 700; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.desc-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.b-inc { background: var(--ok-soft); color: var(--inc-ink); border-color: transparent; }
.badge.b-exp { background: var(--warn-soft); color: var(--exp-ink); border-color: transparent; }
.badge.b-paid { background: var(--ok-soft); color: var(--inc-ink); border-color: transparent; }
.badge.b-sent { background: var(--acc-soft); color: var(--acc); border-color: transparent; }
.badge.b-late { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.b-cancel { text-decoration: line-through; }

.summary-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: .85rem; margin: 10px 2px 0; color: var(--muted); }
.summary-row b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ─── ჩარტი ─── */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis { fill: var(--muted-2); font-size: 11px; font-family: inherit; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit.on { fill: var(--surface-2); }
.tip { position: fixed; z-index: 100; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 8px 10px; font-size: .8rem; min-width: 150px; }
.tip .t-h { font-weight: 700; margin-bottom: 4px; }
.tip .t-r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .t-r b { font-variant-numeric: tabular-nums; }
.tip .t-r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* ─── ფანჯარა (modal) ─── */
.modal-bg { position: fixed; inset: 0; background: rgba(10,12,16,.5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 6px 18px 14px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

.items-table td { padding: 5px 6px; border-bottom: 0; }
.items-table input { padding: 6px 8px; }
.items-table .c-qty { width: 90px; }
.items-table .c-price { width: 120px; }
.items-table .c-sum { width: 110px; }
.inv-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: .88rem; margin-top: 8px; }
.inv-totals .grand { font-size: 1.1rem; font-weight: 800; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }

.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar-fill { height: 100%; border-radius: 4px; }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.list-plain li:last-child { border-bottom: 0; }

.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.help { font-size: .8rem; color: var(--muted); line-height: 1.6; }
.actions select { width: auto; }
.chart svg { max-width: 100%; }

/* ─── დოკუმენტები ─── */
.drop { border: 1px dashed var(--border); border-radius: 10px; padding: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--surface-2); }
.drop.over { border-color: var(--acc); background: var(--acc-soft); }
.att-list { width: 100%; display: flex; flex-direction: column; gap: 4px; }
.att-list:empty { display: none; }
.att { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px 4px 10px; font-size: .85rem; min-width: 0; }
.att-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-m { font-size: .75rem; white-space: nowrap; }
button.badge { font: inherit; font-size: .72rem; }
