/* COMPHOUSE სამუშაოები */
:root {
  color-scheme: light;
  --ground: #F3F4F1;
  --surface: #FFFFFF;
  --ink: #15181C;
  --ink-2: #3F454C;
  --muted: #596069;
  --line: #E1E3DE;
  --line-2: #F0F1EE;
  --control: #D5D8D2;
  --soft: #FAFAF8;

  --y-bg: #FEE2E2; --y-ink: #B91C1C; --y-line: #FCA5A5; /* წამოსაღები — წითელი */
  --b-bg: #FEF3C7; --b-ink: #92400E; --b-solid: #FACC15; --b-line: #FDE68A; --b-on: #422006; /* მისატანი — ყვითელი */
  --link: #1D4ED8;
  --g-bg: #DCFCE7; --g-ink: #166534; --g-solid: #15803D;

  --new-bg: #F3EEFF; --new-line: #DDD0FB; --new-ink: #5B21B6; --new-mark: #7C3AED;
  --old-bg: #EFF6FF; --old-line: #BFDBFE; --old-ink: #1E40AF; --old-mark: #2563EB;

  --danger: #B91C1C;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --bottom-h: calc(140px + var(--safe-b));
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea, select { font-size: 16px; } /* iPhone ზუმს არ აკეთებს */
a { color: var(--link); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }

.page { max-width: 640px; margin: 0 auto; padding-bottom: calc(var(--bottom-h) + 24px); min-height: 100vh; }
.page.no-composer { padding-bottom: calc(80px + var(--safe-b) + 24px); }

/* ---------- ჰედერი ---------- */
.top { padding: calc(14px + var(--safe-t)) 16px 12px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.brand { font-size: 12px; font-weight: 700; letter-spacing: .14em; color: var(--muted); }
h1 { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.15; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 6px 10px; border-radius: 999px; border: 0;
  background: var(--g-bg); color: var(--g-ink); white-space: nowrap; min-height: 32px; font-weight: 600; }
.sync.offline { background: #E7E9E4; color: var(--muted); font-weight: 500; }
.sync.error, .sync.auth { background: #FEE2E2; color: var(--danger); }
.sync svg { flex-shrink: 0; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- სტატისტიკა / ფილტრები ---------- */
.stats { padding: 4px 16px 10px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { border-radius: 14px; padding: 10px 10px 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  border: 2px solid transparent; min-height: 64px; }
.stat b { font-size: 24px; line-height: 1.1; display: flex; align-items: center; gap: 4px; }
.stat span { font-size: 11px; }
.stat.all { background: var(--surface); border-color: var(--line); }
.stat.all span { color: var(--muted); }
.stat.y { background: var(--y-bg); color: var(--y-ink); }
.stat.b { background: var(--b-bg); color: var(--b-ink); }
.stat.g { background: var(--g-bg); color: var(--g-ink); }
.stat[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }

.zones { padding: 0 16px 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.zone-btn { height: 56px; border-radius: 14px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1.5px solid; }
.zone-btn .zl { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; text-align: left; line-height: 1.2; }
.zone-btn b { font-size: 18px; }
.zone-btn.new { background: var(--new-bg); border-color: var(--new-line); color: var(--new-ink); }
.zone-btn.old { background: var(--old-bg); border-color: var(--old-line); color: var(--old-ink); }
.zone-btn.new[aria-pressed="true"] { border: 2.5px solid var(--new-mark); }
.zone-btn.old[aria-pressed="true"] { border: 2.5px solid var(--old-mark); }

.filterbar { margin: 0 16px 10px; padding: 6px 6px 6px 14px; background: var(--ink); color: #fff; border-radius: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.filterbar button { height: 36px; border: 0; border-radius: 9px; background: #2A2F35; color: #fff; padding: 0 12px; font-weight: 600; font-size: 13px; }

/* ---------- სია ---------- */
.list { padding: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.zone-h { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 0; }
.zone-h h2 { margin: 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.zone-h.new h2 { color: var(--new-ink); }
.zone-h.old h2 { color: var(--old-ink); }
.zone-h small { font-size: 12px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px 2px 4px; }
.card-h .name { border: 0; background: none; padding: 8px 10px; font-size: 17px; font-weight: 700; text-align: left; display: flex; align-items: center; gap: 6px; min-height: 44px; }
.card-h .date { font-size: 12px; color: var(--muted); white-space: nowrap; padding-right: 6px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-top: 1px solid var(--line-2); }
.row .body { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; border: 0; background: none; padding: 2px 0; text-align: left; }
.row .text { font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.meta .price { font-weight: 600; color: var(--ink); }
.pill { padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.pill.y { background: var(--y-bg); color: var(--y-ink); }
.pill.b { background: var(--b-bg); color: var(--b-ink); }
.pill.g { background: var(--g-bg); color: var(--g-ink); }
.pill.k { background: #EEF0EC; color: var(--ink-2); }
.st-btn { width: 48px; height: 48px; flex-shrink: 0; border-radius: 14px; display: flex; align-items: center; justify-content: center; padding: 0; }
.st-btn.y { border: 1.5px solid var(--y-line); background: var(--y-bg); color: var(--y-ink); }
.st-btn.b { border: 0; background: var(--b-solid); color: var(--b-on); }
.st-btn.g { border: 0; background: var(--g-solid); color: #fff; }
.more { width: 100%; min-height: 46px; border: 0; border-top: 1px solid var(--line-2); background: var(--soft); display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 14px; font-size: 14px; font-weight: 600; }
.more .sum { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.more.less { justify-content: center; color: var(--muted); font-size: 13px; min-height: 44px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 15px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

/* ---------- ქვედა ზოლი ---------- */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 10; }
.bottom-in { max-width: 640px; margin: 0 auto; }
.composer { display: flex; gap: 8px; padding: 12px 16px; margin: 0; }
.composer input { flex-grow: 1; min-width: 0; height: 50px; border-radius: 14px; border: 1.5px solid var(--control); background: var(--ground); padding: 0 14px; }
.composer input::placeholder { color: #6B7178; }
.composer button { width: 50px; height: 50px; flex-shrink: 0; border-radius: 14px; border: 0; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line-2); padding: 4px 8px calc(4px + var(--safe-b)); }
.tabs button { height: 52px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 500; }
.tabs button[aria-current="page"] { color: var(--ink); font-weight: 700; }

/* ---------- ბარათის ეკრანი ---------- */
.nav { padding: calc(8px + var(--safe-t)) 8px 4px; display: flex; align-items: center; justify-content: space-between; }
.back { height: 44px; padding: 0 8px; border: 0; background: none; display: flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 12px; }
.client-h { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.client-h h1 { overflow-wrap: anywhere; }
.client-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; color: var(--muted); }
.ztag { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.ztag.new { color: var(--new-ink); } .ztag.old { color: var(--old-ink); } .ztag.unknown { color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip-btn { height: 40px; padding: 0 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); font-size: 14px; font-weight: 600; }
.section-t { margin: 18px 2px 8px; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .03em; display: flex; justify-content: space-between; align-items: center; }

.job { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.job-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.job-h .t { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.ref { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; }
.fact { background: var(--ground); padding: 4px 10px; border-radius: 8px; font-size: 13px; }
.fact span { color: var(--muted); }
.timeline { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--ink-2); }
.timeline .on { color: var(--ink); }
.timeline .off { color: #8A9097; }
.actions { display: flex; gap: 8px; }
.btn { height: 48px; border-radius: 12px; border: 1.5px solid var(--control); background: var(--surface); padding: 0 14px; font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.grow { flex-grow: 1; }
.btn.primary { background: var(--ink); color: #fff; border: 0; }
.btn.blue { background: var(--b-solid); color: var(--b-on); border: 0; }
.btn.green { background: var(--g-solid); color: #fff; border: 0; }
.btn.yellow { background: var(--y-bg); color: var(--y-ink); border: 1.5px solid var(--y-line); }
.btn.danger { color: var(--danger); }
.btn.ghost { border: 0; background: transparent; color: var(--ink-2); text-decoration: underline; }
.btn.block { width: 100%; }
.add-row { display: flex; gap: 8px; margin: 12px 0 0; }
.add-row input { flex-grow: 1; min-width: 0; height: 48px; border-radius: 12px; border: 1.5px dashed #C9CDC6; background: transparent; padding: 0 14px; }
.add-row button { width: 48px; height: 48px; border-radius: 12px; border: 0; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.log { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.45; }
.log div { overflow-wrap: anywhere; }
.hist-row { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; text-align: left; width: 100%; }
.hist-row .t { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.hist-row .c { font-size: 13px; color: var(--ink-2); }

/* ---------- ისტორია / კლიენტები ---------- */
.search { padding: 0 16px 10px; }
.search input { width: 100%; height: 48px; border-radius: 12px; border: 1.5px solid var(--control); background: var(--surface); padding: 0 14px; }
.chips { padding: 0 16px 12px; display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip { height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.day-h { font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 2px 0; }
.client-row { width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 56px; }
.client-row .n { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.client-row .s { font-size: 12px; color: var(--muted); }

/* ---------- ფურცელი (sheet) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(21,24,28,.45); z-index: 30; animation: fade .15s ease-out; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(20px + var(--safe-b)); max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 12px; max-width: 640px; margin: 0 auto; animation: up .18s ease-out; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--control); align-self: center; flex-shrink: 0; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.sheet p { margin: 0; color: var(--ink-2); line-height: 1.5; }
.sheet .sub { font-size: 13px; color: var(--muted); }
.big { min-height: 64px; border-radius: 16px; border: 0; padding: 10px 16px; display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; }
.big .l { display: flex; flex-direction: column; gap: 2px; }
.big .l b { font-size: 17px; }
.big .l span { font-size: 13px; }
.big.blue { background: var(--b-solid); color: var(--b-on); } .big.blue .l span { color: #713F12; }
.big.green { background: var(--g-solid); color: #fff; } .big.green .l span { color: #F0FDF4; }
.big.yellow { background: var(--y-bg); color: var(--y-ink); border: 1.5px solid var(--y-line); }
.big.plain { background: var(--surface); border: 1.5px solid var(--control); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--ink-2); }
.field input, .field textarea { height: 48px; border-radius: 12px; border: 1.5px solid var(--control); background: var(--surface); padding: 0 14px; width: 100%; }
.field textarea { height: 84px; padding: 10px 14px; resize: vertical; }
.opt { font-size: 14px; font-weight: 700; }
.opt span { font-weight: 500; color: var(--muted); }
.zone-pick { height: 56px; border-radius: 14px; font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px solid; }
.zone-pick.new { background: var(--new-bg); border-color: var(--new-line); color: var(--new-ink); }
.zone-pick.old { background: var(--old-bg); border-color: var(--old-line); color: var(--old-ink); }
.zone-pick.new[aria-pressed="true"] { border: 2.5px solid var(--new-mark); }
.zone-pick.old[aria-pressed="true"] { border: 2.5px solid var(--old-mark); }
.preview { background: var(--ground); border-radius: 14px; padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; }
.err { color: var(--danger); font-size: 13px; }
.choice { width: 100%; min-height: 52px; border-radius: 14px; border: 1.5px solid var(--control); background: var(--surface); padding: 8px 14px; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------- შეტყობინება ---------- */
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--bottom-h) + 10px); z-index: 40; max-width: 616px; margin: 0 auto;
  background: var(--ink); color: #fff; border-radius: 14px; padding: 6px 6px 6px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; animation: up .18s ease-out; }
.sheet-open .toast { display: none; }
.toast span { font-size: 14px; line-height: 1.35; padding: 8px 0; }
.toast button { height: 44px; padding: 0 14px; border-radius: 10px; border: 0; background: #2A2F35; color: #FDE68A; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.page.no-composer ~ * .toast, .toast.low { bottom: calc(80px + var(--safe-b) + 10px); }

/* ---------- შესვლა ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(60px + var(--safe-t)) 20px 40px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { margin-bottom: -8px; }

@keyframes up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
@media (min-width: 700px) { .page { padding-top: 12px; } }

/* ჩამოწევით განახლება */
.ptr { position: fixed; top: calc(var(--safe-t) - 44px); left: 50%; width: 42px; height: 42px; margin-left: -21px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 2px 12px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center;
  z-index: 25; opacity: 0; color: var(--muted); pointer-events: none; transition: transform .25s ease, opacity .25s ease; }
.ptr.pulling { transition: none; }
.ptr.ready { color: var(--g-solid); }
.ptr.busy { color: var(--g-solid); }
.ptr.busy svg { animation: spin .9s linear infinite; }
