:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14181f; --muted: #5b6472; --line: #dde1e7;
  --accent: #1f5fbf; --accent-ink: #ffffff; --good: #1e7a46; --warn: #b77900; --bad: #c62828;
  --live-bg: #e8f0fc; --chip: #eef1f5; --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #181c22; --ink: #e8ebf0; --muted: #9aa3b0; --line: #2a3039;
    --accent: #5b9bff; --accent-ink: #0b0e12; --good: #4cc27f; --warn: #f2b93b; --bad: #ff6b6b;
    --live-bg: #16263d; --chip: #232932; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --panel: #181c22; --ink: #e8ebf0; --muted: #9aa3b0; --line: #2a3039;
  --accent: #5b9bff; --accent-ink: #0b0e12; --good: #4cc27f; --warn: #f2b93b; --bad: #ff6b6b;
  --live-bg: #16263d; --chip: #232932; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 14px; min-height: 44px; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.ghost { background: transparent; }
.icon-btn { min-width: 44px; padding: 8px; background: transparent; border-color: transparent; font-size: 20px; line-height: 1; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row-btns > button { flex: 1 1 auto; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; min-height: 0; border-radius: 999px; background: var(--chip); border: 1px solid transparent; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.muted { color: var(--muted); }
.bad { color: var(--bad); }
.tabular { font-variant-numeric: tabular-nums; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; max-width: calc(100vw - 32px); transition: transform .2s; z-index: 50; }
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.sheet { background: var(--panel); color: var(--ink); width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -8px; background: var(--panel); padding-top: 8px; }
.sheet-head h2 { font-size: 18px; margin: 8px 0; }
.choose p { margin: 4px 0 8px; }
.conn { background: var(--warn); color: #000; border-radius: 8px; padding: 4px 10px; font-size: 13px; }
[hidden] { display: none !important; }

/* borrow timeline (display + admin) */
.tl-prompt { font-weight: 600; margin-bottom: 8px; }
.tl-strip { display: flex; align-items: flex-start; gap: 6px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.tl-block { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 8px 10px; min-height: 84px; border-radius: 10px; overflow: hidden; background: var(--panel); transition: width .25s; }
.tl-block.ok { border-color: var(--accent); }
.tl-block.no { opacity: .55; }
.tl-block.pinned { background: var(--chip); }
.tl-block.picked { outline: 3px solid var(--accent); }
.tl-block.shrinking .tl-meta { color: var(--warn); font-weight: 600; }
.tl-block:disabled { opacity: 1; cursor: default; }
.tl-time { font-size: 13px; color: var(--muted); }
.tl-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.tl-meta { font-size: 13px; color: var(--muted); }
.tl-day { flex: 0 0 auto; writing-mode: vertical-rl; transform: rotate(180deg); font-size: 13px; font-weight: 600; color: var(--muted); border-left: 2px dashed var(--line); padding: 0 6px; }
.tl-empty { color: var(--muted); padding: 16px; }
.tl-amounts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tl-amounts .chip { min-height: 36px; padding: 4px 14px; font-size: 15px; }
.tl-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; padding: 10px; background: var(--live-bg); border-radius: 10px; }
.tl-preview span { flex: 1 1 200px; }
.tl-preview.bad { background: transparent; border: 1px solid var(--bad); }
