/* Self-hosted birdie.lv fonts (Roboto variable + Anton), latin + latin-ext for Latvian. */
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 100 900; font-display: swap; src: url(fonts/roboto-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 100 900; font-display: swap; src: url(fonts/roboto-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Anton'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/anton-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Anton'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/anton-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #1b1b1b;
  --surface: #242424;
  --surface-2: #2f2f2f;
  --border: #3a3a3a;
  --text: #f2f2f2;
  --muted: #a3a3a3;
  --accent: #179252;
  --accent-dark: #084d40;
  --accent-text: #ffffff;
  --visitor: #333333;
  --danger: #e5484d;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
a { color: #5fd39a; }
button, input, textarea { font: inherit; color: inherit; }

#app { height: 100%; max-width: 1100px; margin: 0 auto; }
.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.screen { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.center { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 12px; text-align: center; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar .title { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .subtitle { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: transparent; color: var(--text); font-size: 22px; text-decoration: none; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 0;
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .55; }

.muted { color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.hint { background: #3a3000; border-color: #5a4a00; text-align: left; font-size: 14px; }

.banner { display: block; margin: 8px 12px 0; padding: 10px 14px; border-radius: 10px; background: #0f3d33; color: #d6f2e3; text-decoration: none; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translate(-50%, 20px);
  background: #000; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login .logo { align-self: center; border-radius: 18px; }
.login h1 { text-align: center; margin: 0 0 8px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-size: 16px; color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-error { color: #ff8a8d; min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------- list ---------- */
.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); }
.tab { flex: 1; text-align: center; padding: 12px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; color: inherit; border-bottom: 1px solid #2a2a2a; }
.row:active { background: var(--surface); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; background: #0f3d33; color: #d6f2e3; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row time { flex: none; color: var(--muted); font-size: 13px; }
.preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .name, .row.unread .preview { color: var(--text); font-weight: 650; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.more { display: block; margin: 16px auto calc(var(--safe-bottom) + 16px); }

/* ---------- chat ---------- */
.chat-body { flex: 1; display: flex; min-height: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.messages { padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; margin: 12px 0 6px; color: var(--muted); font-size: 12px; background: var(--surface); padding: 3px 10px; border-radius: 999px; }
.system { align-self: center; color: var(--muted); font-size: 13px; font-style: italic; margin: 6px 0; text-align: center; }

.msg { max-width: 82%; display: flex; flex-direction: column; align-self: flex-start; margin-top: 4px; }
.msg.agent { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 4px 2px; }
.bubble { padding: 9px 13px; border-radius: 18px; background: var(--visitor); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.visitor .bubble { border-bottom-left-radius: 6px; }
.msg.agent .bubble { background: #1d5e4c; border-bottom-right-radius: 6px; }
.msg.agent.mine .bubble { background: var(--accent); color: var(--accent-text); }
.msg .meta { font-size: 11px; color: var(--muted); margin: 2px 6px 0; }
.msg.pending { opacity: .6; }
.msg.failed .bubble { background: transparent; border: 1px solid var(--danger); color: var(--text); }
.msg.failed { cursor: pointer; }
.msg.failed .meta { color: #ff8a8d; }

.new-pill { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 72px); border: 0; border-radius: 999px; padding: 8px 14px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.4); }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(var(--safe-bottom) + 8px); background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; max-height: 160px; border-radius: 20px; padding: 10px 14px; line-height: 1.35; }
.send-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 18px; cursor: pointer; }

/* context panel: sheet on mobile, sidebar on wide screens */
.context { display: none; }
.context.open {
  display: block; position: fixed; inset: auto 0 0 0; max-height: 70dvh; overflow-y: auto; z-index: 5;
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 16px); box-shadow: 0 -10px 30px rgba(0,0,0,.5);
}
@media (min-width: 900px) {
  .context.open { position: static; max-height: none; width: 300px; border-radius: 0; border-top: 0; border-left: 1px solid var(--border); box-shadow: none; }
}
.ctx-section { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.ctx-section:last-child { border-bottom: 0; }
.ctx-section h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ctx-strong { font-weight: 600; }
.ctx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ctx-url { overflow-wrap: anywhere; }
.ctx-empty { padding: 16px 0; color: var(--muted); }

/* ---------- settings ---------- */
.settings { padding-bottom: calc(var(--safe-bottom) + 24px); }
.settings > .btn.danger { display: flex; margin: 12px; width: calc(100% - 24px); }
.agent-card { display: flex; align-items: center; gap: 12px; }
.agent-card img { border-radius: 50%; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv.small { font-size: 12px; }
.kv .ua { overflow-wrap: anywhere; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- product picker ---------- */
.product-btn { flex: none; width: 44px; height: 44px; font-size: 20px; }
.pp-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.pp-sheet {
  width: 100%; max-width: 640px; max-height: 80dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 12px 12px calc(var(--safe-bottom) + 12px);
}
@media (min-width: 900px) { .pp-overlay { align-items: center; } .pp-sheet { border-radius: 18px; } }
.pp-head { display: flex; gap: 8px; align-items: center; }
.pp-head input { flex: 1; }
.pp-hint { font-size: 12px; margin: 6px 4px; }
.pp-results { overflow-y: auto; display: flex; flex-direction: column; }
.pp-item { display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 6px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; width: 100%; }
.pp-item:active { background: var(--surface-2); }
.pp-item img, .pp-noimg { flex: none; width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: #fff; }
.pp-noimg { display: flex; align-items: center; justify-content: center; background: var(--surface-2); font-size: 22px; }
.pp-main { min-width: 0; }
.pp-name { font-weight: 600; overflow-wrap: anywhere; }
.pp-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.pp-stock.ok { color: #46c47a; }
.pp-stock.warn { color: #f0b429; }
.pp-stock.bad { color: #ff8a8d; }
.bubble a { color: inherit; text-decoration: underline; overflow-wrap: anywhere; }

/* ---------- product cards (spec A.8) ---------- */
.cards { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; width: 260px; max-width: 100%; }
.pcard { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; }
.pcard:active { background: var(--surface-2); }
.pcard img, .pcard-noimg { flex: none; width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: #fff; }
.pcard-noimg { display: flex; align-items: center; justify-content: center; background: var(--surface-2); font-size: 26px; }
.pcard-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pcard-name { font-weight: 600; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; }
.pcard-price { font-size: 14px; }
.pcard-stock { font-size: 12px; color: var(--muted); }
.pcard-stock.ok { color: #46c47a; }
.pcard-stock.warn { color: #f0b429; }
.pcard-stock.bad { color: #ff8a8d; }

.ctx-warn { background: #3a3000; border: 1px solid #5a4a00; color: #ffe08a; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; }

/* ---------- login (birdie.lv look) ---------- */
.login-screen {
  position: fixed; inset: 0; overflow-y: auto; z-index: 1;
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 24px) 16px calc(var(--safe-bottom) + 24px);
  background: radial-gradient(120% 80% at 50% 0%, #179252 0%, #0b6447 45%, #084d40 100%);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; color: #fff; }
.login-brand img { width: 190px; height: auto; }
.login-brand .tag { font-family: 'Anton', Impact, sans-serif; text-transform: uppercase; letter-spacing: .08em; font-size: 15px; opacity: .85; }
.login-card {
  width: 100%; max-width: 380px; background: #fff; color: #242424; border-radius: 16px;
  padding: 26px 22px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { font-family: 'Anton', Impact, sans-serif; font-weight: 400; text-transform: uppercase; letter-spacing: .02em; font-size: 28px; margin: 0 0 4px; color: #242424; }
.login-card .lead { margin: 0 0 18px; color: #767676; font-size: 15px; }
.login-card label { color: #242424; font-weight: 500; }
.login-card input { background: #f3f3f4; border: 1px solid #e1e1e4; color: #242424; }
.login-card input:focus { outline: 2px solid #179252; background: #fff; }
.login-card .btn.primary { width: 100%; min-height: 48px; margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; border-radius: 8px; }
.login-card .btn.primary:hover { background: #084d40; }
.login-card .form-error { color: #c62828; }
.login-card .hint { margin: 14px 0 0; background: #eef7f2; border-color: #cfe9db; color: #084d40; }
.login-foot { margin-top: 18px; color: rgba(255,255,255,.7); font-size: 13px; }
.login-foot a { color: #fff; }

/* ---------- typing + presence (spec A.10) ---------- */
.avatar { position: relative; }
.presence { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--bg); }
.presence.online { background: #46c47a; }
.presence.away { background: #f0b429; }
.preview.typing { color: #5fd39a; font-style: italic; }
.typing-ind { display: flex; align-items: center; gap: 8px; padding: 0 16px 10px; color: var(--muted); font-size: 13px; }
.typing-dots { position: relative; width: 26px; height: 8px; flex: none; }
.typing-dots::before { content: ''; position: absolute; left: 0; top: 1px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); box-shadow: 10px 0 0 var(--muted), 20px 0 0 var(--muted); animation: typing-pulse 1.2s infinite ease-in-out; }
@keyframes typing-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing-dots::before { animation: none; } }

/* ---------- quick replies (spec A.11) ---------- */
.composer-wrap { position: relative; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 0; background: var(--surface); border-top: 1px solid var(--border); scrollbar-width: none; }
.chip { flex: none; border: 1px solid #2f6e55; background: #12382c; color: #d6f2e3; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.chip:active { background: #1d5e4c; }
.reply-menu { position: absolute; left: 10px; right: 10px; bottom: 100%; margin-bottom: 6px; max-height: 50dvh; overflow-y: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 -8px 24px rgba(0,0,0,.4); z-index: 6; }
.reply-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 10px 12px; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); cursor: pointer; }
.reply-item.first { background: #12382c; }
.reply-item span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
