/* Harness — the bahi-khata (ledger book) look.
   The agent writes entries on ruled paper to the right of a red margin; you sign slips for anything important. */
:root {
  --paper: #FAFAF8;
  --ink: #1F2A5A;
  --ink-soft: #4A5480;
  --bahi: #A3242B;
  --haldi: #E3A21A;
  --haldi-wash: #FFF5DC;
  --leaf: #2F7A4B;
  --rule: #DCE1EE;
  --bubble-text: #FAFAF8;
  --sheet: #FFFFFF;
  --shade: rgba(31, 42, 90, .14);
  --line: 28px;             /* ruled-line spacing = agent text line height */
  --margin: 74px;           /* left margin of the ledger */
  --font: "Mukta", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: "Kalam", "Mukta", cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131834;
    --ink: #E8EAF4;
    --ink-soft: #A9AFCB;
    --bahi: #C9474E;
    --haldi: #F0B43A;
    --haldi-wash: #2A2A2E;
    --leaf: #5DB27F;
    --rule: rgba(232, 234, 244, .07);
    --bubble-text: #131834;
    --sheet: #1B2145;
    --shade: rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--haldi); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas: "band" "page" "activity" "composer";
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- header: the ledger's red cloth cover ---------- */
.band {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 6px;
  background: var(--bahi);
  color: #FFF8EC;
  box-shadow: inset 0 -3px 0 var(--haldi);
}
.band .title { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.band .title > span:first-child { font-weight: 700; font-size: 20px; letter-spacing: .2px; }
.presence { font-size: 13px; opacity: .9; display: inline-flex; align-items: center; gap: 6px; }
.presence i { width: 8px; height: 8px; border-radius: 50%; background: #F3C6C8; }
.presence[data-state="on"] i { background: #9FE0B5; }
.presence[data-state="busy"] i { background: var(--haldi); }
.spend { font-size: 14px; opacity: .92; font-variant-numeric: tabular-nums; }
.tabs { flex-basis: 100%; display: flex; gap: 22px; padding: 2px 0 0 46px; margin-bottom: -8px; }
.tabs button { background: none; border: 0; color: #FFF8EC; opacity: .75; padding: 6px 0 9px; font-weight: 500; font-size: 16px; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { opacity: 1; font-weight: 700; border-bottom-color: #FFF8EC; }
.icon-btn { background: none; border: 0; color: inherit; padding: 8px; border-radius: 10px; display: grid; place-items: center; }

/* ---------- the ledger page ---------- */
.ledger {
  overflow-y: auto;
  overscroll-behavior: contain;
  position: relative;
  padding: 12px 14px 20px var(--margin);
  background:
    linear-gradient(to right, transparent calc(var(--margin) - 12px), var(--bahi) calc(var(--margin) - 12px), var(--bahi) calc(var(--margin) - 10.5px), transparent calc(var(--margin) - 10.5px)),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
  background-attachment: local;
}
.day { margin: 14px 0 6px; color: var(--ink-soft); font-size: 14px; line-height: var(--line); }

.entry { position: relative; margin: 0 0 var(--line); line-height: var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.entry .margin {
  position: absolute; left: calc(-1 * var(--margin) + 2px); width: calc(var(--margin) - 18px); white-space: nowrap;
  top: 0; text-align: right; font-size: 12px; line-height: 1.3; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; padding-top: 6px;
}
.entry .margin b { display: block; font-weight: 500; color: var(--ink); }
.entry a { color: inherit; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.entry strong { font-weight: 700; }
.entry.error { color: var(--bahi); }
.entry.notify::before { content: "⏰"; position: absolute; left: -26px; top: 0; font-size: 15px; }

/* your messages: ink bubbles on the right */
.mine { display: flex; justify-content: flex-end; margin: 0 0 var(--line); }
.mine .bubble {
  max-width: 84%;
  background: var(--ink); color: var(--bubble-text);
  padding: 8px 14px 9px; border-radius: 18px 18px 4px 18px;
  line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.mine .bubble .voice { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; opacity: .8; margin-right: 6px; }
.mine .bubble .voice svg { width: 14px; height: 14px; }

/* ---------- the approval slip (the one bold thing) ---------- */
.slip {
  position: relative;
  margin: 4px 0 var(--line);
  background: var(--sheet);
  border-left: 6px solid var(--haldi);
  border-radius: 4px 12px 12px 4px;
  padding: 12px 14px 14px;
  box-shadow: 0 1px 0 var(--rule), 0 6px 18px -10px var(--shade);
  line-height: 1.45;
}
.slip::before { /* perforated top edge, like a slip torn from a receipt book */
  content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px;
  background: radial-gradient(circle, var(--paper) 1.2px, transparent 1.6px) 0 0 / 8px 2px repeat-x;
}
.slip .ask { font-size: 13px; color: var(--ink-soft); }
.slip h3 { margin: 2px 0 6px; font-size: 18px; font-weight: 700; }
.slip .detail { margin: 0 0 6px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14em; overflow: auto; }
.slip .detail dt { float: left; clear: left; color: var(--ink-soft); margin-right: 6px; }
.slip .detail dd { margin: 0 0 2px; }
.slip .why { font-size: 14px; color: var(--ink-soft); margin: 0 0 12px; }
.slip .actions { display: flex; gap: 10px; }
.slip .actions button { flex: 1; min-height: 46px; border-radius: 12px; font-weight: 700; font-size: 16px; }
.slip .block { background: transparent; border: 1.5px solid var(--ink-soft); color: var(--ink); }
.slip .sign { background: var(--ink); border: 0; color: var(--bubble-text); }
.slip.done { border-left-color: var(--leaf); }
.slip.no { border-left-color: var(--bahi); }
.slip.done .actions, .slip.no .actions, .slip.expired .actions { display: none; }
.slip.expired { border-left-color: var(--rule); opacity: .75; }

.slip.done, .slip.no { padding-bottom: 64px; }
.stamp {
  position: absolute; right: 16px; bottom: 14px;
  font: 700 22px/1 var(--hand);
  padding: 6px 12px 4px; border: 2.5px solid currentColor; border-radius: 8px;
  transform: rotate(-9deg); text-align: center;
  color: var(--leaf);
}
.stamp small { display: block; font: 500 12px/1.2 var(--font); margin-top: 2px; }
.slip.no .stamp { color: var(--bahi); }
.stamp.fresh { animation: stamp .32s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes stamp { from { transform: rotate(-9deg) scale(1.9); opacity: 0; } to { transform: rotate(-9deg) scale(1); opacity: 1; } }

.empty { color: var(--ink-soft); line-height: var(--line); }
.empty strong { color: var(--ink); display: block; font-size: 20px; }
.empty ul { list-style: none; padding: 0; margin: 4px 0 0; }
.empty li { margin: 0; }
.empty .link { display: block; width: 100%; text-align: left; padding: 0; line-height: var(--line); color: var(--ink); font-size: 16px; text-decoration-color: var(--haldi); text-decoration-thickness: 2px; }
.empty .link::before { content: "“"; color: var(--ink-soft); }
.empty .link::after { content: "”"; color: var(--ink-soft); }

/* ---------- the khata page ---------- */
.ledger, .khata { grid-area: page; }
.band { grid-area: band; } .activity { grid-area: activity; } .composer { grid-area: composer; }
.totals { margin: 2px 0 var(--line); }
.totals .row { display: flex; justify-content: space-between; align-items: baseline; line-height: var(--line); }
.totals .row span:first-child { color: var(--ink-soft); }
.totals .amt { font-variant-numeric: tabular-nums; font-weight: 500; }
.totals .row.big { line-height: calc(var(--line) * 2); }
.totals .row.big span:first-child { color: var(--ink); font-weight: 700; font-size: 18px; }
.totals .row.big .amt { font-size: 30px; font-weight: 700; }
.totals .bad { color: var(--bahi); }
.totals .good { color: var(--leaf); }
.group { margin: 0 0 var(--line); }
.group h2 { margin: 0; font-size: 15px; font-weight: 700; line-height: var(--line); color: var(--ink-soft); }
.group.alert h2 { color: var(--bahi); }
.deal { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; width: 100%; text-align: left; background: none; border: 0; padding: 0; line-height: var(--line); }
.deal .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal .who small { font-weight: 400; color: var(--ink-soft); font-size: 15px; }
.deal .amt { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.deal .meta { grid-column: 1 / -1; font-size: 14px; color: var(--ink-soft); margin-top: calc(var(--line) * -0.15); line-height: calc(var(--line) * .85); padding-bottom: calc(var(--line) * .15); }
.deal .meta .late { color: var(--bahi); font-weight: 500; }
.deal .meta .soon { color: var(--ink); font-weight: 500; }
.khata.paused .deal { opacity: .55; }

/* ---------- live activity line ---------- */
.activity { display: flex; gap: 10px; align-items: center; padding: 4px 16px 6px var(--margin); color: var(--ink-soft); font-size: 14px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--haldi); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--paper);
  border-top: 1px solid var(--rule);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 46px;
  border: 1.5px solid var(--rule); background: var(--sheet); border-radius: 22px;
  padding: 10px 16px; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--ink-soft); outline: none; }
.mic, .send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; }
.mic { background: var(--haldi-wash); color: var(--ink); }
.send { background: var(--bahi); color: #FFF8EC; }
.send:disabled { opacity: .4; }
.composer.rec .mic { background: var(--bahi); color: #FFF8EC; }
.composer.rec textarea { display: none; }
.recording { flex: 1; display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bahi); animation: blink 1s infinite; }
.link { background: none; border: 0; padding: 6px; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-soft); }
.link.danger { color: var(--bahi); }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; background: rgba(10, 14, 36, .45); z-index: 10; display: flex; }
.drawer-sheet {
  width: min(360px, 88vw); height: 100%; overflow-y: auto; background: var(--paper);
  padding: calc(env(safe-area-inset-top) + 8px) 18px 24px; box-shadow: 8px 0 24px var(--shade);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; font-size: 20px; }
.drawer section { padding: 14px 0; border-top: 1px solid var(--rule); }
.drawer h2 { font-size: 15px; font-weight: 700; margin: 0 0 8px; }
.plain { list-style: none; padding: 0; margin: 0 0 6px; }
.plain li { padding: 6px 0; border-bottom: 1px dashed var(--rule); font-size: 15px; }
.plain li b { display: block; font-weight: 500; }
.plain li .stop { float: right; margin-left: 10px; color: var(--bahi); font-size: 14px; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.btn { display: block; width: 100%; min-height: 44px; margin: 8px 0 0; border-radius: 12px; border: 1.5px solid var(--ink-soft); background: transparent; font-weight: 500; }
.btn.primary { background: var(--bahi); border-color: var(--bahi); color: #FFF8EC; font-weight: 700; }
.seg { display: flex; border: 1.5px solid var(--rule); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px 6px; }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bubble-text); font-weight: 700; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; background: var(--paper); z-index: 20; }
.login h1 { margin: 12px 0 4px; font-size: 28px; }
.login p { max-width: 320px; color: var(--ink-soft); }
.login form { width: min(320px, 100%); }
.login input { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--rule); background: var(--sheet); }
.error { color: var(--bahi); min-height: 1.5em; }

@media (min-width: 640px) { :root { --margin: 92px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- the diary page ---------- */
.diary { grid-area: page; }
.diary .slot { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0; margin: 0 0 calc(var(--line) * .25); color: inherit; font: inherit; line-height: var(--line); }
.diary .slot b { font-weight: 700; }
.diary .slot .meta { display: block; font-size: 14px; color: var(--ink-soft); line-height: calc(var(--line) * .85); padding-bottom: calc(var(--line) * .15); }
.diary .slot.fu .margin { color: var(--haldi); font-weight: 700; }
.diary .slot.fu.late .margin { color: var(--bahi); }
.diary .slot.fu b { font-weight: 500; }
.diary .slot.fu .meta { display: inline; }
.tabs { gap: 20px; }

/* ---------- action links and business form ---------- */
.entry a.act { display: inline-block; text-decoration: none; font-weight: 700; color: var(--ink); border: 1.5px solid var(--ink-soft); border-radius: 999px; padding: 0 14px; margin: 4px 6px 4px 0; line-height: 34px; }
.entry a.act.wa { background: #1F8A4C; border-color: #1F8A4C; color: #fff; }
.entry.welcome { background: var(--haldi-wash); border-left: 4px solid var(--haldi); padding: 4px 12px 8px 12px; margin-left: -4px; border-radius: 4px 10px 10px 4px; }
.biz label { display: block; margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.biz input, .biz textarea { display: block; width: 100%; margin-top: 3px; min-height: 42px; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--rule); background: var(--sheet); color: var(--ink); font: inherit; font-size: 16px; }
.biz textarea { resize: vertical; }
.biz .btn { margin-top: 4px; }
.biz .error { color: var(--bahi); }
