:root {
  --brand: #0F6E56; --brand-dark: #085041; --brand-tint: #E1F5EE;
  --bg: #F6F5F1; --card: #FFFFFF; --text: #1E1E1C; --muted: #6B6A65; --line: #DEDCD3;
  --ok: #3B6D11; --ok-bg: #EAF3DE; --warn: #854F0B; --warn-bg: #FAEEDA;
  --danger: #A32D2D; --danger-bg: #FCEBEB; --info: #185FA5; --info-bg: #E6F1FB;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #5DCAA5; --brand-dark: #9FE1CB; --brand-tint: #04342C;
    --bg: #161615; --card: #232321; --text: #F1EFE8; --muted: #B4B2A9; --line: #3A3A37;
    --ok: #C0DD97; --ok-bg: #27500A; --warn: #FAC775; --warn-bg: #633806;
    --danger: #F7C1C1; --danger-bg: #791F1F; --info: #B5D4F4; --info-bg: #0C447C;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Ethiopic", sans-serif; }
.app { max-width: 480px; margin: 0 auto; padding: 16px 16px 88px; min-height: 100vh; }
.app.wide { max-width: 960px; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 17px; margin: 20px 0 8px; font-weight: 600; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.mt { margin-top: 16px; }
.hidden, [hidden] { display: none !important; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
button:hover, .btn:hover { border-color: var(--muted); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary, .btn.primary { color: #04342C; } }
button.block, .btn.block { display: flex; width: 100%; }
button.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; }
button.small, .btn.small { padding: 6px 10px; min-height: 36px; font-size: 14px; }
button[disabled] { opacity: .6; cursor: default; }

input, select, textarea { font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); min-height: 44px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field + .field { margin-top: 12px; }
.error { color: var(--danger); font-size: 14px; margin-top: 6px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card + .card { margin-top: 10px; }
.card.highlight { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px; border: 0; border-radius: 0; background: none;
  text-align: left; justify-content: flex-start; color: var(--text); text-decoration: none; min-height: 48px; }
.list > * + * { border-top: 1px solid var(--line); }
.list > button:hover, .list > a:hover { background: var(--brand-tint); }
.list-head { font-size: 13px; color: var(--muted); padding: 8px 14px; background: var(--bg); min-height: 0; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge.in_stock, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.low, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ask, .badge.neutral { border-color: var(--line); color: var(--muted); }
.badge.rx { background: var(--warn-bg); color: var(--warn); }
.badge.otc { background: var(--ok-bg); color: var(--ok); }
.badge.controlled, .badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.banner { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.banner.info { background: var(--info-bg); color: var(--info); }

.topbar { display: flex; align-items: center; gap: 8px; margin: -4px 0 12px; }
.topbar h1 { font-size: 18px; margin: 0; }
.back { border: 0; background: none; font-size: 22px; padding: 4px 10px 4px 0; min-height: 40px; color: var(--text); }
.brand { color: var(--brand); font-weight: 700; font-size: 24px; letter-spacing: -.3px; }
.hero { text-align: center; padding: 32px 0 16px; }
.hero .brand { font-size: 40px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; min-height: 36px; }
.chip[aria-pressed=true] { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-dark); }
select.chip { width: auto; padding-right: 28px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { text-align: left; justify-content: flex-start; min-height: 56px; }

.map { width: 100%; display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.map .road { stroke: var(--line); stroke-width: 6; fill: none; }
.map .pin { cursor: pointer; stroke: var(--card); stroke-width: 2; }
.map .pin.in_stock { fill: #3B8F3B; } .map .pin.low { fill: #D9902B; } .map .pin.ask { fill: #8A8982; }
.map .pin.closed { opacity: .45; }
.map .me { fill: #2F7FD6; stroke: var(--card); stroke-width: 3; }
.map text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 6px 2px 12px; flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.in_stock { background: #3B8F3B; } .dot.low { background: #D9902B; } .dot.ask { background: #8A8982; } .dot.me { background: #2F7FD6; }

.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 84%; padding: 8px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--brand-tint); border-color: transparent; }
.msg.system { align-self: center; max-width: 100%; background: none; border: 0; color: var(--muted); font-size: 13px; text-align: center; }
.msg.system.emergency { background: var(--danger-bg); color: var(--danger); font-weight: 600; border-radius: 10px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg img { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; }
.msg.offer { max-width: 100%; width: 100%; }
.composer { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 12px; }
.composer .row { align-items: stretch; }
.code { font: 700 36px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 6px; text-align: center; padding: 12px 0; }

.nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 5; }
.nav a { flex: 1; max-width: 160px; text-align: center; padding: 12px 4px calc(12px + env(safe-area-inset-bottom)); color: var(--muted); text-decoration: none; font-size: 14px; }
.nav a[aria-current=page] { color: var(--brand); font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 10; max-width: 90vw; }

/* portal */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button[aria-selected=true] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.split { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 800px) { .split { grid-template-columns: 320px 1fr; align-items: start; } }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.actions { display: grid; gap: 12px; margin-top: 12px; }
.actions fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.actions legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.inv-row { display: grid; grid-template-columns: 1fr 130px 90px auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
@media (max-width: 600px) { .inv-row { grid-template-columns: 1fr 1fr; } .inv-row > :first-child { grid-column: 1 / -1; } }

/* admin */
h2.flat { margin: 0 0 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.form-grid .field + .field { margin-top: 0; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } .form-grid > div:empty { display: none; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.admin-row:first-child { border-top: 0; }
.admin-line { display: block; }
.licence-img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; display: block; }
textarea { min-height: 64px; resize: vertical; }
