:root {
  --font-ui: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "Noto Sans Devanagari", "Kohinoor Devanagari", Mangal, sans-serif;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --text-caption: .6875rem;
  --text-meta: .75rem;
  --text-small: .8125rem;
  --text-control: .875rem;
  --text-body: .9375rem;
  --text-page-title: clamp(1.5rem, 2.7vw, 2rem);
  --text-section-title: 1.1875rem;
  font-family: var(--font-ui);
  font-size: 100%;
  line-height: 1.5;
  font-weight: var(--weight-regular);
  color: var(--ink);
  background: var(--canvas);
  --ink: var(--khata-ink);
  --muted: var(--khata-muted);
  --subtle: var(--khata-subtle);
  --line: var(--khata-line);
  --line-control: var(--khata-control-line);
  --paper: var(--khata-paper);
  --canvas: var(--khata-canvas);
  --surface: var(--khata-surface);
  --soft: var(--khata-well);
  --selected: var(--khata-selection);
  --fill: var(--khata-action);
  --fill-hover: var(--khata-action-hover);
  --fill-text: var(--khata-action-ink);
  --focus: var(--khata-focus);
  --scrim: var(--khata-scrim);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; font-size: var(--text-body); }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button { line-height: 1.25; }
input, select, textarea { font-weight: var(--weight-regular); }
input:not([type=checkbox], [type=radio], [type=file]), select, textarea { color: var(--ink); background-color: var(--paper); }
input::placeholder, textarea::placeholder { color: var(--subtle); opacity: 1; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3, strong, b { font-weight: var(--weight-semibold); }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: var(--text-section-title); }
h3 { font-size: var(--text-body); }
.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner, .shell { width: min(1110px, calc(100% - 80px)); margin: auto; }
.topbar-inner { min-height: 73px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; text-decoration: none; font-size: 1.25rem; font-weight: var(--weight-semibold); letter-spacing: -.025em; white-space: nowrap; }
.brand-mark { width: 33px; height: 33px; flex-shrink: 0; border-radius: 22%; background: url("/khata-icon-96.png?v=jade") center / cover no-repeat; margin-right: 9px; }
.private { display: flex; align-items: center; gap: 8px; font-size: var(--text-small); color: var(--muted); }
.private > span[aria-hidden] { width: 8px; height: 8px; background: var(--subtle); border-radius: 50%; }
.theme-control { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--text-small); }
.theme-control select { min-height: 44px; border: 1px solid var(--line-control); border-radius: 8px; padding-inline: 7px; }

nav { display: flex; gap: 5px; margin: 27px 0 40px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.nav-link { text-decoration: none; padding: 8px 14px; border-radius: 8px; font-size: var(--text-control); font-weight: var(--weight-medium); color: var(--muted); }
.nav-link.active { background: var(--selected); color: var(--khata-accent-ink); }
.nav-link:hover { background: var(--soft); }
#nav-count, #library-count { font-size: var(--text-meta); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
#nav-count { margin-left: 4px; }
#library-count { padding: 4px 9px; color: var(--muted); background: var(--soft); border-radius: 20px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; gap: 32px; padding-bottom: 64px; }
#record, #library { scroll-margin-top: 20px; }
.intro { margin-bottom: 20px; }
h1 { font-size: var(--text-page-title); letter-spacing: -.025em; }
.intro p { font-size: var(--text-body); color: var(--muted); margin-top: 6px; }

.capture { position: relative; text-align: center; background: var(--khata-summary); color: var(--ink); border: 1px solid var(--khata-rim); box-shadow: var(--khata-card-shadow); border-radius: 23px; padding: 22px 25px 27px; overflow: hidden; }
.capture-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 25px; font-size: var(--text-meta); }
#capture-label { display: flex; align-items: center; gap: 7px; border: 1px solid var(--line-control); border-radius: 100px; color: var(--muted); padding: 5px 10px; text-align: left; }
#capture-label i { flex: 0 0 7px; height: 7px; border-radius: 50%; background: var(--subtle); }
.capture[data-phase="recording"] #capture-label i { background: var(--khata-accent-ink); }
.duration-limit { white-space: nowrap; color: var(--muted); }
#timer { margin-top: 20px; font-variant-numeric: tabular-nums; font-size: clamp(2.25rem, 6vw, 3.25rem); font-weight: var(--weight-regular); letter-spacing: -.025em; line-height: 1.2; }
.wave { display: flex; justify-content: center; align-items: center; gap: clamp(3px, .85vw, 7px); height: 78px; margin: 2px 0 9px; }
.wave i { width: 3px; flex: 0 0 3px; border-radius: 3px; background: var(--line-control); transform-origin: center; }
.capture[data-phase="recording"] .wave i { background: var(--khata-accent-ink); }
.record-button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--fill); color: var(--fill-text); display: grid; place-items: center; margin: 6px auto 0; box-shadow: var(--khata-action-shadow); }
.record-button:enabled:hover { background: var(--fill-hover); }
.record-button:focus-visible { outline-color: var(--focus); outline-offset: 7px; }
.record-button:disabled { opacity: .63; }

