/* Finrep prototype kit v0. Design-v2 primitives as plain CSS on tokens.css.
   Sizes follow the interface guidelines for prototypes (brand book "Control sizing"):
   40px default and 32px small controls. Rule IDs from interface-design-guidelines.md. */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:ital,wght@0,400;0,600;1,400&display=swap");

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: 14px; line-height: 20px;
  color: var(--foreground); background: var(--background);
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary); text-decoration: none; font-weight: 500; } /* C-11 action link */
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
[hidden] { display: none !important; }
svg.lucide { width: 16px; height: 16px; stroke-width: 2; flex-shrink: 0; }

/* Type (T-05..T-09) */
.t-page { font-size: 20px; line-height: 28px; font-weight: 600; letter-spacing: -0.2px; }
.t-title { font-size: 14px; line-height: 20px; font-weight: 600; }
.t-label { font-size: 14px; line-height: 20px; font-weight: 500; }
.t-meta, .muted { color: var(--muted-foreground); }
.t-meta { font-size: 12px; line-height: 16px; }
.t-num { font-variant-numeric: tabular-nums; text-align: right; }
.prose { font-family: var(--font-serif); font-size: 16px; line-height: 24px; max-width: 70ch; } /* T-02, L-25 */
.prose p + p { margin-top: 12px; }
.prose h3 { font-family: var(--font-serif); font-size: 16px; font-weight: 600; margin: 20px 0 8px; }

/* Layout helpers (L-07: 4,8,12,16,24,32,48) */
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.gap-4 { gap: 4px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.stack-24 > * + * { margin-top: 24px; }
.stack-16 > * + * { margin-top: 16px; }
.stack-8 > * + * { margin-top: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Workspace shell (L-01, L-14): top bar, no rail */
.ws { display: grid; grid-template-rows: 56px minmax(0, 1fr); height: 100%; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--background); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { width: 28px; height: 28px; border-radius: var(--radius-md); background: var(--primary); color: var(--primary-foreground); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; }
.topbar .sep { width: 1px; height: 20px; background: var(--border); }
.ws-body { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
.ws-body.with-panel { grid-template-columns: minmax(0, 1fr) 380px; }
.page { overflow: auto; min-height: 0; }
.page-inner { padding: 24px 32px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.page-head .grow > * + * { margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }

/* Section nav inside a workspace (list rail, separated by space; L-10, L-16) */
.split { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 0; height: 100%; }
.sidenav { border-right: 1px solid var(--border); padding: 16px 8px; overflow: auto; }
.sidenav .group { font-size: 12px; line-height: 16px; color: var(--muted-foreground); padding: 12px 12px 4px; }
.navitem { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: var(--radius-md); color: var(--foreground); font-weight: 500; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.navitem:hover { background: var(--accent); }
.navitem[aria-current="page"] { background: var(--muted-brand); color: var(--primary); }
.navitem .end { margin-left: auto; }

/* Buttons (B-01..B-06, Q-04) */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: var(--radius-lg); border: 1px solid transparent; font-weight: 500; font-size: 14px; white-space: nowrap; cursor: pointer; transition: background var(--motion-quick) ease-in-out, opacity var(--motion-quick); }
.btn.sm { height: 32px; padding: 0 10px; border-radius: var(--radius-md); }
.btn.icon { width: 40px; padding: 0; } .btn.sm.icon { width: 32px; }
.btn.primary { background: var(--primary); color: var(--primary-foreground); }
.btn.primary:hover { opacity: .9; }
.btn.outline { background: var(--background); border-color: var(--border); color: var(--foreground); box-shadow: var(--shadow-2xs); }
.btn.outline:hover { background: var(--accent); }
.btn.ghost { background: transparent; color: var(--foreground); }
.btn.ghost:hover { background: var(--accent); }
.btn.destructive { background: var(--destructive); color: #fff; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn .fina-spark { color: inherit; }

/* Badges (G-01, G-02, C-07): dot + word */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--radius-full); font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; background: var(--secondary); color: var(--secondary-foreground); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-foreground); color: var(--positive-text, #15803d); }
.badge.warning { background: var(--warning-foreground); color: #b45309; }
.badge.destructive { background: var(--destructive-foreground); color: var(--destructive); }
.badge.info { background: var(--information-foreground); color: #0369a1; }
.badge.brand { background: var(--muted-brand); color: var(--primary); }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full); background: var(--muted); color: var(--muted-foreground); font-size: 12px; font-weight: 500; }

/* Inputs (F-01, F-02) */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-weight: 500; }
.input, .select, textarea.input { height: 40px; width: 100%; border: 1px solid var(--input); border-radius: var(--radius-lg); padding: 0 12px; background: var(--background); }
.input.sm, .select.sm { height: 32px; border-radius: var(--radius-md); }
textarea.input { height: auto; min-height: 96px; padding: 8px 12px; resize: vertical; }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring) 25%, transparent); }

