/* Spendly — hand-written styles, no build step. Light and dark follow the OS. */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #171a23;
  --muted: #646b7d;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #15803d;      --ok-soft: #e7f6ec;
  --warn: #b45309;    --warn-soft: #fdf3e2;
  --grey: #4b5563;    --grey-soft: #eef0f3;
  --bad: #b91c1c;     --bad-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3d;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --accent: #818cf8;
    --accent-2: #a5b4fc;
    --accent-soft: #23264a;
    --accent-text: #0f1117;
    --danger: #f87171;
    --danger-soft: #3a1d22;
    --ok: #4ade80;   --ok-soft: #173325;
    --warn: #fbbf24; --warn-soft: #3a2d14;
    --grey: #c0c6d4; --grey-soft: #262b38;
    --bad: #f87171;  --bad-soft: #3a1d22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.hidden { display: none !important; }

/* --- buttons and inputs ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 600 14px var(--font); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-success { color: var(--ok); }
.btn-success:hover { background: var(--ok-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 14px var(--font);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* --- auth pages -------------------------------------------------------------------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 32px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 32px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-size: 17px; }
.auth-card h1 { margin: 22px 0 4px; }
.auth-card p.lead { margin: 0 0 22px; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 14px;
  background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.demo-accounts { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
.demo-accounts summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
.demo-accounts table { width: 100%; margin-top: 10px; font-size: 12.5px; border-collapse: collapse; }
.demo-accounts td { padding: 5px 4px; border-bottom: 1px solid var(--border); }
.demo-accounts tr { cursor: pointer; }
.demo-accounts tr:hover td { background: var(--surface-2); }

/* --- app shell --------------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.me { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; }
.me-name { font-weight: 700; font-size: 14px; }
.me-email { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.me .badges { margin: 8px 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.content { padding: 24px 28px 40px; max-width: 1180px; width: 100%; }

/* --- cards, tables, pills ---------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px;
  border-bottom: 1px solid var(--border); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 700; padding: 11px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.data td { padding: 13px 20px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.title-cell { font-weight: 600; }
.sub { font-size: 12.5px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-transform: capitalize; background: var(--grey-soft); color: var(--grey); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.submitted { background: var(--warn-soft); color: var(--warn); }
.pill.approved { background: var(--ok-soft); color: var(--ok); }
.pill.rejected { background: var(--bad-soft); color: var(--bad); }
.pill.invited { background: var(--warn-soft); color: var(--warn); }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px;
  font-weight: 700; background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.badge.role-owner { background: var(--accent-soft); color: var(--accent); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.search { position: relative; width: 320px; max-width: 100%; }
.search svg { position: absolute; left: 11px; top: 11px; width: 18px; height: 18px; color: var(--muted); }
.search .input { padding-left: 36px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font: 600 13px var(--font); cursor: pointer; }
.tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }

/* --- detail -------------------------------------------------------------------------- */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 12px 16px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.amount-big { font-size: 34px; font-weight: 800; letter-spacing: -.03em; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; color: var(--muted); }

/* --- modal and toast ----------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); display: grid; place-items: center;
  padding: 16px; z-index: 50; animation: fade .12s ease-out; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 24px; animation: pop .14s ease-out; }
.modal h2 { margin-bottom: 8px; }
.modal .row { justify-content: flex-end; margin-top: 20px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 60;
  animation: pop .14s ease-out; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px) scale(.98); } }
.modal { animation-name: fade; }

/* --- chat ------------------------------------------------------------------------------ */
.chat { display: flex; flex-direction: column; height: calc(100vh - 64px); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 28px 28px 12px; }
.chat-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 13px;
  font-weight: 800; background: var(--surface-2); color: var(--muted); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; }
.bubble { max-width: 640px; padding: 11px 15px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.bubble.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tool-chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; font-size: 12px; max-width: 640px; }
.tool-chip summary { list-style: none; cursor: pointer; padding: 4px 10px; display: flex; gap: 6px; align-items: center; font-family: var(--mono); }
.tool-chip summary::-webkit-details-marker { display: none; }
.tool-chip .code { font-weight: 700; }
.tool-chip .code.ok { color: var(--ok); } .tool-chip .code.err { color: var(--danger); }
.tool-chip pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); font: 11.5px/1.45 var(--mono);
  max-height: 240px; overflow: auto; white-space: pre-wrap; }
.welcome { text-align: center; padding: 40px 0 8px; }
.welcome .brand-mark { width: 52px; height: 52px; font-size: 26px; border-radius: 14px; margin: 0 auto 14px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.suggestion { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px;
  font: 600 13px var(--font); color: var(--text); cursor: pointer; }
.suggestion:hover { border-color: var(--accent); color: var(--accent); }
.composer { padding: 14px 28px 22px; background: linear-gradient(transparent, var(--bg) 30%); }
.composer form { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 8px 14px; box-shadow: var(--shadow); }
.composer form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font: 15px/1.5 var(--font); padding: 7px 0; max-height: 160px; min-height: 24px; }
.composer .hint { max-width: 780px; margin: 8px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* --- responsive ------------------------------------------------------------------------ */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; gap: 12px; overflow-x: auto; }
  .sidebar .brand span { display: none; }
  .nav { flex-direction: row; }
  .me { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; }
  .me-name, .me-email, .me .badges { display: none; }
  .topbar { position: static; padding: 0 16px; }
  .content { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .detail { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .chat { height: calc(100vh - 124px); }
  .chat-scroll, .composer { padding-left: 16px; padding-right: 16px; }
  .hide-sm { display: none; }
}