.mic { position: relative; width: 12px; height: 21px; border: 2px solid currentColor; border-radius: 9px; transform: translateY(-4px); }
.mic::before { content: ""; position: absolute; width: 22px; height: 14px; left: -7px; top: 10px; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 14px 14px; }
.mic::after { content: ""; position: absolute; top: 22px; left: 3px; width: 2px; height: 6px; background: currentColor; }
.stop-icon { display: none; width: 21px; height: 21px; border-radius: 4px; background: currentColor; }
.capture[data-phase="recording"] .mic { display: none; }
.capture[data-phase="recording"] .stop-icon { display: block; }
#capture-hint { margin-top: 17px; color: var(--muted); font-size: var(--text-small); min-height: 19px; font-weight: var(--weight-semibold); }
.privacy-note { display: flex; align-items: baseline; gap: 11px; margin: 18px 3px 0; color: var(--muted); font-size: var(--text-small); line-height: 1.6; }
.lock { position: relative; display: inline-block; width: 12px; height: 9px; border: 1.4px solid currentColor; border-radius: 2px; flex-shrink: 0; }
.lock::before { content: ""; position: absolute; width: 7px; height: 6px; border: 1.4px solid currentColor; border-bottom: 0; border-radius: 7px 7px 0 0; left: 1px; top: -6px; }

