﻿:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface2: #f0f3f9; --border: #e2e7f0;
  --text: #18202e; --text2: #3b4658; --muted: #6b778c;
  --primary: #2f5bea; --primary-hover: #2449c6; --primary-ink: #ffffff; --primary-soft: #e9eeff;
  --danger: #d92d20; --danger-soft: #feecea; --success: #12905a; --star: #f5a623;
  --mark: #ffe08a; --mark-ink: #1f1f1f; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 14px; --tab-h: 58px;
}
:root[data-theme="dark"] {
  --bg: #0c1322; --surface: #141d31; --surface2: #1a2540; --border: #26335a;
  --text: #e7ecf6; --text2: #c5cee0; --muted: #8e9bb5;
  --primary: #5b8cff; --primary-hover: #7aa1ff; --primary-ink: #0b1226; --primary-soft: #1f2d55;
  --danger: #ff6b5e; --danger-soft: #3a1d22; --success: #3dd68c; --star: #ffc24a;
  --mark: #8a6b00; --mark-ink: #ffffff; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0c1322; --surface: #141d31; --surface2: #1a2540; --border: #26335a;
    --text: #e7ecf6; --text2: #c5cee0; --muted: #8e9bb5;
    --primary: #5b8cff; --primary-hover: #7aa1ff; --primary-ink: #0b1226; --primary-soft: #1f2d55;
    --danger: #ff6b5e; --danger-soft: #3a1d22; --success: #3dd68c; --star: #ffc24a;
    --mark: #8a6b00; --mark-ink: #ffffff; --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
html { font-size: 16px; }
body {
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Naskh Arabic", "Geeza Pro", sans-serif;
  background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#app { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 920px; margin: 0 auto; background: var(--bg); }
#topbar {
  display: flex; align-items: center; gap: 6px; min-height: 52px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; background: var(--bg); flex: none;
}
#topbar h1 { flex: 1; font-size: 1.2rem; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
#topbar .brand img { width: 30px; height: 30px; border-radius: 8px; }
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px); outline: none; }
#view.no-fab { padding-bottom: 28px; }
#tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr); flex: none; background: var(--surface);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); position: relative; z-index: 5;
}
#tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tab-h);
  font-size: .72rem; color: var(--muted); text-decoration: none; }
