:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #1d2320; --muted: #66706b; --line: #e2e5e1;
  --accent: #2f6b45; --accent-ink: #ffffff; --accent-soft: #e6f0e9; --danger: #b3261e;
  --radius: 8px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Georgian", "BPG Arial", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 var(--font); color: var(--ink); background: var(--bg); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 17px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: #c5cbc6; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 8px; }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--ink); font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 13px; }
label.check input { width: auto; margin: 0; }
label.inline { display: flex; align-items: center; gap: 6px; margin: 0; }
label.inline select { width: auto; margin: 0; }
.pad { padding-top: 22px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 4px 0; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.row2 > * { min-width: 0; }
[hidden] { display: none !important; }

/* auth */
#auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.auth-card button { width: 100%; margin-top: 8px; padding: 9px; }

/* top bar */
.top { display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 52px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--accent); }
.brand img { height: 34px; width: auto; display: block; }
.brand span { padding-left: 8px; border-left: 1px solid var(--line); letter-spacing: .04em; }
.auth-logo { display: block; height: 72px; width: auto; margin: 0 auto 10px; }
.auth-card h1 { text-align: center; font-size: 18px; letter-spacing: .06em; color: var(--muted); }
#tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
#tabs button { border: 0; background: none; padding: 16px 12px; border-radius: 0; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
#tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.who { white-space: nowrap; font-size: 13px; }

/* layout */
.tab { padding: 16px 20px; }
.tab.narrow { max-width: 860px; }
#tab-target { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; position: sticky; top: 68px; max-height: calc(100vh - 84px); overflow: auto; }
.filters-head { display: flex; justify-content: space-between; align-items: baseline; }
fieldset { min-width: 0; border: 0; border-top: 1px solid var(--line); margin: 0; padding: 10px 0 4px; }
legend { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { margin: 0; }
.chips input { display: none; }
.chips span { display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); font-size: 13px; cursor: pointer; }
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }

/* multi-select */
.ms { position: relative; margin-bottom: 8px; }
.ms > .ms-label { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.ms > button.ms-btn { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 6px; }
.ms > button.ms-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms > button.ms-btn.set { border-color: var(--accent); background: var(--accent-soft); }
.ms-pop { position: absolute; z-index: 20; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; }
.ms-pop input[type=search] { margin-bottom: 6px; }
.ms-opts { max-height: 240px; overflow: auto; }
.ms-opts label { display: flex; gap: 6px; align-items: flex-start; color: var(--ink); font-size: 13px; margin: 0; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.ms-opts label:hover { background: var(--bg); }
.ms-opts input { width: auto; margin: 2px 0 0; }
.ms-opts em { margin-left: auto; color: var(--muted); font-style: normal; font-size: 11px; }
.ms-pop .ms-foot { display: flex; justify-content: space-between; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 6px; }

/* results */
.results { min-width: 0; }
.results-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; }
.stat b { display: block; font-size: 18px; }
.stat small { color: var(--muted); }
.inline-save { display: flex; gap: 6px; align-items: center; }
.inline-save input { width: 260px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfa; position: sticky; top: 0; white-space: nowrap; }
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: #f3f6f3; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td small { display: block; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-right: 3px; }
.tag.el { background: #e8eef8; color: #2d4f8a; }
.nophone { color: var(--muted); font-style: italic; }

/* sales */
.sales-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.sales-bar input[type=search] { flex: 1; min-width: 220px; width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; padding: 6px 14px; }
.seg button.on { background: var(--accent); color: #fff; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 0; }
.pager span { margin-right: auto; }

/* dialogs */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 30, 25, .35); }
dialog form, #custDlg { padding: 0; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.dlg-head h2 { margin: 0; }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; flex-wrap: wrap; }
.spacer { flex: 1; }
.cust-search { padding: 14px 20px 0; position: relative; }
.hits { position: absolute; left: 20px; right: 20px; z-index: 5; list-style: none; margin: -6px 0 0; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow: auto; }
.hits li { padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.hits li:hover, .hits li.on { background: var(--accent-soft); }
.hits small { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 14px; padding: 8px 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label.req::after { content: " *"; color: var(--danger); }
#custBody { padding: 16px 20px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kv div small { display: block; color: var(--muted); font-size: 11px; }

/* lists */
.lists { list-style: none; padding: 0; }
.lists li { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; }
.lists li .grow { flex: 1; min-width: 0; }
.lists li small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 16px; }
.auth-card form, .auth-card [data-view] { margin: 0; }
.auth-card .switch { text-align: center; font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.auth-card .switch button.link, .auth-card [data-view=message] button.link { width: auto; padding: 0; margin: 0; }
.auth-card .resend { display: block; width: 100%; text-align: center; margin-top: 10px; }
.auth-card [data-view=message] p { margin: 4px 0 16px; }
.outbox-note { margin: 18px 0 0; padding: 8px 10px; background: #fff7e0; border: 1px solid #f0dfa8; border-radius: 6px; font-size: 12px; color: #6b5a1e; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #d97706; color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #eef0ee; color: var(--muted); white-space: nowrap; }
.pill.on { background: var(--accent-soft); color: var(--accent); }
.pill.wait { background: #fff1d6; color: #9a5b00; }
.pill.off { background: #fbe9e7; color: var(--danger); }
button.sm { padding: 3px 9px; font-size: 12px; margin: 2px 0; }
td.acts { white-space: normal; min-width: 220px; }
#userTable tbody tr { cursor: default; }
#userTable tbody tr:hover { background: none; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 100; }

@media (max-width: 860px) {
  #tab-target { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; }
  .top { gap: 10px; padding: 0 12px; }
  .tab { padding: 12px; }
  .who #whoName { display: none; }
}