/* Tabs (X-01, X-02, Q-07): muted container, white active */
.tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius-lg); background: var(--muted); }
.tab { height: 30px; padding: 0 12px; border-radius: var(--radius-md); border: 0; background: none; font-weight: 500; color: var(--muted-foreground); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tab[aria-selected="true"] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
/* Top-bar tabs: underline (module/workspace header) */
.navtabs { display: flex; gap: 4px; height: 100%; }
.navtab { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 100%; color: var(--muted-foreground); font-weight: 500; border: 0; background: none; cursor: pointer; position: relative; }
.navtab[aria-selected="true"] { color: var(--foreground); }
.navtab[aria-selected="true"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: var(--foreground); }

/* Cards (K-01..K-03, L-15, L-18) */
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); padding: 16px; min-width: 0; }
.card.click { cursor: pointer; transition: background var(--motion-quick); }
.card.click:hover { background: var(--accent); }
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-head .grow > * + * { margin-top: 2px; }

/* Tables (D-01..D-05, L-24) */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; background: var(--background); text-align: left; font-weight: 500; color: var(--muted-foreground); height: 40px; padding: 0 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { height: 44px; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--accent); }
.table tr.selected td { background: var(--muted-brand); }

/* Key-value grid for form answers */
.kv { display: grid; grid-template-columns: minmax(180px, 40%) minmax(0, 1fr); gap: 0; }
.kv > div { padding: 10px 0; border-bottom: 1px solid var(--border); }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }

/* Question rows (Form items) */
.q { display: grid; grid-template-columns: 56px minmax(0, 1fr) minmax(200px, 32%) 112px; gap: 16px; align-items: start; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q:hover { background: var(--muted); }
.q .qid { color: var(--muted-foreground); font-weight: 500; }
.q .ans { font-weight: 500; }
.q .was { font-size: 12px; line-height: 16px; color: var(--muted-foreground); margin-top: 2px; }
.q .was s { text-decoration-color: var(--muted-foreground); }

/* Fina (signature, P-04): spark, thinking, citations, side panel */
.fina-spark { width: 16px; height: 16px; color: var(--primary); flex-shrink: 0; }
.cite { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; margin: 0 2px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--background); font-family: var(--font-sans); font-size: 12px; font-weight: 500; color: var(--muted-foreground); cursor: pointer; vertical-align: 1px; }
.cite:hover { border-color: var(--border-brand); color: var(--primary); }
.cite svg.lucide { width: 12px; height: 12px; }
.thinking { display: flex; align-items: center; gap: 8px; color: var(--muted-foreground); }
.thinking .fina-spark { animation: fina-pulse 1.2s var(--ease-move) infinite; }
@keyframes fina-pulse { 50% { opacity: .35; transform: scale(.85); } }
.steps { list-style: none; padding: 0; margin: 8px 0 0; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--muted-foreground); }
.steps li.done { color: var(--foreground); }
.steps li.done svg { color: var(--success); }
.panel { border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--background); }
.panel-head { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.panel-body { flex: 1; overflow: auto; padding: 16px; }
.panel-foot { padding: 12px 16px; border-top: 1px solid var(--border); }
.wash { background: var(--background-brand); border-radius: var(--radius-lg); padding: 12px 16px; }

/* Callouts: proactive signal (P-05) */
.signal { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.signal .ic { margin-top: 2px; }
.signal.warning .ic { color: var(--warning); }
.signal.destructive .ic { color: var(--destructive); }
.signal.info .ic { color: var(--information); }
.signal.success .ic { color: var(--success); }

/* Redline for narrative edits */
ins.add { background: var(--success-foreground); color: #15803d; text-decoration: none; border-bottom: 1px solid var(--success); }
del.rem { color: var(--destructive); text-decoration: line-through; }

/* Progress */
.bar { height: 6px; border-radius: var(--radius-full); background: var(--muted); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* Empty, skeleton, toast */
.empty { text-align: center; padding: 48px 16px; color: var(--muted-foreground); }
.skeleton { background: var(--muted); border-radius: var(--radius-md); height: 16px; }
@media (prefers-reduced-motion: no-preference) { .skeleton { animation: shimmer 1.4s ease-in-out infinite; } }
@keyframes shimmer { 50% { opacity: .5; } }
.toast { position: fixed; right: 24px; bottom: 24px; padding: 12px 16px; border-radius: var(--radius-lg); background: var(--foreground); color: var(--background); box-shadow: var(--shadow-md); z-index: 50; }

/* Dialog (O-01..O-03) */
.scrim { position: fixed; inset: 0; background: rgb(10 41 32 / .32); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dialog { width: min(560px, 100%); max-height: 85vh; overflow: auto; background: var(--popover); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 24px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* Marks a prototype so it is never mistaken for the product */
.proto-tag { position: fixed; left: 12px; bottom: 12px; z-index: 60; font-size: 12px; font-weight: 500; padding: 4px 8px; border-radius: var(--radius-full); background: var(--warning-foreground); color: #b45309; border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
