/* Darasa AI Desk — neutral, chat-first layout (light + dark). */
:root {
  --bg: #ffffff;
  --side: #f9f9f9;
  --hover: #ececec;
  --active: #e3e3e3;
  --ink: #0d0d0d;
  --ink-2: #424242;
  --muted: #8f8f8f;
  --line: #e5e5e5;
  --bubble: #f4f4f4;
  --composer: #ffffff;
  --card: #ffffff;
  --primary: #0d0d0d;
  --on-primary: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --pop-shadow: 0 8px 30px rgba(0,0,0,.14);
  --ok-bg: #e7f6ec; --ok: #18794e;
  --warn-bg: #fff4dc; --warn: #94600a;
  --bad-bg: #fdecec; --bad: #b42318;
  --font: ui-sans-serif, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --side: #171717;
    --hover: #2a2a2a;
    --active: #303030;
    --ink: #ececec;
    --ink-2: #c4c4c4;
    --muted: #8e8e8e;
    --line: #343434;
    --bubble: #303030;
    --composer: #303030;
    --card: #262626;
    --primary: #ececec;
    --on-primary: #0d0d0d;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    --pop-shadow: 0 8px 30px rgba(0,0,0,.5);
    --ok-bg: #12301f; --ok: #6fd3a0;
    --warn-bg: #3a2c0d; --warn: #f2c66d;
    --bad-bg: #3d1616; --bad: #f59b93;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.5rem 0 .6rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1.1rem 0 .5rem; }
code { font-family: var(--mono); font-size: .86em; background: var(--bubble); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.boot { height: 100dvh; display: grid; place-items: center; color: var(--muted); }
svg.i { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons and inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; font-weight: 500; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: .88; background: var(--primary); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; padding: 11px 16px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; color: var(--ink-2); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.field { display: grid; gap: 6px; font-size: .85rem; color: var(--ink-2); font-weight: 500; }
.input, .field input, .field select, select.input {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-weight: 400; color: var(--ink); min-width: 0;
}
.input:focus, .field input:focus, .field select:focus, textarea:focus { outline: none; border-color: var(--ink-2); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--ink-2); }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Auth screens */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.auth-card .logo-lg { margin: 0 auto 4px; }
.auth-card h1 { text-align: center; font-size: 1.75rem; }
.auth-card .sub { text-align: center; color: var(--muted); margin: -6px 0 8px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: -.02em; flex-shrink: 0; }
.logo-lg { width: 48px; height: 48px; border-radius: 14px; font-size: 24px; }

/* App frame */
.app { display: flex; height: 100dvh; overflow: hidden; }
.side { width: 260px; flex-shrink: 0; background: var(--side); display: flex; flex-direction: column; border-right: 1px solid transparent; }
.app.side-collapsed .side { display: none; }
.side-top { display: flex; align-items: center; gap: 6px; padding: 10px 10px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; flex: 1; padding-left: 4px; white-space: nowrap; }
.side-nav { padding: 4px 8px; display: grid; gap: 1px; }
.side-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; text-align: left; color: var(--ink); font-size: .92rem; }
.side-item:hover { background: var(--hover); }
.side-item.on { background: var(--active); }
.side-item .badge { margin-left: auto; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: var(--on-primary); font-size: .72rem; font-weight: 700; display: inline-grid; place-items: center; }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.side-label { font-size: .75rem; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; }
.chat-link { display: block; width: 100%; border: 0; background: transparent; text-align: left; padding: 7px 10px; border-radius: 10px; font-size: .9rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-link:hover { background: var(--hover); }
.chat-link.on { background: var(--active); }
.side-foot { padding: 8px; border-top: 1px solid var(--line); }
.profile { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; border-radius: 12px; padding: 8px; text-align: left; }
.profile:hover { background: var(--hover); }
.avatar-txt { width: 32px; height: 32px; border-radius: 50%; background: #5b5bd6; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .8rem; flex-shrink: 0; }
.profile .who { min-width: 0; line-height: 1.25; }
.profile .who b { display: block; font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile .who span { font-size: .78rem; color: var(--muted); }
.scrim { display: none; }
.only-desk { display: inline-grid; }
.only-phone { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar { height: 56px; flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 0 10px; }
.topbar .show-collapsed { display: none; }
.app.side-collapsed .topbar .show-collapsed { display: inline-grid; }
.picker { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; border-radius: 10px; padding: 7px 10px; font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.picker:hover { background: var(--hover); }
.picker .dim { color: var(--muted); font-weight: 500; }
.picker svg.i { width: 16px; height: 16px; color: var(--muted); }
.topbar .mobile-only { display: none; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Popover menus */
.pop { position: fixed; z-index: 60; min-width: 230px; max-width: calc(100vw - 24px); background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--pop-shadow); padding: 6px; }
.pop-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.pop-head b { display: block; font-weight: 600; }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; border-radius: 10px; padding: 9px 10px; text-align: left; color: var(--ink); }
.pop-item:hover { background: var(--hover); }
.pop-item .tick { margin-left: auto; visibility: hidden; }
.pop-item.on .tick { visibility: visible; }
.pop-item .desc { display: block; font-size: .78rem; color: var(--muted); }

/* Chat */
.thread { flex: 1; overflow-y: auto; }
.thread-inner { max-width: 768px; margin: 0 auto; padding: 12px 20px 28px; display: flex; flex-direction: column; gap: 22px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--bubble); border-radius: 20px; padding: 10px 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg-ai { display: flex; gap: 14px; align-items: flex-start; }
.msg-ai .bot { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; flex-shrink: 0; margin-top: 1px; background: var(--bg); }
.msg-ai .bot svg.i { width: 16px; height: 16px; }
.msg-ai .body { flex: 1; min-width: 0; padding-top: 3px; }
.md p { margin: 0 0 .7em; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: .2em 0 .8em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md .tbl { margin: .6em 0 .9em; }
.thinking .body { color: var(--muted); }
.shimmer { background: linear-gradient(90deg, var(--muted) 0%, var(--ink) 50%, var(--muted) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.notice { align-self: center; font-size: .85rem; border-radius: 999px; padding: 6px 14px; text-align: center; max-width: 100%; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.bad { background: var(--bad-bg); color: var(--bad); border-radius: 14px; }

.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 0 8px; min-height: 52vh; }
.hero h1 { font-size: 1.75rem; margin: 14px 0 6px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 440px; }
.starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 640px; margin-top: 28px; }
.starter { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 12px 14px; transition: background .15s; }
.starter:hover { background: var(--hover); }
.starter b { display: block; font-weight: 500; font-size: .92rem; }
.starter span { color: var(--muted); font-size: .84rem; }

.composer-wrap { padding: 0 16px calc(10px + env(safe-area-inset-bottom)); flex-shrink: 0; }
.composer { max-width: 768px; margin: 0 auto; background: var(--composer); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 20px; }
.composer textarea { flex: 1; border: 0; outline: none; background: transparent; resize: none; padding: 8px 0; max-height: 200px; min-height: 24px; line-height: 1.5; }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; flex-shrink: 0; }
.send:disabled { opacity: .3; cursor: default; }
.send svg.i { width: 18px; height: 18px; stroke-width: 2.4; }
.footnote { text-align: center; font-size: .75rem; color: var(--muted); margin-top: 8px; }

/* Draft cards */
.draft { border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 16px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.draft-head { display: flex; align-items: center; gap: 12px; }
.draft-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--bubble); display: grid; place-items: center; flex-shrink: 0; }
.draft-title { font-weight: 600; }
.draft-sub { font-size: .8rem; color: var(--muted); }
.draft-summary { color: var(--ink-2); }
.pill { margin-left: auto; font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; background: var(--warn-bg); color: var(--warn); }
.pill.confirmed { background: var(--ok-bg); color: var(--ok); }
.pill.rejected, .pill.expired, .pill.replaced { background: var(--bubble); color: var(--muted); }
.draft.replaced { opacity: .7; box-shadow: none; }
.pill.failed, .pill.check { background: var(--bad-bg); color: var(--bad); }
.draft.rejected, .draft.expired { opacity: .75; box-shadow: none; }
.callout { display: flex; gap: 8px; align-items: flex-start; border-radius: 12px; padding: 9px 12px; font-size: .88rem; }
.callout svg.i { width: 17px; height: 17px; margin-top: 2px; }
.callout.warn { background: var(--warn-bg); color: var(--warn); }
.callout.ok { background: var(--ok-bg); color: var(--ok); }
.callout.bad { background: var(--bad-bg); color: var(--bad); }
.scrollbox { max-height: 340px; overflow: auto; border-radius: 14px; }
.scrollbox .tbl { overflow: visible; }
.scrollbox th { position: sticky; top: 0; z-index: 1; }
.draft-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-weight: 500; color: var(--muted); font-size: .78rem; background: var(--side); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--hover); }
tr.voided td { text-decoration: line-through; color: var(--muted); }
.sub-line { color: var(--muted); font-size: .8rem; }

/* Pages: reports, drafts, admin */
.page { flex: 1; overflow-y: auto; }
.page-inner { max-width: 1040px; margin: 0 auto; padding: 8px 24px 48px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 8px 0 18px; }
.page-head p { margin: 0; color: var(--muted); }
.seg { display: flex; gap: 4px; background: var(--bubble); border-radius: 999px; padding: 4px; overflow-x: auto; scrollbar-width: none; margin-bottom: 18px; width: fit-content; max-width: 100%; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-size: .88rem; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; margin-top: 2px; }
.cols { display: grid; grid-template-columns: minmax(280px, 1fr) 1.6fr; gap: 20px; align-items: start; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 130px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.stack { display: grid; gap: 12px; }
.empty-note { color: var(--muted); padding: 28px 0; text-align: center; }
.alert { border-radius: 12px; padding: 10px 14px; font-size: .9rem; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.temp { font: 600 1.05rem var(--mono); background: var(--warn-bg); color: var(--warn); padding: 4px 10px; border-radius: 8px; display: inline-block; margin: 4px 0; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--ink-2); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.link-btn:hover { background: var(--hover); }
.link-btn svg.i { width: 16px; height: 16px; }

/* Phone */
@media (max-width: 768px) {
  .side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(84vw, 320px); transform: translateX(-102%); visibility: hidden; transition: transform .22s ease, visibility .22s; }
  .app.side-collapsed .side { display: flex; }
  .app.side-open .side { transform: none; visibility: visible; box-shadow: var(--pop-shadow); }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.35); }
  .topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); justify-content: space-between; padding: 0 6px; border-bottom: 1px solid var(--line); }
  .topbar .mobile-only { display: inline-grid; }
  .only-desk { display: none; }
  .only-phone { display: inline-grid; }
  .topbar .show-collapsed, .app.side-collapsed .topbar .show-collapsed { display: none; }
  .picker { font-size: 1rem; }
  .thread-inner { padding: 14px 14px 20px; gap: 18px; }
  .msg-user { max-width: 88%; }
  .msg-ai { gap: 10px; }
  .msg-ai .bot { width: 26px; height: 26px; }
  .hero { min-height: 40vh; }
  .hero h1 { font-size: 1.4rem; }
  .starters { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }
  .starter { padding: 10px 12px; border-radius: 14px; }
  .starter span { display: none; }
  .composer-wrap { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer { padding: 6px 6px 6px 16px; border-radius: 24px; }
  .composer textarea { font-size: 16px; } /* stops iPhone zooming in */
  .page-inner { padding: 6px 14px 40px; }
  .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 12px; border-radius: 14px; }
  .stat .v { font-size: 1.05rem; }
  .draft { padding: 14px; border-radius: 16px; }
  .draft-actions { flex-direction: column; }
  .draft-actions .btn { width: 100%; padding: 11px 16px; }
  th, td { padding: 8px 9px; }
  .input, .field input, .field select { font-size: 16px; }
}