#library, .review { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 23px; }
#library { margin-top: 3px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.library-subtitle { font-size: var(--text-small); color: var(--muted); margin-top: 5px; }
.empty { border-radius: 12px; min-height: 190px; margin-top: 22px; padding: 20px 12px; border: 1px dashed var(--line); display: grid; align-content: center; justify-items: center; text-align: center; }
.empty-icon { width: 41px; height: 41px; border-radius: 12px; background: var(--soft); display: flex; align-items: center; justify-content: center; gap: 3px; margin-bottom: 11px; }
.empty-icon i { background: var(--subtle); width: 3px; height: 10px; border-radius: 2px; }
.empty-icon i:nth-child(2) { height: 18px; }
.empty strong { font-size: var(--text-control); }
.empty p, .library-status { margin-top: 5px; font-size: var(--text-small); color: var(--muted); }
#refresh { margin-top: 12px; }
#recordings { padding: 0; list-style: none; margin: 15px 0 0; }
#recordings:empty { margin: 0; }
.saved-item { border-top: 1px solid var(--line); padding: 13px 0; }
.saved-item:last-child { padding-bottom: 0; }
.saved-row { display: flex; gap: 11px; align-items: center; }
.saved-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.saved-text strong { display: block; font-size: var(--text-control); }
.saved-text span, .saved-duration, #take-duration { font-size: var(--text-meta); color: var(--muted); }
.saved-duration, #take-duration { font-variant-numeric: tabular-nums; }
.play-toggle { width: 44px; height: 44px; background: var(--soft); color: var(--muted); border: 0; border-radius: 12px; flex-shrink: 0; font-size: var(--text-control); }
.play-toggle:hover { background: var(--selected); }
audio { display: block; width: 100%; height: 46px; margin: 12px 0 6px; }
.review { margin-top: 15px; }
.review label { display: block; font-size: var(--text-control); font-weight: var(--weight-semibold); margin: 13px 0 6px; }
.review label span { font-weight: var(--weight-regular); color: var(--muted); font-size: var(--text-meta); margin-left: 3px; }
.review input { width: 100%; padding: 10px 11px; border-radius: 8px; border: 1px solid var(--line-control); color: var(--ink); background: var(--paper); }
.review input::placeholder { color: var(--subtle); }
.actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 15px; }
.primary, .secondary, .quiet, .danger { font-size: var(--text-control); font-weight: var(--weight-medium); min-height: 43px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; }
.primary { color: var(--fill-text); background: var(--fill); }
.primary:hover:enabled { background: var(--fill-hover); }
.secondary { color: var(--ink); border-color: var(--line-control); background: var(--paper); }
.secondary:hover { background: var(--soft); }
.quiet { color: var(--muted); background: transparent; }
.quiet:hover { background: var(--soft); }
.danger { color: var(--fill-text); background: var(--fill); }
button:disabled { opacity: .63; }
.remove { min-height: 36px; padding-left: 0; }
.alert, .notice { margin-top: 12px; border-radius: 9px; padding: 10px 13px; font-size: var(--text-control); }
.alert { background: var(--soft); color: var(--ink); }
.notice { background: var(--soft); color: var(--ink); }
dialog { border: 1px solid var(--khata-rim); box-shadow: var(--khata-modal-shadow); border-radius: 15px; color: var(--ink); padding: 21px; background: var(--paper); width: min(420px, calc(100% - 32px)); }
#confirm-dialog { position: fixed; inset: 0; margin: auto; max-height: calc(100dvh - 24px); }
dialog::backdrop { background: var(--scrim); }
dialog p { margin-top: 9px; font-size: var(--text-control); color: var(--muted); overflow-wrap: anywhere; }
dialog .actions { justify-content: flex-end; }
@media (max-width: 760px) {
  .topbar-inner, .shell { width: min(520px, calc(100% - 36px)); }
  .topbar-inner { min-height: 62px; }
  nav { margin: 18px 0 28px; padding-bottom: 13px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 25px; padding-bottom: 35px; }
  .intro { margin-bottom: 19px; }
  .capture { padding: 18px 17px 22px; border-radius: 19px; }
  #timer { margin-top: 16px; }
  .wave { height: 68px; }
  #library, .review { padding: 18px; }
}
@media (max-width: 350px) {
  .private { font-size: var(--text-caption); }
  .nav-link { padding-inline: 10px; }
  .wave { gap: 2px; }
}
.record-status { display: table; margin-top: 5px; padding: 2px 7px; border-radius: 5px; font-weight: var(--weight-medium); background: var(--soft); }
.saved-text .record-status.logged { color: var(--muted); background: var(--selected); }
.saved-text .record-status.pending { color: var(--muted); background: var(--soft); }
.saved-text .record-status.waiting { color: var(--muted); background: var(--soft); }
.saved-text .saved-summary { display: block; margin-top: 5px; font-size: var(--text-small); color: var(--ink); }
.recording-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 9px; }
.recording-actions > button { min-height: 44px; }
.saved-item .remove { padding-inline: 8px; }
.job-error { margin-top: 7px; color: var(--muted); font-size: var(--text-small); line-height: 1.45; }
#transaction-dialog { width: min(525px, calc(100% - 24px)); max-height: calc(100dvh - 24px); }
.close-dialog { color: var(--muted); min-height: 36px; width: 36px; padding: 0; font-size: 23px; }
.transcript { margin: 14px 0; padding: 12px; background: var(--soft); border-radius: 9px; font-size: var(--text-small); }
.transcript p { color: var(--ink); white-space: pre-wrap; max-height: 145px; overflow: auto; }
.transaction-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.transaction-fields label { font-size: var(--text-small); font-weight: var(--weight-medium); }
.transaction-fields .wide { grid-column: 1 / -1; }
.transaction-fields small { color: var(--muted); font-weight: var(--weight-regular); }
.transaction-fields input, .transaction-fields select { width: 100%; min-width: 0; min-height: 40px; margin-top: 5px; border-radius: 7px; border: 1px solid var(--line-control); background: var(--paper); color: var(--ink); padding: 7px 8px; font-family: inherit; font-size: var(--text-body); font-weight: var(--weight-regular); }
.date-equivalent { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); border-radius: 7px; background: var(--soft); padding: 9px; font-size: var(--text-small); }
.date-equivalent output { color: var(--ink); font-size: var(--text-control); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; text-align: end; }
.transcript summary { font-weight: var(--weight-semibold); cursor: pointer; }
#transactions { padding-bottom: 40px; }
.ledger-heading { display: flex; align-items: end; flex-wrap: wrap; gap: 16px; justify-content: space-between; margin-bottom: 20px; }
.ledger-heading label { display: grid; gap: 6px; min-width: min(220px, 100%); font-size: var(--text-small); font-weight: var(--weight-medium); }
.ledger-heading select { font-family: inherit; min-height: 44px; padding: 8px; border: 1px solid var(--line-control); border-radius: 7px; background: var(--paper); color: var(--ink); }
#ledger-totals, #ledger-entries { list-style: none; margin: 0; padding: 0; }
#ledger-totals { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#ledger-totals li { border: 1px solid var(--khata-rim); border-radius: 11px; background: var(--khata-summary); box-shadow: var(--khata-card-shadow); padding: 9px 12px; font-size: var(--text-small); font-variant-numeric: tabular-nums; }
.ledger-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px 22px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 15px; margin-bottom: 9px; }
.ledger-entry-info, .ledger-money { display: grid; gap: 4px; }
.ledger-entry-info { overflow-wrap: anywhere; }
.ledger-reason { font-size: var(--text-control); }
.ledger-date, .ledger-account, .ledger-money span, #ledger-empty, #ledger-status { color: var(--muted); font-size: var(--text-small); }
.ledger-money { text-align: right; font-variant-numeric: tabular-nums; font-size: var(--text-body); }
.ledger-action { min-height: 44px; }
.ledger-feedback { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .ledger-entry { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .ledger-action { grid-column: 1 / -1; justify-self: start; }
}
#transaction-form .actions { position: sticky; bottom: 0; margin-top: 12px; padding: 9px 0 1px; background: var(--paper); }

/* Chat, recorder and ledger share the app shell. */
.topbar { background: var(--surface); }
.topbar-inner { min-height: 68px; }
.app-nav { width: fit-content; margin: 20px auto 26px; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--soft); }
.app-nav .nav-link { min-height: 43px; display: flex; align-items: center; gap: 8px; padding: 8px 17px; border-radius: 10px; }
.app-nav .nav-link.active { background: var(--selected); color: var(--khata-accent-ink); font-weight: var(--weight-semibold); }
.nav-icon { display: block; position: relative; width: 18px; height: 18px; color: currentColor; }
.icon-chat::before { content: ""; position: absolute; inset: 2px 1px 3px; border: 1.7px solid; border-radius: 5px; }
.icon-chat::after { content: ""; position: absolute; bottom: 2px; left: 4px; width: 4px; height: 4px; border-bottom: 1.7px solid; border-left: 1.7px solid; transform: skewY(-35deg); background: var(--soft); }
.active .icon-chat::after { background: var(--selected); }
.icon-record::before { content: ""; position: absolute; inset: 1px 5px 4px; border: 1.7px solid; border-radius: 6px; }
.icon-record::after { content: ""; position: absolute; inset: 7px 2px 1px; border: solid; border-width: 0 1.7px 1.7px; border-radius: 0 0 9px 9px; }
.icon-ledger::before { content: ""; position: absolute; inset: 1px 2px; border: 1.7px solid; border-radius: 3px; }
.icon-ledger::after { content: ""; position: absolute; top: 6px; left: 6px; width: 6px; height: 1.7px; background: currentColor; box-shadow: 0 4px currentColor; }
.chat-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; width: min(100%, 820px); margin: 0 auto 26px; height: min(760px, calc(100dvh - 172px)); min-height: 475px; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); overflow: hidden; box-shadow: var(--khata-float-shadow); }
.chat-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 17px 23px 16px; border-bottom: 1px solid var(--line); }
.chat-heading h1 { font-size: 1.25rem; }
.pay-link { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 13px; border-radius: 10px; background: var(--fill); color: var(--fill-text); box-shadow: var(--khata-action-shadow); text-decoration: none; font-size: var(--text-small); font-weight: var(--weight-medium); }
.pay-link:hover { background: var(--fill-hover); }
.pay-plus { font-size: 18px; line-height: 1; font-weight: var(--weight-medium); color: var(--fill-text); }
.chat-scroll { overflow: auto; overscroll-behavior: contain; min-height: 0; scrollbar-width: thin; }
.chat-empty { display: grid; align-content: center; min-height: 100%; padding: 26px max(18px, calc((100% - 530px) / 2)); }
.assistant-mark { display: flex; justify-content: center; align-items: center; gap: 3px; width: 43px; height: 43px; border-radius: 13px; background: var(--soft); margin-bottom: 13px; }
.assistant-mark i { display: block; width: 3px; height: 9px; border-radius: 2px; background: var(--khata-accent-ink); }
.assistant-mark i:nth-child(2) { height: 19px; }
.chat-empty h2 { font-size: clamp(1.25rem, 3vw, 1.625rem); letter-spacing: -.018em; }
.chat-empty > p { color: var(--muted); font-size: var(--text-control); margin: 8px 0 16px; line-height: 1.45; }
.suggestions { display: grid; gap: 6px; max-width: 390px; }
.suggestions button { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; padding: 8px 12px; min-height: 43px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted); font-size: var(--text-small); font-weight: var(--weight-medium); }
.suggestions button:hover { background: var(--soft); }
.suggestions button span { font-size: var(--text-body); color: var(--muted); }
.chat-messages { display: grid; gap: 14px; padding: 19px 23px; margin: 0; list-style: none; }
.chat-messages:empty { padding: 0; }
.message { display: flex; align-items: flex-start; }
.message.user { justify-content: flex-end; }
.bubble { min-width: 0; max-width: min(100%, 600px); overflow-wrap: anywhere; }
.user .bubble { max-width: min(83%, 535px); border-radius: 14px 14px 4px 14px; padding: 10px 14px; background: var(--selected); color: var(--ink); font-size: var(--text-control); }
.question-text { white-space: pre-wrap; }
.assistant .bubble { width: fit-content; min-width: min(100%, 290px); padding: 13px 14px; border-radius: 4px 14px 14px 14px; background: var(--canvas); border: 1px solid var(--line); font-size: var(--text-control); }
.assistant .bubble:has(.answer-total) { background: var(--khata-summary); border-color: var(--khata-rim); box-shadow: var(--khata-card-shadow); }
.answer-total { display: block; color: var(--ink); font-size: 1.375rem; letter-spacing: -.018em; font-variant-numeric: tabular-nums; }
.answer-body { line-height: 1.45; }
.answer-filters { margin-top: 4px; font-size: var(--text-meta); color: var(--muted); }
.answer-sources { list-style: none; margin: 8px 0 0; padding: 0; }
.answer-source { display: grid; align-items: center; width: 100%; gap: 9px; grid-template-columns: minmax(0,1fr) auto auto; text-align: left; padding: 8px 0; min-height: 48px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); font-size: var(--text-small); }
.answer-source:hover, .source-arrow { color: var(--khata-accent-ink); }
.source-info { display: grid; gap: 2px; min-width: 0; }
.source-date, .source-reason { font-size: var(--text-caption); color: var(--muted); }
.source-amount { font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.more-transactions { display: inline-flex; align-items: center; min-height: 44px; color: var(--khata-accent-ink); font-weight: var(--weight-medium); }
.composer-area { border-top: 1px solid var(--line); padding: 12px 22px 8px; background: var(--paper); box-shadow: var(--khata-sticky-shadow); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 5px; border: 1px solid var(--line-control); border-radius: 15px; background: var(--surface); }
.composer:focus-within { border-color: var(--focus); }
.composer textarea { display: block; flex: 1; min-width: 0; min-height: 44px; max-height: 92px; field-sizing: content; resize: none; font: inherit; font-size: var(--text-body); color: var(--ink); border: 0; padding: 11px 8px; background: transparent; }
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--subtle); }
.ask-mic, .ask-send { position: relative; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 11px; flex: 0 0 44px; }
.ask-mic { color: var(--muted); background: var(--soft); }
.ask-mic .mic { transform: translateY(-3px) scale(.68); }
.ask-mic[data-mode="recording"] { background: var(--selected); color: var(--muted); }
.ask-mic[data-mode="recording"] .mic, .ask-stop { display: none; }
.ask-mic[data-mode="recording"] .ask-stop { display: block; width: 13px; height: 13px; border-radius: 3px; background: currentColor; }
.ask-send { color: var(--fill-text); background: var(--fill); font-size: 22px; }
.ask-send:enabled:hover { background: var(--fill-hover); }
.composer-foot { display: flex; justify-content: space-between; gap: 5px; align-items: center; color: var(--muted); margin-top: 4px; font-size: var(--text-caption); }
#clear-chat { min-height: 32px; border: none; background: transparent; color: var(--muted); font: inherit; text-decoration: underline; }
.ask-progress { margin-bottom: 7px; color: var(--muted); font-size: var(--text-small); }
.ask-retry { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-bottom: 8px; }
.ask-retry p { flex: 1 1 165px; font-size: var(--text-small); color: var(--ink); }
.ask-retry button { min-height: 40px; padding-inline: 9px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#recorder-workspace { grid-template-columns: minmax(0, 1fr); max-width: 680px; margin: auto; gap: 16px; }
#library summary { display: flex; align-items: center; gap: 8px; min-height: 42px; cursor: pointer; font-size: var(--text-control); font-weight: var(--weight-medium); }
#library summary::after { content: "⌄"; margin-left: auto; font-size: 18px; color: var(--muted); }
#library[open] summary::after { content: "⌃"; }
#library:not([open]) { padding-block: 7px; }
#transactions { max-width: 910px; margin: auto; }

@media (max-width: 760px) {
  .topbar-inner, .shell { width: calc(100% - 24px); }
  .topbar-inner { min-height: 55px; }
  .brand { font-size: 1.125rem; }
  .brand-mark { width: 29px; height: 29px; }
  .shell { padding: 9px 0 calc(69px + env(safe-area-inset-bottom)); }
  .app-nav { position: fixed; z-index: 3; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(3,1fr); width: auto; margin: 0; padding: 5px 12px calc(5px + env(safe-area-inset-bottom)); gap: 7px; border-width: 1px 0 0; border-radius: 0; background: var(--surface); box-shadow: var(--khata-sticky-shadow); }
  .app-nav .nav-link { display: grid; justify-items: center; align-content: center; gap: 1px; min-height: 50px; padding: 4px; font-size: var(--text-caption); }
  .icon-chat::after { background: var(--surface); }
  .chat-shell { margin: 0; height: calc(100dvh - 128px - env(safe-area-inset-bottom)); min-height: 355px; border-radius: 16px; }
  .chat-heading { padding: 12px 13px; }
  .chat-heading h1 { font-size: 1.125rem; }
  .pay-link { min-height: 44px; padding: 6px 9px; font-size: var(--text-meta); }
  .chat-empty { padding: 17px; }
  .chat-empty > p { font-size: var(--text-small); margin-bottom: 11px; }
  .assistant-mark { margin-bottom: 9px; width: 36px; height: 36px; }
  .chat-messages { padding: 13px 12px; }
  .assistant .bubble { padding: 11px; }
  .composer-area { padding: 8px 9px 5px; }
  .composer textarea { font-size: 1rem; }
  #clear-chat { min-height: 35px; }
  #recorder-workspace, #transactions { padding-top: 12px; padding-bottom: 8px; }
}
@media (max-width: 345px) {
  .pay-link { padding-inline: 7px; font-size: var(--text-caption); }
  .source-amount { max-width: 82px; text-align: right; }
  .answer-source { gap: 6px; }
}
.ledger-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.ledger-filters label { min-width: 140px; }
.due-status { font-weight: var(--weight-semibold); }
#due-date-equivalent { align-self: end; min-height: 40px; }
@media (max-width: 600px) { .ledger-filters { width: 100%; } .ledger-filters label { flex: 1; min-width: 110px; } }
.mic-modes { display: flex; gap: 7px; margin-bottom: 6px; }
.mic-modes button { min-height: 36px; padding: 4px 11px; border: 1px solid var(--line-control); border-radius: 18px; background: var(--paper); color: var(--ink); font-size: var(--text-meta); font-weight: var(--weight-medium); }
.mic-modes button[aria-pressed="true"] { color: var(--khata-accent-ink); background: var(--selected); border-color: var(--khata-rim); }
.message.transaction { justify-content: flex-end; }
.transaction .bubble { border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 10px 13px; background: var(--soft); }
.chat-capture-state { margin-top: 4px; color: var(--muted); font-size: var(--text-meta); }
.chat-capture-action { min-height: 44px; margin-top: 4px; padding: 0; border: 0; background: transparent; color: var(--ink); font-size: var(--text-small); font-weight: var(--weight-semibold); text-decoration: underline; }
.message.attachment { justify-content: flex-end; }
.attachment .bubble { border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 10px 13px; background: var(--soft); }
.attach-file { font-size: 23px; }
#attachment-dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100dvh - 24px); }
#attachment-original { display: inline-block; margin-top: 6px; font-size: var(--text-small); }
#attachment-columns { margin-top: 14px; }
#attachment-columns label { font-size: var(--text-small); font-weight: var(--weight-medium); }
#attachment-columns select { max-width: 100%; border: 1px solid var(--line-control); border-radius: 6px; padding: 7px; font: inherit; }
.column-mapping { margin: 9px 0; }
.column-mapping summary, .attachment-row summary { min-height: 38px; padding-top: 7px; cursor: pointer; font-size: var(--text-control); font-weight: var(--weight-semibold); }
#apply-mapping { margin-top: 8px; }
.attachment-row { border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; margin: 8px 0; }
.attachment-check { display: flex; gap: 8px; min-height: 37px; align-items: center; font-size: var(--text-small); font-weight: var(--weight-semibold); }
.attachment-check input { width: 18px; height: 18px; accent-color: var(--fill); }
#attachment-dialog .actions { position: sticky; bottom: 0; padding-top: 8px; background: var(--paper); }
#attachment-excerpt { white-space: pre-wrap; }
.monthly-report { border: 1px solid var(--line); border-radius: 10px; background: var(--paper); padding: 0 13px; margin: 0 0 15px; }
.monthly-report summary { min-height: 44px; padding-top: 12px; font-size: var(--text-control); font-weight: var(--weight-semibold); cursor: pointer; }
.monthly-report form, .report-bs { display: flex; flex-wrap: wrap; gap: 9px; align-items: flex-end; }
.monthly-report form { padding-top: 4px; }
.monthly-report label { display: grid; gap: 5px; font-size: var(--text-small); font-weight: var(--weight-medium); }
.monthly-report input, .monthly-report select { min-height: 44px; padding: 7px; color: var(--ink); border: 1px solid var(--line-control); border-radius: 7px; background: var(--paper); font-family: inherit; }
.monthly-report p { margin: 10px 0 12px; color: var(--muted); font-size: var(--text-small); }
.report-download { display: inline-flex; align-items: center; min-height: 44px; padding: 0 11px; margin-top: 8px; border: 1px solid var(--line-control); border-radius: 7px; color: var(--ink); font-weight: var(--weight-semibold); }
@media (max-width:600px) { .monthly-report form > button { width: 100%; min-height: 44px; } }
#loan-field input[type=checkbox] { width: 18px; min-height: 18px; height: 18px; vertical-align: middle; margin: 0 6px 0 0; }
#insights { max-width: 950px; margin: auto; width: 100%; padding-bottom: 65px; }
#insights .ledger-heading p, .insight-note { color:var(--muted); margin:8px 0; font-size: var(--text-small); }
#insights input, #insights select { border:1px solid var(--line-control); min-height:44px; padding:6px; border-radius:7px; background:var(--paper); font-family: inherit; }
.insight-card { border:1px solid var(--line); border-radius:12px; padding:15px; margin-bottom:14px; background:var(--paper); }
.insight-card h3 { margin:12px 0 6px; font-size: var(--text-body); }
.insight-metrics { display:flex; gap:12px; flex-wrap:wrap; margin:10px 0 14px; }
.insight-metrics div { background: var(--khata-summary); border: 1px solid var(--khata-rim); box-shadow: var(--khata-card-shadow); border-radius: 9px; padding: 7px 10px; }
.insight-metrics dt { font-size: var(--text-meta); color:var(--muted); }
.insight-metrics dd { margin:3px 0 0; font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.insight-table-wrap { overflow:auto; }
.insight-table { width:100%; border-collapse:collapse; font-size: var(--text-small); }
.insight-table th,.insight-table td { padding:6px 8px; border-bottom:1px solid var(--line); text-align:left; }
.category-period { display:flex; gap:10px; align-items:center; margin:14px 0 5px; font-weight: var(--weight-medium); }
.insight-expenses, #reminder-entries { list-style:none; padding:0; }
.insight-expenses li, #reminder-entries li { display:flex; flex-wrap:wrap; gap:9px; align-items:center; justify-content:space-between; padding:5px 0; }
.chat-shell.has-reminders { grid-template-rows:auto auto minmax(0,1fr) auto; }
.due-reminders { padding:0 14px; background:var(--soft); border-bottom:1px solid var(--line); font-size: var(--text-small); }
.due-reminders summary { padding:10px 0; cursor:pointer; font-weight: var(--weight-semibold); }
@media (max-width:760px) { .app-nav { grid-template-columns:repeat(4,1fr); gap:4px; } }
.auth-shell { width:min(100% - 32px,420px); margin:45px auto; }
.auth-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auth-card { margin-top: 23px; padding: 21px; border-radius: 14px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--khata-float-shadow); }
.auth-card p { margin:9px 0; color:var(--muted); font-size: var(--text-control); }
.auth-card form { display:grid; gap:12px; margin:17px 0 10px; }
.auth-card label { display:grid; gap:5px; font-weight: var(--weight-medium); font-size: var(--text-small); }
.auth-card input { min-height: 44px; padding: 7px 10px; border: 1px solid var(--line-control); border-radius: 7px; font-size: var(--text-body); }
#sign-out { min-height:35px; margin-left:5px; }
#messages { width: 100%; max-width: 1050px; margin: 0 auto 28px; }
.messages-layout {
  display: grid; grid-template-columns: minmax(260px, 34%) minmax(0, 1fr);
  height: clamp(460px, calc(100dvh - 163px), 780px); border: 1px solid var(--line);
  background: var(--paper); border-radius: 22px; overflow: hidden; box-shadow: var(--khata-float-shadow);
}
.messages-inbox { min-width: 0; overflow: auto; border-right: 1px solid var(--line); }
.messages-inbox-header { padding: 21px 18px 11px; border-bottom: 1px solid var(--line); }
.messages-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 14px; }
#new-message { background: var(--fill); border-radius: 10px; box-shadow: var(--khata-action-shadow); white-space: nowrap; }
#new-message:enabled:hover, #send-secure-message button[type=submit]:enabled:hover { background: var(--fill-hover); }
#new-message span { margin-right: 2px; }
.message-search, .message-form label, #onboarding label { display: grid; gap: 5px; width: 100%; font-size: var(--text-small); font-weight: var(--weight-medium); }
#onboarding label:not(.phone-opt-in) { display: block; margin-top: 12px; }
#onboarding-phone { display: block; margin-top: 5px; }
#onboarding label small { margin-left: 4px; color: var(--muted); font-weight: var(--weight-regular); }
.message-search input, .message-form input:not([type=checkbox]), #onboarding-phone, #passkey-password {
  min-height: 44px; border: 1px solid var(--line-control); border-radius: 9px; padding: 8px 10px; width: 100%;
}
.message-search input { padding-inline: 12px; background: var(--surface); color: var(--ink); font-size: var(--text-small); font-weight: var(--weight-medium); }
.message-search input:disabled { opacity: .75; }
.message-request-button {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; margin-top: 7px; padding: 6px 8px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: var(--text-small); font-weight: var(--weight-semibold);
}
.message-request-button:hover { background: var(--soft); }
#message-request-count { min-width: 19px; padding: 2px 5px; border-radius: 15px; background: var(--fill); color: var(--fill-text); font-size: var(--text-caption); }
#message-contacts, #secure-thread, .message-request-section ul, .message-contact-list { list-style: none; padding: 0; margin: 0; }
#message-contacts { padding: 7px; }
.message-conversation {
  display: grid; align-items: center; grid-template-columns: auto minmax(0,1fr) auto; gap: 10px; width: 100%;
  min-height: 68px; padding: 8px 11px; border: 0; border-radius: 11px; background: var(--paper); color: var(--ink); text-align: left;
}
.message-conversation:hover { background: var(--soft); }
.message-conversation[aria-current] { background: var(--selected); }
.message-avatar { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 40px; border-radius: 50%; background: var(--selected); color: var(--khata-accent-ink); font-size: var(--text-small); font-weight: var(--weight-semibold); }
.message-conversation-details { min-width: 0; display: grid; gap: 4px; }
.message-conversation-details strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--text-control); }
.message-conversation-details > span, .message-row-arrow, .message-row-time { color: var(--muted); font-size: var(--text-meta); }
.message-row-arrow { font-size: 18px; }
.message-pane { min-width: 0; min-height: 0; display: grid; background: var(--surface); }
.message-empty { display: grid; justify-items: center; align-content: center; gap: 7px; padding: 30px 18px; text-align: center; }
.message-empty h2 { font-size: 1rem; }
.message-empty p { max-width: 26ch; color: var(--muted); font-size: var(--text-small); }
.message-empty-icon { display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); margin-bottom: 3px; color: var(--muted); }
.message-empty-icon::before { inset: 13px 12px 16px; }
.message-empty-icon::after { bottom: 13px; left: 16px; background: var(--paper); }
#active-message-thread { display: grid; min-width: 0; min-height: 0; grid-template-rows: auto minmax(0,1fr) auto; }
.message-thread-header { display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 10px 15px; background: var(--paper); border-bottom: 1px solid var(--line); }
.message-thread-title { flex: 1 1 0; min-width: 0; }
#thread-heading { font-size: 1rem; overflow-wrap: anywhere; }
#thread-handle { color: var(--muted); font-size: var(--text-caption); overflow-wrap: anywhere; }
#message-back { display: none; font-size: 22px; min-width: 44px; padding-inline: 7px; }
#remove-message-contact { margin-left: auto; font-size: var(--text-meta); flex: 0 0 auto; padding-inline: 8px; }
.message-thread-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px clamp(12px, 3vw, 25px); }
#secure-thread { display: grid; gap: 9px; }
#secure-thread li { justify-self: start; min-width: 0; max-width: min(85%, 440px); border: 1px solid var(--line); border-radius: 15px 15px 15px 4px; background: var(--paper); color: var(--ink); padding: 9px 12px 6px; }
#secure-thread li.sent { justify-self: end; background: var(--selected); color: var(--ink); border-color: var(--selected); border-radius: 15px 15px 4px 15px; }
#secure-thread p { font-size: var(--text-body); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
#secure-thread time { display: block; text-align: right; color: var(--muted); font-size: var(--text-meta); font-variant-numeric: tabular-nums; margin-top: 4px; }

