:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f5f8;
  --paper: #fff;
  --ink: #222437;
  --muted: #62677a;
  --line: #e5e5ed;
  --accent: #6040ab;
  --accent-dark: #4c308d;
  --accent-soft: #ede8fa;
  --sidebar: #221b35;
  --sidebar-muted: #c9bfd8;
  --green: #166947;
  --green-soft: #e8f5ed;
  --amber: #875411;
  --amber-soft: #fff2de;
  --red: #ab354a;
  --red-soft: #fcecf0;
  --blue: #3258a0;
  --blue-soft: #eaf0fe;
  --radius: 13px;
  --shadow: 0 2px 4px #26203a08;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, textarea, select { font: inherit; }
button, select, summary { cursor: pointer; }
button, a, input, select, textarea, summary { outline-offset: 4px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); }
a { color: var(--accent-dark); }
button { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 4vw, 2.15rem); letter-spacing: -.05em; line-height: 1.12; }
h2 { font-size: 1rem; letter-spacing: -.018em; }
h3 { font-size: .95rem; }
p { line-height: 1.55; }
svg { width: 19px; height: 19px; flex: none; vertical-align: middle; }

.skip-link { position: fixed; z-index: 8; top: .5rem; left: .5rem; transform: translateY(-160%); background: #fff; padding: .65rem 1rem; border-radius: 5px; }
.skip-link:focus { transform: none; }
.initial-view { width: min(450px, 90vw); margin: 30vh auto 0; text-align: center; }
.app-shell:has(.sidebar) { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #fff; display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 0; height: 100vh; overflow: auto; padding: 1.25rem .95rem .8rem; }
.brand { display: flex; align-items: center; gap: .75rem; padding: .15rem .48rem; width: fit-content; }
.brand-symbol { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 10px; color: #fff; background: #7251bf; }
.brand-symbol svg { width: 22px; height: 22px; }
.brand-name { font-size: 1rem; font-weight: 700; letter-spacing: -.025em; }
.brand-sub { color: var(--sidebar-muted); font-size: .77rem; margin-top: .13rem; }
.nav-group + .nav-group { margin-top: 1.16rem; }
.nav-heading { padding: 0 .65rem; margin: 0 0 .35rem; color: var(--sidebar-muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
.nav-link { display: flex; align-items: center; gap: .66rem; color: #eee8f7; width: 100%; border: 0; padding: .47rem .66rem; border-radius: 8px; text-decoration: none; line-height: 1.2; min-height: 35px; }
.nav-link svg { width: 17px; height: 17px; color: var(--sidebar-muted); }
.nav-link:hover { background: #3b304e; }
.nav-link[aria-current="page"] { background: #4a356e; color: #fff; font-weight: 650; }
.nav-link[aria-current="page"] svg { color: #e0cef8; }
.sidebar-bottom { margin-top: auto; padding: .7rem .4rem 0; border-top: 1px solid #ffffff23; color: var(--sidebar-muted); font-size: .77rem; }
.sidebar-bottom svg { width: 15px; height: 15px; margin-right: .23rem; }

.workspace { min-width: 0; }
.topbar { min-height: 61px; display: flex; align-items: center; justify-content: space-between; gap: .8rem; background: #fff; border-bottom: 1px solid var(--line); padding: .65rem clamp(1rem, 3vw, 2.25rem); }
.topbar-left, .topbar-right, .profile, .actions, .field-row, .icon-title { display: flex; align-items: center; gap: .65rem; }
.topbar-left { min-width: 0; }
.organisation { font-size: .84rem; color: #4d5063; font-weight: 600; }
.topbar-right { flex: none; }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; font-size: .72rem; }
.profile-name { font-weight: 650; font-size: .78rem; }
.profile-role { margin-top: .12rem; color: var(--muted); font-size: .72rem; }
.small-button { width: 35px; height: 35px; display: grid; place-items: center; border: 1px solid var(--line); background: white; border-radius: 8px; }
.small-button:hover { background: var(--bg); }
.menu-button { display: none; }
.workspace > main { width: min(100%, 1510px); margin-inline: auto; padding: clamp(1rem, 3vw, 2.25rem); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: .9rem; margin: .3rem 0 1.5rem; }
.page-heading p { color: var(--muted); margin-top: .35rem; }
.actions { flex-wrap: wrap; }
.button { border: 1px solid var(--line); text-decoration: none; background: #fff; color: var(--ink); padding: .57rem .8rem; min-height: 37px; display: inline-flex; align-items: center; justify-content: center; gap: .42rem; font-size: .82rem; font-weight: 650; border-radius: 8px; white-space: nowrap; }
.button svg { width: 16px; height: 16px; }
.button:hover { background: #f7f6fb; border-color: #dad3e8; }
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.danger { background: var(--red-soft); color: var(--red); border-color: #f2ced6; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.panel { background: var(--paper); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); min-width: 0; }
.panel + .panel { margin-top: 1rem; }
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .65rem; padding: 1.05rem 1.15rem; }
.panel-header p, .section-note { font-size: .8rem; color: var(--muted); margin-top: .27rem; }
.panel-body { padding: .1rem 1.15rem 1.15rem; }
.grid { display: grid; gap: 1rem; }
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1rem; }
.metric { padding: .95rem 1.05rem; min-width: 0; }
.metric .icon-title { color: var(--muted); font-size: .78rem; gap: .5rem; font-weight: 600; }
.metric .tile-icon { background: var(--accent-soft); color: var(--accent-dark); }
.tile-icon { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 7px; flex: none; }
.tile-icon svg { width: 16px; height: 16px; }
.tile-icon.green { background: var(--green-soft); color: var(--green); }
.tile-icon.blue { background: var(--blue-soft); color: var(--blue); }
.tile-icon.amber { background: var(--amber-soft); color: var(--amber); }
.metric-value { display: block; margin-top: .68rem; font-size: clamp(1.07rem, 2.4vw, 1.57rem); font-weight: 730; letter-spacing: -.055em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-note { color: var(--muted); font-size: .75rem; margin-top: .24rem; }
.dashboard-grid { grid-template-columns: minmax(0, 1.75fr) minmax(255px, 1fr); margin-bottom: 1rem; align-items: stretch; }
.grid > .panel { margin-top: 0; }
.full-width { grid-column: 1 / -1; }
.calendar { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.calendar svg { width: 16px; height: 16px; }
.badge { min-height: 23px; padding: .19rem .52rem; border-radius: 99px; display: inline-flex; align-items: center; width: fit-content; gap: .27rem; background: #eeedf2; color: #5f5b6d; font-weight: 650; font-size: .72rem; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.purple { background: var(--accent-soft); color: var(--accent-dark); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.dot::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.text-link { background: none; border: 0; padding: 0; font-weight: 650; color: var(--accent-dark); text-align: left; text-decoration: none; cursor: pointer; }
.text-link:hover { text-decoration: underline; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; text-align: left; font-size: .82rem; }
thead { background: #f8f7fb; color: #55566a; }
th, td { border-bottom: 1px solid var(--line); padding: .73rem 1rem; vertical-align: middle; }
th { font-weight: 650; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfaff; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 1.3rem 1.15rem; }
.stack { display: grid; gap: .2rem; }
.status-list { display: grid; margin: 0; padding: 0; }
.status-list > div { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .67rem 0; border-top: 1px solid var(--line); }
.status-list .icon-title { color: #4d4c62; }
.status-list dd { margin: 0; }

.cash-chart { width: 100%; height: auto; min-height: 126px; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .85rem; font-size: .72rem; color: var(--muted); margin-top: .8rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.swatch { width: 9px; height: 9px; background: #7654c5; border-radius: 2px; }
.swatch.risk { background: #e3b779; }
.swatch.litigation { background: #c76073; }

.control-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.field { display: grid; gap: .34rem; min-width: 0; }
.field label, .field-label { font-size: .8rem; font-weight: 650; }
.field input:not([type="checkbox"]), .field select, .field textarea { width: 100%; margin: 0; border: 1px solid #dcdce7; border-radius: 7px; background: #fff; color: var(--ink); padding: .55rem .62rem; min-height: 38px; }
.field textarea { min-height: 6.4rem; resize: vertical; }
.field input[type="checkbox"] { accent-color: var(--accent); }
.fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.wide { grid-column: 1 / -1; }
.form-actions { margin-top: .92rem; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: .7rem; }
.toolbar input, .toolbar select { border: 1px solid var(--line); border-radius: 7px; padding: .48rem .68rem; background: white; max-width: 100%; }
.installment-settings { padding: .75rem; background: #f8f7fb; border-radius: 9px; border: 1px solid var(--line); }
.installment-settings h3 { margin-bottom: .6rem; }
.installment-top, .installment-row { margin: .75rem 0; }
.installment-row { align-items: end; padding: .75rem 0; border-top: 1px solid var(--line); }
.installment-row .field-row { align-self: center; }
.simulation-subtotal { padding: 0 1.15rem .9rem; font-size: .82rem; font-weight: 650; color: var(--accent-dark); }
.notice { padding: .63rem .82rem; margin-bottom: .9rem; background: var(--blue-soft); color: var(--blue); border: 1px solid #d6e1fa; border-radius: 8px; }
.notice.success { background: var(--green-soft); color: var(--green); border-color: #cee9d9; }
.notice.error { background: var(--red-soft); color: var(--red); border-color: #f3ccd5; }
.search-field { display: flex; align-items: center; gap: .35rem; }
.search-field svg { width: 15px; height: 15px; color: var(--muted); }
.details-cell { max-width: 425px; overflow-wrap: anywhere; }
.details-cell summary { color: var(--accent-dark); }
.details-cell pre { white-space: pre-wrap; margin: .4rem 0 0; }
.import-columns { margin-top: .8rem; color: var(--muted); }
.import-columns p { margin-top: .35rem; overflow-wrap: anywhere; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(ellipse at top left, #eae3f7, var(--bg) 65%); }
.login-card { width: min(100%, 408px); padding: 1.65rem; display: grid; gap: 1.15rem; }
.login-card .brand { padding: 0; }
.login-card .brand-sub { color: var(--muted); }
.login-card .notice { margin: 0; }
.login-form { display: grid; gap: .85rem; }
.login-form .button { margin-top: .2rem; }

@media (max-width: 1050px) {
  .app-shell:has(.sidebar) { grid-template-columns: 212px minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 740px) {
  .app-shell:has(.sidebar) { display: block; }
  .sidebar { position: fixed; z-index: 5; top: 0; left: 0; width: min(280px, 90vw); height: 100dvh; box-shadow: 0 0 0 100vmax #21192e80; }
  .sidebar:not(.open) { display: none; }
  .sidebar .menu-button { display: grid; border-color: #ffffff38; background: transparent; color: white; margin-left: auto; }
  .sidebar > .topbar-left { justify-content: space-between; }
  .menu-button { display: grid; }
  .topbar { padding: .5rem .75rem; }
  .topbar .profile > div:last-child { display: none; }
  .topbar .badge { display: none; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 1.1rem; }
  .control-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
  .control-grid { grid-template-columns: minmax(0, 1fr); }
  .metrics { gap: .55rem; }
  .metric { padding: .64rem; }
  .tile-icon { width: 25px; height: 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

.login-heading { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.global-help { flex: none; }
.help-dialog {
  width: min(36rem, calc(100% - 1.5rem)); max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - 1.5rem); border: 1px solid var(--line); border-radius: 13px;
  color: var(--ink); background: white; padding: 0; overflow: auto;
}
.help-dialog::backdrop { background: rgba(25, 20, 44, .55); }
.help-dialog-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--line); }
.help-dialog-header h2 { margin: 0; font-size: 1.18rem; }
.help-dialog-body { display: grid; gap: .85rem; padding: 1.1rem 1.2rem; line-height: 1.55; }
.help-dialog-body p, .help-floating p { margin: 0; }
.help-lead { font-weight: 650; }
.help-meta { color: var(--muted); font-size: .82rem; }
.help-actions, .help-tours { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.help-facts { display: grid; margin: 0; }
.help-facts div { display: grid; grid-template-columns: minmax(6rem, 30%) 1fr; gap: .55rem; border-top: 1px solid var(--line); padding: .5rem 0; overflow-wrap: anywhere; }
.help-facts dt { font-weight: 620; }
.help-facts dd { margin: 0; }
.help-reason, .batch-warnings { color: #744116; background: #fff7e8; border: 1px solid #ead5b5; border-radius: 8px; padding: .52rem .7rem; }
.batch-warnings { margin: .6rem 1.15rem; padding-left: 1.9rem; }
.help-dialog textarea { min-height: 4.25rem; }
.help-action-group { display: inline-flex; position: relative; align-items: center; gap: .3rem; max-width: 100%; }
.help-trigger {
  display: inline-grid; place-items: center; flex: 0 0 auto; min-width: 26px; min-height: 26px;
  border: 1px solid #ccc2e5; border-radius: 50%; background: #f7f4fc; color: #503286;
  font: inherit; font-size: .8rem; font-weight: 750; line-height: 1;
}
.help-trigger:hover { border-color: #684ca9; background: #eee8fa; }
.help-tooltip {
  display: none; position: absolute; inset-inline-end: 0; bottom: 100%; z-index: 16;
  width: max-content; max-width: min(17.5rem, calc(100vw - 2rem)); border: 1px solid #5a417e;
  border-radius: 7px; padding: .45rem .5rem; background: #332449; color: white;
  font-size: .77rem; font-weight: 500; text-align: left; white-space: normal;
}
.help-tooltip:not([hidden]):hover, .help-trigger:hover + .help-tooltip:not([hidden]), .help-trigger:focus + .help-tooltip:not([hidden]) { display: block; }
.help-floating {
  position: fixed; inset-inline-end: max(.8rem, env(safe-area-inset-right)); bottom: max(.8rem, env(safe-area-inset-bottom));
  width: min(26rem, calc(100% - 1.6rem)); max-height: 43dvh; overflow: auto; z-index: 25;
  display: grid; gap: .6rem; padding: .85rem; box-shadow: 0 10px 30px rgba(30, 19, 57, .23);
}
.help-floating h2 { margin: 0; font-size: 1.05rem; }
.help-inspecting #app :is(button, a, input, select, textarea, summary, [data-help-id]):not([data-help-exempt]) { cursor: help; }
[data-tour-target] { outline: 3px solid #6746aa; outline-offset: 4px; scroll-margin: .8rem; }
.help-search { max-width: 32rem; }
.help-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr)); gap: .55rem; }
.help-result { border: 1px solid var(--line); border-radius: 9px; padding: .65rem .75rem; }
.help-result h3 { font-size: .93rem; margin: 0 0 .33rem; }
.help-result p { color: var(--muted); font-size: .85rem; line-height: 1.5; margin: 0; }
.help-result .text-link { text-align: left; }
.help-dialog :focus-visible, .help-trigger:focus-visible, .help-floating :focus-visible {
  outline: 2px solid #6944b1; outline-offset: 3px;
}
@media (max-width: 740px) {
  .help-trigger { min-width: 32px; min-height: 32px; }
  .help-dialog-body, .help-dialog-header { padding-inline: .8rem; }
  .help-tooltip { inset-inline-start: auto; }
  .help-floating { max-height: 46dvh; }
}

.hide-inline-help .help-trigger, .hide-inline-help .help-tooltip { display: none; }
.help-preference { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; }
