/* SRAO Cloud Accounting — mobile-first, desktop sidebar */
:root {
  --navy: #0f1f4b; --navy-2: #162a5e; --blue: #1a4fa8; --blue-2: #2563c9; --sky: #e8f0fb; --gold: #f5a623;
  --ink: #18223a; --muted: #5b6472; --line: #e3e7ee; --bg: #f5f7fb; --card: #fff;
  --green: #1f8a4c; --green-bg: #e6f5ec; --red: #c0392b; --red-bg: #fdecea; --amber: #b7791f; --amber-bg: #fff6e0;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
  --nav-h: 64px; --side-w: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; color: var(--navy); }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.grid { display: grid; gap: .9rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ── Shell ── */
.app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff; display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; padding-top: calc(.6rem + env(safe-area-inset-top)); }
.topbar img.mark { width: 30px; height: 30px; border-radius: 8px; background: #fff; padding: 2px; }
.topbar .org { flex: 1; min-width: 0; }
.topbar .org b { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .org span { font-size: .72rem; opacity: .75; }
.topbar button { background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 10px; padding: .45rem .6rem; cursor: pointer; }
main { padding: 1rem .9rem 1.5rem; max-width: 1180px; margin: 0 auto; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; }
.bottomnav a .ic { font-size: 1.25rem; line-height: 1; }
.bottomnav a.on { color: var(--blue); }
.bottomnav a.plus .ic { background: var(--blue); color: #fff; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; margin-top: -18px; box-shadow: 0 6px 14px rgba(26,79,168,.35); }
.sidenav { display: none; }
@media (min-width: 900px) {
  .app { padding-bottom: 0; padding-left: var(--side-w); }
  .bottomnav { display: none; }
  .topbar { display: none; }
  .sidenav { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--navy); color: #fff; padding: 1rem .8rem; gap: .2rem; overflow-y: auto; z-index: 30; }
  .sidenav .brand { display: flex; gap: .6rem; align-items: center; padding: .2rem .4rem 1rem; }
  .sidenav .brand img { width: 36px; height: 36px; border-radius: 9px; background: #fff; padding: 3px; }
  .sidenav .brand b { font-size: .95rem; display: block; } .sidenav .brand span { font-size: .72rem; opacity: .7; }
  .sidenav select { width: 100%; margin: 0 0 .8rem; background: var(--navy-2); color: #fff; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; padding: .5rem; }
  .sidenav a { display: flex; gap: .7rem; align-items: center; color: rgba(255,255,255,.82); text-decoration: none; padding: .55rem .7rem; border-radius: 10px; font-weight: 600; font-size: .92rem; }
  .sidenav a:hover { background: rgba(255,255,255,.08); color: #fff; }
  .sidenav a.on { background: rgba(255,255,255,.14); color: #fff; }
  .sidenav .grow { flex: 1; }
  .sidenav .foot { font-size: .72rem; opacity: .65; padding: .6rem .4rem 0; display: flex; gap: .4rem; align-items: center; }
  .sidenav .foot img { width: 16px; height: 16px; animation: spin 4s linear infinite; background: #fff; border-radius: 50%; }
  main { padding: 1.6rem 2rem 7rem; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards, KPIs ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; min-width: 0; }
.card h3 { margin-bottom: .6rem; }
.kpi .label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 1.45rem; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; margin-top: .15rem; word-break: break-word; }
.kpi .sub { font-size: .8rem; color: var(--muted); }
.kpi.accent { background: linear-gradient(135deg, var(--blue), var(--navy)); color: #fff; border: 0; }
.kpi.accent .label, .kpi.accent .sub { color: rgba(255,255,255,.8); } .kpi.accent .value { color: #fff; }
.live { display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; color: var(--green); font-weight: 700; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 99px; font-size: .72rem; font-weight: 700; background: var(--sky); color: var(--blue); white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); } .badge.red { background: var(--red-bg); color: var(--red); } .badge.amber { background: var(--amber-bg); color: var(--amber); } .badge.grey { background: #eef0f4; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: .5rem; }
.bars i { flex: 1; background: var(--sky); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars i.today { background: var(--blue); }
.split { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: #eef0f4; }
.split span { display: block; height: 100%; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); align-items: center; }
.list li:last-child { border-bottom: 0; }

/* ── Forms ── */
label.f { display: block; font-size: .82rem; font-weight: 700; color: var(--navy); margin-bottom: .75rem; }
label.f > span { display: block; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=tel], input[type=time], select, textarea {
  width: 100%; padding: .65rem .75rem; border: 1px solid #cfd6e2; border-radius: 10px; background: #fff; font-size: 16px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,201,.35); border-color: var(--blue-2); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .68rem 1.1rem; border-radius: 11px; border: 1px solid transparent; font-weight: 700; cursor: pointer; text-decoration: none; background: var(--blue); color: #fff; white-space: nowrap; }
.btn:hover { background: var(--blue-2); }
.btn.ghost { background: #fff; color: var(--blue); border-color: #cfd6e2; }
.btn.ghost:hover { background: var(--sky); }
.btn.danger { background: #fff; color: var(--red); border-color: #f0c8c3; }
.btn.sm { padding: .4rem .7rem; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.seg { display: flex; background: #eef1f6; border-radius: 11px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: transparent; padding: .5rem .6rem; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; font-size: .88rem; min-width: 70px; }
.seg button.on { background: #fff; color: var(--blue); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.lines .line { display: grid; grid-template-columns: 1fr 80px 110px 34px; gap: .5rem; align-items: end; margin-bottom: .5rem; }
.lines .line.two { grid-template-columns: 1fr 120px 34px; }
@media (max-width: 600px) {
  .lines .line { grid-template-columns: 1fr 1fr 34px; }
  .lines .line > label:first-child { grid-column: 1 / -1; }
  .lines .line.two { grid-template-columns: 1fr 120px 34px; }
  .lines .line.two > label:first-child { grid-column: auto; }
  .chat .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .3rem; -webkit-overflow-scrolling: touch; }
  .chat .chips button { flex: none; }
}
.cols { grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.x { border: 0; background: #f1f3f7; border-radius: 8px; height: 40px; cursor: pointer; color: var(--muted); }
details.more { margin: .5rem 0 1rem; } details.more summary { cursor: pointer; color: var(--blue); font-weight: 700; font-size: .88rem; }
.total-bar { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; background: var(--sky); border-radius: 12px; font-weight: 800; color: var(--navy); margin: .5rem 0 1rem; }
.total-bar .amt { font-size: 1.3rem; }

/* ── Tables ── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f7f9fc; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
tr.total td { font-weight: 800; background: #f7f9fc; color: var(--navy); }
tr.sect td { font-weight: 800; color: var(--blue); background: #fbfcfe; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f7f9fc; }
table.wide th:first-child, table.wide td:first-child { position: sticky; left: 0; background: #fff; min-width: 190px; z-index: 1; }
table.wide tr.total td:first-child { background: #f7f9fc; }
.neg { color: var(--red); }

/* ── Modal, toast ── */
.modal-bg { position: fixed; inset: 0; background: rgba(15,31,75,.45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 1.1rem 1rem calc(1rem + env(safe-area-inset-bottom)); animation: up .2s ease; }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { max-width: 640px; border-radius: 18px; } .modal.wide { max-width: 1000px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.modal .mhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
.modal .close { border: 0; background: #f1f3f7; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); background: var(--navy); color: #fff; padding: .7rem 1rem; border-radius: 12px; z-index: 200; box-shadow: var(--shadow); max-width: 92vw; font-weight: 600; }
.toast.err { background: var(--red); }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ── Assistant avatar (blinking) ── */
.av { position: relative; display: inline-block; }
.av .stage { position: absolute; }
.av .stage img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.av .lid { position: absolute; border-radius: 50%; transform: scaleY(0); transform-origin: 50% 0; box-shadow: inset 0 -2px 0 rgba(45,22,12,.55); animation: blink 5.2s infinite; pointer-events: none; }
@keyframes blink { 0%, 91% { transform: scaleY(0); } 93.5% { transform: scaleY(1); } 96% { transform: scaleY(0); } }
@media (prefers-reduced-motion: reduce) { .av .lid { animation-duration: 12s; } }
.av.head { border-radius: 50%; overflow: hidden; background: var(--sky); flex: none; }
.av.full { overflow: hidden; border-radius: 14px; flex: none; box-shadow: 0 2px 8px rgba(15,31,75,.12); }
.av-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .7rem; }
.av-pick .av { margin: 0 auto; display: block; }
.av-pick button { border: 2px solid var(--line); background: #fff; border-radius: 16px; padding: .4rem .4rem .6rem; cursor: pointer; text-align: center; }
.av-pick button.on { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,79,168,.15); }
.av-pick b { display: block; font-size: .85rem; margin-top: .35rem; color: var(--navy); } .av-pick span { font-size: .72rem; color: var(--muted); }

/* ── Chat ── */
.chat { display: flex; flex-direction: column; height: calc(100vh - 160px); min-height: 420px; }
@media (min-width: 900px) { .chat { height: calc(100vh - 120px); } }
.chat-head { display: flex; gap: .8rem; align-items: center; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 1rem 0; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 86%; padding: .7rem .9rem; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot { background: #fff; border: 1px solid var(--line); border-top-left-radius: 4px; align-self: flex-start; }
.msg.me { background: var(--blue); color: #fff; border-top-right-radius: 4px; align-self: flex-end; }
.msg .src { display: block; margin-top: .4rem; font-size: .72rem; color: var(--muted); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .6rem; }
.chips button { border: 1px solid #cfd6e2; background: #fff; border-radius: 99px; padding: .4rem .75rem; font-size: .82rem; cursor: pointer; color: var(--navy); font-weight: 600; }
.chat-input { display: flex; gap: .5rem; padding-top: .6rem; }
.typing { display: inline-flex; gap: 4px; } .typing i { width: 7px; height: 7px; border-radius: 50%; background: #b5bfd0; animation: pulse 1s infinite; } .typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
.fab { position: fixed; right: 22px; bottom: 22px; z-index: 40; border: 0; background: transparent; cursor: pointer; display: none; filter: drop-shadow(0 8px 18px rgba(15,31,75,.3)); }
@media (min-width: 900px) { .fab { display: block; } }
.fab .tip { position: absolute; right: 86px; bottom: 44px; background: #fff; color: var(--navy); font-weight: 700; padding: .5rem .8rem; border-radius: 12px; white-space: nowrap; font-size: .85rem; box-shadow: var(--shadow); }

/* ── Upload ── */
.drop { border: 2px dashed #b9c6dc; border-radius: 16px; padding: 1.6rem 1rem; text-align: center; background: #fbfcff; cursor: pointer; }
.drop.over { background: var(--sky); border-color: var(--blue); }
.drop .big { font-size: 2rem; }
.doc-row { display: flex; gap: .8rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.doc-row .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--sky); display: grid; place-items: center; flex: none; }
.doc-row .meta { flex: 1; min-width: 0; } .doc-row .meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review { display: grid; gap: 1rem; }
@media (min-width: 900px) { .review { grid-template-columns: 1fr 1.1fr; } }
.review .preview { background: #f1f3f7; border-radius: 12px; min-height: 260px; display: grid; place-items: center; overflow: hidden; }
.review .preview img { max-width: 100%; max-height: 70vh; } .review .preview iframe { width: 100%; height: 70vh; border: 0; }
.unsure input, .unsure select { border-color: var(--amber); background: var(--amber-bg); }

/* ── Auth / onboarding ── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.2rem; background: radial-gradient(circle at 20% 0%, #24418d, var(--navy) 60%); }
.auth .box { background: #fff; border-radius: 20px; padding: 1.5rem; width: 100%; max-width: 440px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth .logo { display: flex; gap: .7rem; align-items: center; margin-bottom: 1rem; } .auth .logo img { width: 44px; height: 44px; }
.ind-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.ind-pick button { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: .75rem; cursor: pointer; }
.ind-pick button.on { border-color: var(--blue); background: var(--sky); }
.ind-pick b { display: block; color: var(--navy); } .ind-pick span { font-size: .75rem; color: var(--muted); }
.steps { display: flex; gap: .4rem; margin-bottom: 1rem; } .steps i { flex: 1; height: 5px; border-radius: 9px; background: var(--line); } .steps i.on { background: var(--blue); }
.hello { display: flex; gap: 1rem; align-items: center; }
.bubble { background: #fff; border: 1px solid var(--line); border-radius: 16px; border-top-left-radius: 4px; padding: .75rem 1rem; box-shadow: var(--shadow); }
.banner { padding: .7rem 1rem; border-radius: 12px; background: var(--amber-bg); color: #7a5410; font-size: .88rem; margin-bottom: 1rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

@media print {
  .sidenav, .bottomnav, .topbar, .fab, .noprint { display: none !important; }
  .app { padding: 0 !important; } main { padding: 0 !important; max-width: none; }
  .card { box-shadow: none; border: 0; } .tablewrap { border: 0; overflow: visible; }
  table.wide th:first-child, table.wide td:first-child { position: static; }
}