#message-thread-notice { max-width: 380px; margin: 12px auto; text-align: center; }
#thread-status, .message-status, #phone-verification-status, #contact-source-hint { color: var(--muted); font-size: var(--text-small); overflow-wrap: anywhere; }
#message-enable { margin-top: 8px; }
#verify-contact { text-align: left; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
#contact-code { color: var(--ink); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: var(--text-control); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
#send-secure-message { display: grid; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--paper); box-shadow: var(--khata-sticky-shadow); }
.message-compose-row { display: flex; align-items: end; gap: 7px; flex-wrap: wrap; }
.message-media-tools { display: flex; gap: 2px; }
.message-media-tools .quiet { min-height: 45px; padding-inline: 7px; font-size: var(--text-small); }
#send-secure-message textarea { flex: 1; min-width: 0; min-height: 45px; max-height: 125px; resize: vertical; padding: 11px; border: 1px solid var(--line-control); border-radius: 12px; color: var(--ink); background: var(--surface); font: inherit; }
#send-secure-message button[type=submit] { min-height: 45px; background: var(--fill); border-radius: 11px; }
#message-media-preview { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 7px; border-radius: 8px; background: var(--soft); min-width: 0; }
#message-media-draft { min-width: 0; overflow-wrap: anywhere; font-size: var(--text-small); }
.message-attachment { display: grid; gap: 6px; max-width: 100%; }
#secure-thread .message-attachment-label, #secure-thread .message-attachment-error { font-size: var(--text-meta); }
.message-attachment img, #message-media-draft img { max-width: 100%; max-height: 200px; object-fit: contain; object-position: left center; }
#message-media-draft img { max-height: 65px; }
.message-attachment audio, #message-media-draft audio { min-width: 0; width: min(220px,100%); }
.message-attachment button { justify-self: start; }
.message-form { display: grid; gap: 9px; margin: 10px 0 0; }
.message-form button { justify-self: start; }
.message-form p { margin: 0; font-size: var(--text-small); color: var(--muted); }
#onboarding .phone-opt-in, .message-form .message-opt-in { display: flex; align-items: center; gap: 7px; min-height: 44px; }
.message-dialog { width: min(470px, calc(100dvw - 24px)); max-height: calc(100dvh - 28px); padding: 17px 19px 19px; }
.message-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.message-dialog-heading button { font-size: 21px; min-width: 44px; }
.message-dialog h3, #verify-contact h3 { font-size: var(--text-control); margin: 0; }
.message-mobile { border-top: 1px solid var(--line); margin-top: 15px; padding-top: 5px; }
.message-mobile summary { cursor: pointer; min-height: 44px; padding-block: 13px 8px; font-size: var(--text-small); font-weight: var(--weight-medium); }
.message-request-section { margin-top: 12px; }
.message-request-section li { margin: 6px 0; padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; font-size: var(--text-small); }
.message-request-section li > span { display: block; margin-top: 5px; }
.message-request-actions, .contact-sources { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.contact-file { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.contact-file:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.contact-file input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
#contact-review { margin: 15px 0 10px; }
#contact-candidates { max-height: 172px; overflow: auto; margin: 5px 0 8px; }
.contact-choice, .contact-match { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 5px 2px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.contact-choice input { width: 17px; height: 17px; flex: 0 0 17px; accent-color: var(--fill); }
.contact-match { justify-content: space-between; margin: 5px 0; }
.contact-match button { flex-shrink: 0; }
.contact-choice strong, .contact-match strong { display: block; font-size: var(--text-small); }
.contact-choice small, .contact-match small { display: block; color: var(--muted); font-size: var(--text-meta); }
@media (max-width: 760px) {
  body:has(#messages:not([hidden])) #passkey-set-up { display: none; }
  .app-nav.has-messages { grid-template-columns: repeat(5,minmax(0,1fr)); }
  .app-nav.has-messages .nav-link { font-size: var(--text-caption); min-width: 0; }
  #messages { margin-bottom: 0; }
  .messages-layout { grid-template-columns: minmax(0,1fr); height: max(350px, calc(100dvh - 129px - env(safe-area-inset-bottom))); border-radius: 16px; }
  .messages-inbox { border-right: 0; }
  .messages-inbox-header { padding: 15px 14px 8px; }
  .message-pane, #messages.has-selected-conversation .messages-inbox { display: none; }
  #messages.has-selected-conversation .message-pane { display: grid; }
  #message-back { display: block; }
  .message-thread-header { gap: 6px; padding-inline: 6px; }
  .message-thread-header .message-avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: var(--text-caption); }
  #remove-message-contact { font-size: var(--text-caption); padding-inline: 5px; }
  #send-secure-message textarea, .transaction-fields input:not([type=checkbox]), .transaction-fields select,
  .auth-card input, .message-form input:not([type=checkbox]), #onboarding-phone { font-size: 1rem; }
  .message-media-tools { flex: 0 0 100%; }
  .message-media-tools .quiet { min-height: 39px; padding-inline: 9px; }
  .private .secondary { padding-inline: 9px; font-size: var(--text-meta); }
}
@media (max-width: 420px) {
  .private > span[aria-hidden] { display: none; }
  .private { gap: 5px; }
}
@media (max-width: 540px) {
  .private { flex-wrap: wrap; justify-content: flex-end; }
  .private:has(#sign-out:not([hidden])) #workspace-label,
  .private:has(#sign-out:not([hidden])) > span[aria-hidden] { display: none; }
  .private .theme-control > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media (375px <= width <= 420px) {
  .private .secondary { white-space: nowrap; }
}