#tabbar a.active { color: var(--primary); font-weight: 600; }
.i { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.fill { fill: currentColor; }
.fab { position: absolute; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 16px rgba(47,91,234,.4); display: grid; place-items: center; z-index: 6; cursor: pointer; }
.fab .i { width: 1.6rem; height: 1.6rem; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; min-height: 44px; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: .9rem; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn .i { width: 1.15rem; height: 1.15rem; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--text2); flex: none; }
.icon-btn:active { background: var(--surface2); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.grow > * { flex: 1; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.err { color: var(--danger); font-size: .85rem; margin-top: 4px; }

input[type="text"], input[type="search"], input:not([type]), input[type="number"], select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 1rem; min-height: 46px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.invalid { border-color: var(--danger) !important; }
.field { display: block; margin: 0 0 14px; }
.field > .lab { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 5px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------- cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--surface2); }
.card.sel { outline: 2px solid var(--primary); }
.card-head { display: flex; gap: 8px; align-items: flex-start; }
.card-head h3 { flex: 1; font-size: 1.05rem; margin: 0; word-break: break-word; }
.card .crumbs { color: var(--muted); font-size: .82rem; margin-top: 3px; }
.card .snip { margin: 8px 0 6px; color: var(--text2); font-size: .95rem; word-break: break-word; }
.star { border: 0; background: transparent; padding: 6px; margin: -6px -6px 0 0; color: var(--muted); border-radius: 50%; cursor: pointer; flex: none; }
.star.on { color: var(--star); }
.star .i { width: 1.4rem; height: 1.4rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--surface2); color: var(--text2); font-size: .8rem; border: 0; }
.chip.primary { background: var(--primary-soft); color: var(--primary); }
.chip.btn-chip { cursor: pointer; font-size: .9rem; padding: 6px 12px; background: var(--primary-soft); color: var(--primary); }
.chip.ok { background: rgba(18,144,90,.14); color: var(--success); }
.chip.warn { background: rgba(245,166,35,.18); color: #b26b00; }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
mark { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0 1px; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 20px 2px 10px; display: flex; align-items: center; }
.section-title .spacer { flex: 1; }
.empty { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty .i { width: 2.6rem; height: 2.6rem; margin-bottom: 8px; opacity: .7; }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.banner { display: flex; gap: 12px; align-items: flex-start; background: var(--primary-soft); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.banner.warn { background: rgba(245,166,35,.16); }
.banner .body { flex: 1; min-width: 0; }
.banner p { margin: 4px 0 8px; font-size: .92rem; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; word-break: break-word; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }

/* ---------- search ---------- */
.searchbar { position: sticky; top: 0; z-index: 4; background: var(--bg); padding: 4px 0 8px; }
.searchbox { position: relative; display: flex; align-items: center; }
.searchbox > .i { position: absolute; inset-inline-start: 13px; color: var(--muted); pointer-events: none; }
.searchbox input { padding-inline-start: 42px; padding-inline-end: 44px; min-height: 52px; border-radius: 16px; font-size: 1.05rem; border: 2px solid var(--border); }
.searchbox input:focus { border-color: var(--primary); outline: none; }
.searchbox .clear { position: absolute; inset-inline-end: 4px; }
.filterrow { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.filterrow .info { flex: 1; font-size: .82rem; color: var(--muted); min-width: 0; }
.badge { display: inline-grid; place-items: center; min-width: 1.2rem; height: 1.2rem; padding: 0 5px; border-radius: 999px; background: var(--primary); color: var(--primary-ink); font-size: .72rem; font-weight: 700; }
.select-bar { display: flex; gap: 8px; align-items: center; background: var(--primary-soft); border-radius: 12px; padding: 8px 10px; margin: 6px 0; }
.card.selectable { display: flex; gap: 10px; align-items: flex-start; }
.card.selectable > .body { flex: 1; min-width: 0; }
.card.selectable input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); margin-top: 2px; }

/* ---------- detail ---------- */
.q-title { font-size: 1.35rem; font-weight: 700; margin: 6px 0 8px; word-break: break-word; }
.md { word-break: break-word; font-size: 1.04rem; line-height: 1.6; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .6em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1em 0 .4em; }
.md ul, .md ol { padding-inline-start: 1.4em; margin: .5em 0; }
.md blockquote { margin: .6em 0; padding: 4px 12px; border-inline-start: 4px solid var(--primary); background: var(--surface2); border-radius: 6px; }
.md code { background: var(--surface2); padding: 1px 6px; border-radius: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.md pre { background: var(--surface2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; text-align: left; }
.md pre code { padding: 0; background: none; }
.table-wrap { overflow-x: auto; margin: .6em 0; }
.md table { border-collapse: collapse; width: max-content; min-width: 100%; max-width: none; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; min-width: 6.5em; max-width: 18em; word-break: normal; overflow-wrap: break-word; vertical-align: top; }
.md th { background: var(--surface2); }
.pager { position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 10px 0 4px; background: linear-gradient(transparent, var(--bg) 30%); }
.pager .pos { flex: 1; text-align: center; color: var(--muted); font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.link { background: none; border: 0; color: var(--primary); text-align: start; padding: 8px 2px; cursor: pointer; font-size: 1rem; width: 100%; }

/* ---------- form ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.tabs button { flex: 0 0 auto; padding: 6px 14px; border: 0; background: transparent; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.mdbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.mdbar .btn { min-height: 36px; padding: 4px 10px; }
.preview { min-height: 140px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.formbar { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0 6px; background: linear-gradient(transparent, var(--bg) 25%); }
.formbar .btn { flex: 1; }

/* ---------- sheets, dialogs, toast ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(8,12,24,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.backdrop.center { align-items: center; padding: 18px; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.dialog { width: 100%; max-width: 420px; background: var(--surface); border-radius: 18px; padding: 20px; animation: pop .15s; max-height: 90dvh; overflow-y: auto; }
.dialog h3 { margin-bottom: 8px; font-size: 1.15rem; }
.dialog p { margin: 0 0 12px; color: var(--text2); white-space: pre-line; }
.dialog .row { justify-content: flex-end; margin-top: 14px; }
.sheet h3 { margin-bottom: 12px; }
.sheet .action { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 8px; border: 0; background: transparent; text-align: start; cursor: pointer; border-radius: 10px; font-size: 1.02rem; }
.sheet .action:active { background: var(--surface2); }
.sheet .action.danger { color: var(--danger); }
.symbols { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.symbols button { min-height: 46px; font-size: 1.15rem; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; cursor: pointer; }
.progress { height: 10px; border-radius: 6px; background: var(--surface2); overflow: hidden; margin: 12px 0; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .1s; }
#toast { position: fixed; left: 50%; transform: translate(-50%, 20px); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 22px); background: #1c2438; color: #fff; padding: 11px 16px; border-radius: 12px;
  z-index: 60; opacity: 0; pointer-events: none; transition: .2s; max-width: 92vw; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: #9db8ff; font-weight: 700; cursor: pointer; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes pop { from { transform: scale(.96); opacity: .5; } }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; min-height: 44px; }
.seg button.on { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border: 0; }
.status-ok { color: var(--success); }

/* ---------- printing / PDF ---------- */
#print-root { display: none; }
@media print {
  html, body { height: auto; background: #fff; color: #000; }
  #app, #overlay-root, #toast { display: none !important; }
  #print-root { display: block; padding: 0; font-family: "Segoe UI", system-ui, sans-serif; color: #111; }
  #print-root h1 { font-size: 20pt; } #print-root h2 { font-size: 13pt; margin: 14pt 0 2pt; }
  #print-root .pmeta { color: #667085; font-size: 9pt; }
  #print-root .q { break-inside: avoid-page; border-bottom: 1px solid #ccc; padding-bottom: 8pt; }
  #print-root .md { font-size: 10.5pt; }
}

/* the app draws its own clear button */
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; display: none; }

.formbar .btn { white-space: nowrap; padding-inline: 8px; }


