/* Anything Invoicing — design system */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/InterVariable-ui.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { letter-spacing: -0.02em; font-weight: 600; }
::selection { background: var(--accent-soft); }

:root {
  --radius: 6px;
  --radius-lg: 10px;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sidebar: 232px;
  --header: 64px;
  --topbar: var(--header);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .18);
  --shadow: 0 8px 24px rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .12);
  --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 38%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 13%, transparent);
  --success-soft: color-mix(in srgb, var(--success) 13%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 14%, transparent);
  --info-soft: color-mix(in srgb, var(--info, #5f8fe8) 13%, transparent);
}

:root, :root[data-theme="dark"] {
  --bg: #0d0f14;
  --surface: #13161d;
  --surface-2: #191d26;
  --surface-3: #1f2430;
  --border: #232734;
  --border-strong: #303545;
  --text: #d7dae2;
  --text-dim: #8a92a6;
  --text-faint: #838b9e;
  --danger: #ff5c72;
  --danger-contrast: #0d0f14;
  --success: #66d38a;
  --warn: #f0b35a;
  --info: #6f9bf0;
  --focus: color-mix(in srgb, var(--accent) 70%, white 30%);
  --paper: #ffffff;
  --paper-text: #1b1e27;
  --paper-muted: #6b7280;
  --paper-border: #e4e7ec;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e8ebf0;
  --border: #e0e3e9;
  --border-strong: #cfd4dd;
  --text: #1b1e27;
  --text-dim: #565c6d;
  --text-faint: #626878;
  --danger: #c8283f;
  --danger-contrast: #ffffff;
  --success: #16794a;
  --warn: #9a5c00;
  --info: #2f6fd0;
  --focus: var(--accent);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 10px 28px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  --paper: #ffffff;
  --paper-text: #1b1e27;
  --paper-muted: #6b7280;
  --paper-border: #e4e7ec;
  color-scheme: light;
}

:root, :root[data-accent="red"] { --accent: #d95252; --accent-strong: #e56a6a; --accent-contrast: #0d0f14; }
:root[data-accent="purple"] { --accent: #9469db; --accent-strong: #a37ce2; --accent-contrast: #0d0f14; }
:root[data-accent="green"] { --accent: #3fae6a; --accent-strong: #4fc47c; --accent-contrast: #0d0f14; }
:root[data-accent="blue"] { --accent: #4a86e8; --accent-strong: #5f97f2; --accent-contrast: #0d0f14; }
:root[data-accent="orange"] { --accent: #e0823c; --accent-strong: #ec9550; --accent-contrast: #0d0f14; }
:root[data-accent="teal"] { --accent: #2ba7a0; --accent-strong: #35bdb5; --accent-contrast: #0d0f14; }
:root[data-accent="pink"] { --accent: #d65a8e; --accent-strong: #e66fa0; --accent-contrast: #0d0f14; }
:root[data-accent="amber"] { --accent: #d4a02f; --accent-strong: #e2b243; --accent-contrast: #0d0f14; }
:root[data-accent="indigo"] { --accent: #5b5bd6; --accent-strong: #6e6ee6; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="red"] { --accent: #b7342f; --accent-strong: #a02a26; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="purple"] { --accent: #6b3fb0; --accent-strong: #5a3299; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="green"] { --accent: #2f8a53; --accent-strong: #267446; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="blue"] { --accent: #2f6fd0; --accent-strong: #285fb2; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="orange"] { --accent: #b5641f; --accent-strong: #9c5418; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="teal"] { --accent: #1f7f7a; --accent-strong: #196b67; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="pink"] { --accent: #b03d6f; --accent-strong: #98335f; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="amber"] { --accent: #9a7418; --accent-strong: #856312; --accent-contrast: #ffffff; }
:root[data-theme="light"][data-accent="indigo"] { --accent: #4a4ac4; --accent-strong: #3f3fae; --accent-contrast: #ffffff; }

.skip-link {
  position: fixed; top: -100px; left: 16px; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: 8px 14px; border-radius: var(--radius);
}
.skip-link:focus { top: 12px; }
.icon { flex: none; }

/* Sidebar */
.sidebar {
  position: fixed; inset: var(--header) auto 0 0; width: var(--sidebar);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px; z-index: 45;
}
.sidebar-org { display: none; }
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 2px 8px 20px; font-weight: 600; letter-spacing: -0.02em;
}
.brand-mark {
  width: var(--mark-size, 24px); height: var(--mark-size, 24px); border-radius: 7px;
  display: grid; place-items: center; flex: none;
  background: transparent; color: var(--accent);
  font-size: 13px; font-weight: 700; letter-spacing: -0.04em;
  overflow: hidden;
}
.brand-word { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); }

.org-switch { position: relative; margin: 0 4px 14px; }
.org-switch > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 9px;
  padding: 8px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.org-switch > summary:hover { border-color: var(--border-strong); background: var(--surface-3); }
.org-switch > summary::-webkit-details-marker { display: none; }
.org-avatar {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.org-avatar.small { width: 22px; height: 22px; font-size: 11px; border-radius: 5px; }
img.org-avatar { object-fit: contain; background: var(--surface-2); }
.org-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.org-name { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-meta { font-size: 10.5px; color: var(--text-faint); }
.org-switch > summary .icon { color: var(--text-faint); }

.nav { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.nav > .nav-label:first-child { padding-top: 6px; }
.nav-label {
  font-size: 10px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint); padding: 16px 8px 6px;
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 33px 0 9px; border-radius: var(--radius);
  font-size: 13px; color: var(--text-dim); transition: background .12s, color .12s;
}
.nav-main { display: flex; align-items: center; gap: 9px; width: 100%; height: 100%; color: inherit; }
.nav-add {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 19px; height: 19px;
  border-radius: 5px; color: var(--text-faint); opacity: 0;
  transition: background .12s, color .12s, opacity .12s;
}
.nav-item:hover .nav-add,
.nav-item:focus-within .nav-add { opacity: 1; }
.nav-add:hover, .nav-add:focus-visible { background: var(--surface-3); color: var(--text); opacity: 1; }
.nav-item .nav-add .icon { color: currentColor; }
@media (hover: none) {
  .nav-add { opacity: .7; }
}
.nav-item .icon { color: var(--text-faint); transition: color .12s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:hover .icon { color: var(--text-dim); }
.nav-item.is-active { background: var(--accent-soft); color: var(--text); font-weight: 550; }
.nav-item.is-active .icon { color: var(--accent); }

.sidebar-foot { margin-top: auto; padding-top: 14px; }
.user-menu > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 9px;
  padding: 8px; border-radius: var(--radius); transition: background .12s;
}
.user-menu > summary:hover { background: var(--surface-2); }
.user-menu > summary::-webkit-details-marker { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar-fallback {
  display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); font-size: 11px; font-weight: 600;
}
.user-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.user-name { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta { font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Menus */
.menu {
  position: absolute; z-index: 60; min-width: 240px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 5px; margin-top: 4px;
}
.org-menu { width: 270px; max-width: calc(100vw - 24px); top: calc(100% + 6px); left: 0; }
.user-dropdown { width: calc(var(--sidebar) - 32px); bottom: calc(100% + 6px); top: auto; }
.menu form { margin: 0; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border: 0; border-radius: 6px; background: transparent;
  font-size: 12.5px; color: var(--text-dim); text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.is-active { color: var(--text); }
.menu-check { margin-left: auto; color: var(--accent); }
.menu-item-muted { color: var(--text-faint); }
.action-menu { position: relative; }
.action-menu > summary { list-style: none; cursor: pointer; }
.action-menu > summary::-webkit-details-marker { display: none; }
.action-menu[open] > summary { background: var(--surface-2); border-color: var(--border-strong); }
.action-menu .menu { right: 0; left: auto; top: calc(100% + 6px); min-width: 190px; }
.menu-item .theme-icon-light { display: none; }
:root[data-theme="light"] .menu-item .theme-icon-light { display: block; }
:root[data-theme="light"] .menu-item .theme-icon-dark { display: none; }

/* App shell */
.shell { margin-left: var(--sidebar); min-height: calc(100vh - var(--header)); }

.app-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header); display: flex; align-items: center; gap: 16px;
  padding: 0 22px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.app-brand { display: flex; align-items: center; gap: 9px; flex: none; min-width: 0; }
.app-brand .brand-mark {
  width: var(--mark-size, 26px); height: var(--mark-size, 26px);
  background: transparent; color: var(--accent);
}
.app-brand-word { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.brand-accent { color: var(--accent); }
.header-org { flex: 0 1 auto; max-width: 260px; min-width: 0; margin: 0; }
.header-org > summary { height: 36px; padding: 5px 8px; gap: 8px; margin: 0; }
.header-org .org-copy { justify-content: center; max-width: 200px; }
.header-org .org-name { font-size: 13px; }
.header-org .org-meta { display: none; }
.header-org .org-menu { top: calc(100% + 16px); }

.header-user { position: relative; flex: none; }
.header-user > summary { padding: 4px; gap: 7px; }
.header-user .avatar { width: 30px; height: 30px; }
.header-user .user-copy { flex: 0 1 auto; min-width: 0; }
.header-user .user-name { max-width: 150px; }
.header-user .user-dropdown {
  top: calc(100% + 16px); right: 0; left: auto; bottom: auto; width: 210px;
}

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-heading { min-width: 0; flex: 1 1 auto; }
.page-heading h1 { font-size: 21px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-heading p { font-size: 12.5px; color: var(--text-faint); margin-top: 3px; }
.page-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  justify-content: flex-end; flex: 0 0 auto; min-width: 0;
}
.page-actions:empty { display: none; }
.assistant-model-form { margin: 0; }
.assistant-model-select {
  height: 32px; max-width: 220px; padding: 0 8px; font-size: 12px;
  color: var(--text-dim); border-radius: var(--radius);
}
.assistant-model-select:disabled { opacity: .6; cursor: not-allowed; }
.page-subtitle-inline { display: flex; align-items: center; gap: 8px; }
.assistant-subtitle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 3px; }
.assistant-subtitle p { margin: 0; }
.auto-rule-manage {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 10.5px; font-weight: 550;
  line-height: 1; cursor: pointer; white-space: nowrap;
}
.auto-rule-manage:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--text); }
.auto-rule-manage .icon { color: var(--success); }
.auto-rule-manage-label { color: var(--text-dim); }
.auto-rule-manage-mobile { display: none; color: var(--text-dim); }
.auto-rule-count {
  display: inline-grid; place-items: center; min-width: 15px; height: 15px;
  padding: 0 4px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 9.5px; font-weight: 650;
}
.auto-rule-manage-action { color: var(--text); font-weight: 600; }
.theme-button { margin-left: 0; }

.search {
  display: flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 9px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-faint);
}
.search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input[type="search"] {
  border: 0; background: transparent; outline: 0; width: 100%; height: auto;
  min-width: 0; padding: 0; box-shadow: none; color: var(--text);
}
.search input[type="search"]:focus { border: 0; box-shadow: none; }
.search input::placeholder { color: var(--text-faint); }
.search kbd {
  font: 10px var(--mono); color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; background: var(--surface-2);
}
.header-search { width: clamp(190px, 24vw, 300px); min-width: 0; }
.header-search .search-submit {
  display: grid; place-items: center; flex: none;
  padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer;
}
.header-search .search-submit:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-light { display: block; }
:root[data-theme="light"] .theme-icon-dark { display: none; }

.content { padding: 24px 28px 56px; max-width: 1380px; }
.mobile-menu { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 12.5px; font-weight: 550; cursor: pointer;
  white-space: nowrap; transition: background .13s, border-color .13s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-button:focus-visible, .nav-item:focus-visible, summary:focus-visible,
a:focus-visible, .tab:focus-visible, .menu-item:focus-visible, .flash-close:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 9px; font-size: 12px; }
.draft-clear { margin-top: 2px; color: var(--text-faint); }
.draft-clear:hover { color: var(--danger); background: var(--danger-soft); }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-button {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--text-dim); cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.icon-button.is-danger { color: var(--danger); }
.icon-button.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.subtle { color: var(--text-dim); }
.muted { color: var(--text-faint); }
.num { font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

/* Flash */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--text-faint);
}
.flash-success { border-left-color: var(--success); background: var(--success-soft); }
.flash-error { border-left-color: var(--danger); background: var(--danger-soft); }
.flash-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.flash-info { border-left-color: var(--info); background: var(--info-soft); }
.flash-close {
  margin-left: auto; flex: none; display: grid; place-items: center;
  width: 26px; height: 26px; border: 0; border-radius: 4px;
  background: transparent; color: var(--text-faint); cursor: pointer;
}
.flash-close:hover { background: var(--surface-2); color: var(--text); }

/* Page sections */
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 14px; }
.section-head .btn { margin-left: auto; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 13px; font-weight: 600; }
.panel-head .btn { margin-left: auto; }
.panel-body { padding: 16px; }
.panel-empty { padding: 34px 20px; text-align: center; color: var(--text-faint); font-size: 12.5px; }

/* Stats */
.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden; margin-bottom: 18px;
}
.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { padding: 15px 17px; border-right: 1px solid var(--border); }
.stat:last-child { border-right: 0; }
.stat-label { font-size: 11px; color: var(--text-faint); font-weight: 550; letter-spacing: .02em; }
.stat-value { font-size: 23px; font-weight: 600; letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-meta { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.stat-delta { display: flex; align-items: baseline; gap: 5px; margin-top: 7px; font-size: 11.5px; font-weight: 550; font-variant-numeric: tabular-nums; }
.stat-delta span { font-size: 10.5px; font-weight: 400; color: var(--text-faint); }
.stat-delta.is-good { color: var(--success); }
.stat-delta.is-bad { color: var(--danger); }
.stat-delta.is-flat { color: var(--text-faint); }
.stat-meta strong { color: var(--text-dim); font-weight: 550; }
.stat-danger .stat-value { color: var(--danger); }
.stat-success .stat-value { color: var(--success); }

/* Workspace switch skeleton */
.skeleton {
  display: block; position: relative; overflow: hidden;
  border-radius: 4px; background: var(--surface-2);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 18%, color-mix(in srgb, var(--text) 8%, transparent) 50%, transparent 82%);
  transform: translateX(-100%);
  animation: skeleton-sweep 1.25s ease-in-out infinite;
}
@keyframes skeleton-sweep { to { transform: translateX(100%); } }
.sk-subtitle { margin-top: 7px; width: 132px; height: 10px; }
.sk-line { height: 9px; }
.sk-label { width: 66px; }
.sk-value { width: 112px; max-width: 72%; height: 23px; margin-top: 10px; border-radius: 6px; }
.sk-meta { width: 96px; max-width: 62%; margin-top: 9px; }
.sk-button { width: 108px; height: 32px; border-radius: var(--radius); }
.sk-button-primary { width: 126px; }
.sk-title { width: 112px; height: 11px; }
.sk-toolbar { width: 58px; height: 21px; margin-left: auto; border-radius: 999px; }

.sk-table { padding: 5px 0; }
.sk-row {
  display: flex; align-items: center; gap: 20px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.sk-row:last-child { border-bottom: 0; }
.sk-cell { flex: 1 1 auto; height: 10px; }
.sk-cell-sm { flex: 0 0 68px; }
.sk-cell-xs { flex: 0 0 54px; }
.sk-cell-money { flex: 0 0 66px; margin-left: auto; }

.sk-chart { display: flex; align-items: flex-end; gap: 12px; height: 138px; padding-top: 8px; }
.sk-bar { flex: 1; height: 40%; border-radius: 4px 4px 2px 2px; }
.sk-bar:nth-child(2) { height: 64%; }
.sk-bar:nth-child(3) { height: 47%; }
.sk-bar:nth-child(4) { height: 78%; }
.sk-bar:nth-child(5) { height: 36%; }
.sk-bar:nth-child(6) { height: 58%; }

.sk-feed { display: flex; flex-direction: column; gap: 16px; }
.sk-feed-item { display: flex; align-items: flex-start; gap: 10px; }
.sk-dot { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.sk-feed-copy { flex: 1; display: flex; flex-direction: column; gap: 7px; padding-top: 4px; }
.sk-feed-line { width: 78%; height: 9px; }
.sk-feed-line.is-short { width: 44%; height: 8px; }

body.is-switching-org .org-switch form,
body.is-switching-org .org-switch a { pointer-events: none; }

/* Rolling digits */
.roll-digit { display: inline-block; height: 1em; overflow: hidden; vertical-align: -.08em; }
.roll-strip { display: flex; flex-direction: column; }
.roll-digit-value { display: flex; align-items: center; justify-content: center; height: 1em; line-height: 1; }
.roll-symbol { display: inline-block; }

/* Grid */
.grid { display: grid; gap: 18px; }
.grid-main { grid-template-columns: minmax(0, 1.7fr) minmax(280px, .95fr); align-items: start; }
.reports-secondary { margin-top: 18px; }
.invoice-form-layout { display: flex; flex-wrap: wrap; }
.invoice-form-summary { order: 2; flex: 0 0 260px; position: sticky; top: calc(var(--topbar) + 18px); }
.invoice-form-main { order: 1; flex: 1 1 680px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* Tables */
.table-wrap, .lines-wrap {
  overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.table-wrap::-webkit-scrollbar, .lines-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb, .lines-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 999px;
}
.table-wrap::-webkit-scrollbar-track, .lines-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap, .lines-wrap {
  background:
    linear-gradient(to right, var(--surface) 40%, transparent) left center / 24px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 40%, transparent) right center / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0% 50%, rgba(0, 0, 0, .16), transparent) left center / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .16), transparent) right center / 10px 100% no-repeat scroll;
}
/* Keep the scroll surface inside the panel's rounded border. */
.panel > .table-wrap:first-child {
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}
.panel > .table-wrap:last-child {
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl thead th {
  text-align: left; font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint); padding: 9px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; background: var(--surface);
}
.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr[data-row-href] { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .right { text-align: right; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .primary { font-weight: 550; color: var(--text); }
.tbl .secondary { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
.tbl .recurring-mark {
  display: inline-flex; align-items: center;
  margin-left: 5px; vertical-align: -1px;
  color: var(--text-faint);
}
.tbl .recurring-mark:hover { color: var(--accent); }
.tbl .nowrap { white-space: nowrap; }
.row-link { position: relative; }
.row-link a.stretch { position: absolute; inset: 0; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11px; font-weight: 550; white-space: nowrap;
  background: var(--surface-2); color: var(--text-dim);
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { color: var(--text-faint); }
.badge-plain::before { display: none; }

/* Filters */
.filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px;
}
.filters .field { margin: 0; }
.filters input, .filters select { height: 32px; font-size: 12.5px; }
.filters select { width: auto; min-width: 0; max-width: 100%; flex: 0 1 auto; }
.filters input[type="date"] { width: auto; min-width: 0; max-width: 100%; flex: 0 1 auto; }
.filters .search { height: 32px; flex: 0 1 auto; }
.filters .search-input { min-width: 220px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.tab {
  padding: 8px 11px; font-size: 12.5px; color: var(--text-faint);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-size: 11.5px; font-weight: 550; color: var(--text-dim); }
.field .hint, .settings-shell .hint { font-size: 11px; color: var(--text-faint); }
.settings-shell .hint.text-warn { color: var(--warn); }
.field .error { font-size: 11px; color: var(--danger); }
input[type="text"], input[type="email"], input[type="search"], input[type="number"],
input[type="date"], input[type="url"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; height: 36px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); outline: 0; font-size: 13px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 82px; padding: 9px 10px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly] { color: var(--text-dim); background: var(--surface-2); }
input[type="file"] {
  width: 100%; padding: 9px 10px; border: 1px dashed var(--border-strong);
  border-radius: var(--radius); background: var(--surface-2); color: var(--text-dim); font-size: 12px;
}
input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 5px 10px; border: 1px solid var(--border);
  border-radius: 5px; background: var(--surface); color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--surface-3); }

.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.field-label-row label { margin: 0; }
.money-input {
  display: flex; align-items: center; height: 36px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.money-input span { padding-left: 10px; color: var(--text-dim); font-size: 13px; }
.money-input input {
  border: 0; height: 100%; padding-left: 6px; box-shadow: none; background: transparent;
}
.money-input input:focus { border: 0; box-shadow: none; }
.money-input:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }

.color-control {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface);
}
.color-input {
  width: 40px; height: 40px; padding: 0; flex: none; overflow: hidden;
  border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 7px; }
.color-input::-moz-color-swatch { border: 0; border-radius: 7px; }
.color-value { font: 12px/1 var(--mono); color: var(--text); letter-spacing: .02em; }
.color-control .hint { flex-basis: 100%; margin-top: 0; }
.color-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.color-preset {
  width: 24px; height: 24px; padding: 0; border: 1px solid var(--border-strong);
  border-radius: 50%; background: var(--swatch); cursor: pointer;
}
.color-preset:hover { transform: translateY(-1px); }
.color-preset.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--accent); border-color: transparent; }
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  font-family: inherit; font-size: 13px; font-weight: 400; line-height: normal;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%238a92a6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
  transition: border-color .12s, background-color .12s, box-shadow .12s;
}
select:hover { border-color: var(--border-strong); background-color: var(--surface-2); }
select:disabled { opacity: .55; cursor: not-allowed; background-color: var(--surface-2); }
select option { background: var(--surface); color: var(--text); }
.filters select { background-position: right 9px center; padding-right: 29px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.invoice-details-grid { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.invoice-details-grid .field { margin-bottom: 0; }
.notes-terms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }.notes-term { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.notes-term label { font-size: 11.5px; font-weight: 550; color: var(--text-dim); }
.notes-term textarea { min-height: 118px; background: var(--surface-2); }
.notes-term textarea:focus { background: var(--surface); }
.surcharge-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.surcharge-option { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.surcharge-option:hover { border-color: var(--border-strong); }
.surcharge-option .surcharge-name { color: var(--text); font-weight: 550; }
.surcharge-option .surcharge-amount { margin-left: auto; min-width: 62px; text-align: right; }
.surcharge-picker > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-dim); font-size: 12.5px;
  transition: border-color .12s, background-color .12s;
}
.surcharge-picker > summary::-webkit-details-marker { display: none; }
.surcharge-picker > summary:hover { border-color: var(--border-strong); background: var(--surface-2); }
.surcharge-picker[open] > summary { border-color: var(--border-strong); background: var(--surface-2); }
.surcharge-picker > summary .icon { margin-left: auto; color: var(--text-faint); transition: transform .15s ease; }
.surcharge-picker[open] > summary .icon { transform: rotate(180deg); }
.surcharge-picker { position: relative; }
.surcharge-menu {
  top: calc(100% + 6px); left: 0; right: 0; min-width: 0; width: 100%;
  max-height: 320px; overflow-y: auto; overscroll-behavior: contain;
}
.surcharge-menu .surcharge-options { grid-template-columns: minmax(0, 1fr); gap: 2px; }
.surcharge-menu .surcharge-option { padding: 7px 8px; border-color: transparent; background: transparent; }
.surcharge-menu .surcharge-option:hover { border-color: transparent; background: var(--surface-2); }
.notes-default { margin-left: auto; }
.form-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.form-section-head h2 { margin: 0; }
.form-section { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 4px; }
.form-section h2 { font-size: 13px; margin-bottom: 12px; }
.form-actions { display: flex; align-items: center; gap: 8px; padding-top: 18px; border-top: 1px solid var(--border); margin-top: 6px; }
.form-actions .spacer { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }
.inline-form { display: inline; }

/* Lines editor */
.lines { width: 100%; border-collapse: collapse; min-width: 700px; }
.lines input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.lines input[type="number"]::-webkit-outer-spin-button,
.lines input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.lines th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 600; padding: 0 8px 8px;
}
.lines td { padding: 4px 4px; vertical-align: top; }
.lines input, .lines select { height: 34px; font-size: 12.5px; }
.lines .line-desc { min-width: 220px; }
.lines .line-qty { width: 72px; text-align: right; }
.lines .line-price { width: 110px; text-align: right; }
.lines .line-discount { width: 76px; text-align: right; }
.lines .line-tax { width: 76px; text-align: right; }
.lines .line-total { width: 110px; text-align: right; font-variant-numeric: tabular-nums; padding-top: 11px; white-space: nowrap; }
.lines .remove-line { margin-top: 4px; }
.line-handle-col, .line-handle { width: 12px; padding-left: 0 !important; padding-right: 0 !important; }
.line-handle { vertical-align: middle !important; }
.line-drag {
  display: inline-grid; place-items: center;
  width: 12px; height: 28px; padding: 0;
  border: 0; border-radius: 4px; background: transparent;
  color: var(--text-faint); cursor: grab;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: color .12s ease, background .12s ease, opacity .12s ease;
}
.line-drag:hover { color: var(--text); background: var(--surface-2); }
.line-drag:active, .line-drag.is-dragging { cursor: grabbing; color: var(--accent); background: var(--surface-2); }
[data-sortable-rows] tbody tr:only-child .line-drag { visibility: hidden; pointer-events: none; }
@media (hover: hover) {
  .line-drag { opacity: .45; }
  tr:hover .line-drag, .line-drag:focus-visible, .line-drag.is-dragging { opacity: 1; }
}
tr.is-drag-origin > td { opacity: .22; }
tr.is-drag-origin > td.line-handle { opacity: 1; }
tr.is-line-dropped > td { animation: line-drop .55s ease; }
@keyframes line-drop {
  from { background: var(--accent-soft); }
  to { background: transparent; }
}
html.is-reordering-lines, html.is-reordering-lines * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }
.line-drag-ghost {
  position: fixed; z-index: 240; overflow: hidden;
  border-radius: 8px; background: var(--surface);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .28), 0 0 0 1px var(--border-strong);
  pointer-events: none; will-change: transform;
}
.line-drag-ghost table { background: var(--surface); }
.line-drag-ghost .line-handle { opacity: 1; }
.line-product { min-width: 150px; }
.add-line { margin-top: 6px; }
.totals { margin-left: auto; width: 290px; margin-top: 18px; }
.totals-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: 12.5px; color: var(--text-dim); }
.totals-row strong { color: var(--text); font-weight: 550; }
.totals-row.grand { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 10px; font-size: 15px; color: var(--text); }
.totals-row.grand strong { font-size: 18px; letter-spacing: -0.02em; }
.totals input { height: 30px; width: 110px; text-align: right; }

/* Activity feed */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: 0; }
.feed-icon {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--surface-2); color: var(--text-dim);
}
.feed-copy { min-width: 0; flex: 1; }
.feed-copy p { font-size: 12.5px; color: var(--text-dim); }
.feed-copy p strong { color: var(--text); font-weight: 550; }
.feed-time { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 6px 2px 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 7px; height: 100%; justify-content: flex-end; }
.chart-bars { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; }
.chart-bar {
  flex: 1; width: auto; border-radius: 3px 3px 0 0;
  background: color-mix(in srgb, var(--accent) 55%, var(--surface-2));
  transition: background .15s;
}
.chart-col:hover .chart-bar:not(.is-expense) { background: var(--accent); }
.chart-bar.is-expense { background: color-mix(in srgb, var(--warn) 55%, var(--surface-2)); }
.chart-col:hover .chart-bar.is-expense { background: var(--warn); }
.chart-bar.is-empty { background: var(--border); min-height: 2px; }
.chart-label { font-size: 10px; color: var(--text-faint); text-align: center; }
.chart-value { font-size: 10px; color: var(--text-faint); text-align: center; font-variant-numeric: tabular-nums; }
.chart-legend { margin-left: auto; display: flex; gap: 12px; font-size: 11px; color: var(--text-faint); }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend span::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }
.chart-legend span.is-expense::before { background: color-mix(in srgb, var(--warn) 65%, var(--surface-2)); }
.chart-legend span.is-net::before { width: 12px; height: 2px; border-radius: 999px; background: var(--text); }
.chart-toggle {
  position: relative; margin-left: auto; display: inline-flex; gap: 2px; padding: 2px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
}
.chart-toggle-thumb {
  position: absolute; top: 2px; left: 0; height: calc(100% - 4px); width: 0;
  border-radius: 999px; background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
  transition: transform .3s cubic-bezier(.22, .8, .3, 1), width .3s cubic-bezier(.22, .8, .3, 1);
}
.chart-toggle button {
  position: relative; z-index: 1;
  appearance: none; border: 0; background: transparent; color: var(--text-faint);
  font: inherit; font-size: 11px; font-weight: 550; line-height: 1;
  padding: 5px 9px; border-radius: 999px; cursor: pointer;
  transition: color .18s ease;
}
.chart-toggle button:hover { color: var(--text); }
.chart-toggle button.is-active { color: var(--text); }
.chart-toggle button:disabled { opacity: .45; cursor: not-allowed; }
.bar-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 5px 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.bar-row:last-child { border-bottom: 0; }
.bar-label { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 12.5px; }
.bar-label a { color: var(--text); font-weight: 550; }
.bar-label small { color: var(--text-faint); font-size: 10.5px; }
.bar-track { grid-column: 1 / -1; grid-row: 2; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: color-mix(in srgb, var(--accent) 65%, var(--surface-2)); }
.bar-fill.is-expense { background: color-mix(in srgb, var(--warn) 60%, var(--surface-2)); }
.bar-value { grid-column: 2; grid-row: 1; text-align: right; font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }

.donut-layout { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { position: relative; width: 168px; height: 168px; flex: none; }
.donut-svg { width: 100%; height: 100%; display: block; }
.donut-svg { transform-origin: 50% 50%; }
.donut-seg {
  transition: stroke-dasharray .55s cubic-bezier(.22, .8, .3, 1),
              stroke-dashoffset .55s cubic-bezier(.22, .8, .3, 1),
              opacity .12s ease;
  cursor: default;
}
.donut-seg:hover { opacity: .78; }
.donut-svg.is-switching { animation: donut-spin .62s cubic-bezier(.18, .82, .28, 1); }
@keyframes donut-spin {
  from { transform: rotate(-145deg); }
  to { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .chart-toggle-thumb, .donut-seg { transition: none; }
  .donut-svg.is-switching { animation: none; }
}
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; z-index: 1; pointer-events: none; transition: opacity .16s ease; }
.donut-center.is-switching span { opacity: .25; }
.donut-center strong { font-size: 24px; font-weight: 600; letter-spacing: -0.03em; }
[data-status-chart][data-status-view="amount"] .donut-center [data-status-value] { font-size: 14px; letter-spacing: -0.04em; line-height: 1.15; }
.donut-center span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); transition: opacity .16s ease; }
.donut-legend { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 8px; }
.legend-row {
  display: grid; grid-template-columns: 9px minmax(0, 1fr) auto auto;
  gap: 8px; align-items: center; font-size: 12px;
}
.legend-name { transition: opacity .16s ease, transform .16s ease; }
.donut-legend.is-switching .legend-name { opacity: .25; transform: translateX(-4px); }
.donut-legend.is-switching .legend-row:nth-child(2) .legend-name { transition-delay: .02s; }
.donut-legend.is-switching .legend-row:nth-child(3) .legend-name { transition-delay: .04s; }
.donut-legend.is-switching .legend-row:nth-child(4) .legend-name { transition-delay: .06s; }
.donut-legend.is-switching .legend-row:nth-child(5) .legend-name { transition-delay: .08s; }
.donut-legend.is-switching .legend-row:nth-child(6) .legend-name { transition-delay: .1s; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-name { color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { grid-column: 3; color: var(--text-faint); font-size: 11px; white-space: nowrap; }
.legend-value { grid-column: 4; color: var(--text); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.expense-map { position: relative; height: 220px; }
.expense-map.is-switching .expense-tile span { opacity: .25; transform: translateX(-4px); }
.expense-cell {
  position: absolute; padding: 3px;
  transition: left .55s cubic-bezier(.22,.8,.3,1), top .55s cubic-bezier(.22,.8,.3,1),
              width .55s cubic-bezier(.22,.8,.3,1), height .55s cubic-bezier(.22,.8,.3,1);
}
.expense-tile {
  width: 100%; height: 100%; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px; border-radius: 8px; color: #fff; background: var(--tile);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .28);
}
.expense-tile span, .expense-tile strong, .expense-tile small { display: none; }
.expense-tile span { font-size: 11px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .16s ease, transform .16s ease; }
.expense-tile strong { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-tile small { font-size: 10.5px; opacity: .8; white-space: nowrap; }
.expense-tile.is-full span, .expense-tile.is-full strong, .expense-tile.is-full small { display: block; }
.expense-tile.is-amount { align-items: center; justify-content: center; padding: 4px 3px; }
.expense-tile.is-amount strong { display: block; font-size: 10.5px; letter-spacing: 0; }
.expense-tile.is-blank { padding: 0; }

.stack-bar { display: flex; width: 100%; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin: 6px 0 14px; }
.stack-seg { height: 100%; min-width: 0; }
.stack-legend { display: flex; flex-direction: column; gap: 7px; }

.cash-chart { width: 100%; height: auto; display: block; overflow: visible; }
.cash-zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.cash-income { fill: color-mix(in srgb, var(--accent) 70%, var(--surface-2)); }
.cash-expense { fill: color-mix(in srgb, var(--warn) 66%, var(--surface-2)); }
.cash-net { fill: none; stroke: var(--text); stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; }
.cash-hover-line { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; pointer-events: none; }
.cash-hover-line.is-visible { opacity: 1; }
.chart-tip.cash-hover-tip { max-width: 260px; white-space: normal; line-height: 1.4; }
.cash-label { fill: var(--text-faint); font-size: 10px; text-anchor: middle; }
.rank {
  display: inline-grid; place-items: center; width: 18px; height: 18px;
  border-radius: 50%; background: var(--surface-2); color: var(--text-faint);
  font-size: 10px; font-variant-numeric: tabular-nums;
}

.chart-tip {
  position: fixed; z-index: 200; pointer-events: none;
  padding: 8px 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  font-size: 12px; white-space: nowrap; opacity: 0;
  transform: translate(-50%, -100%); transition: opacity .12s ease;
}
.chart-tip.is-visible { opacity: 1; }

.copy-value {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 0; border: 0; background: transparent; color: inherit; font: inherit;
  text-align: left; cursor: copy; border-radius: 4px;
}
.copy-value > span { min-width: 0; }
.copy-value .copy-icon { color: var(--text-faint); opacity: .65; flex: none; }
.copy-value:hover .copy-icon { color: var(--accent); opacity: 1; }
.copy-value .copy-check { display: none; color: var(--success); flex: none; }
.copy-value.is-copied .copy-icon { display: none; }
.copy-value.is-copied .copy-check { display: inline; }
.copy-value:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.copy-address { align-items: flex-start; }
.copy-address > span { line-height: 1.55; }

/* Empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 48px 24px; text-align: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  color: var(--text-faint);
}
.empty > .icon { color: var(--text-faint); }
.empty h2 { font-size: 14px; color: var(--text); }
.empty p { font-size: 12.5px; max-width: 380px; }
.empty .btn { margin-top: 4px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); }
.pagination .btn { height: 28px; }
.pagination-links { display: flex; gap: 6px; }

/* Infinite lists */
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); }
.list-footer .btn { height: 28px; }
.list-actions { display: flex; align-items: center; gap: 6px; }
.list-status { min-width: 0; }
[data-list-more] { min-width: 96px; }
[data-list-more][aria-busy="true"] { opacity: .65; pointer-events: none; }
.list-sentinel { height: 1px; }
.list-loading td { padding-top: 12px; padding-bottom: 12px; }
.list-loading .skeleton { display: block; height: 9px; border-radius: 4px; }
@keyframes list-row-in { from { opacity: 0; } to { opacity: 1; } }
.tbl tbody tr.is-new-row { animation: list-row-in .18s ease-out; }

/* Document */
.doc-head { display: flex; align-items: flex-start; gap: 18px; padding: 22px; border-bottom: 1px solid var(--border); }
.doc-logo { max-width: 130px; max-height: 54px; object-fit: contain; }
.doc-title { margin-left: auto; text-align: right; }
.doc-title .eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.doc-title h2 { font-size: 21px; margin-top: 2px; }
.doc-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.doc-meta-4 { grid-template-columns: 1.4fr 1fr 1fr .7fr; }
.doc-meta dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.doc-meta dd { margin: 3px 0 0; font-size: 12.5px; }
.doc-lines { padding: 0 22px; }
.doc-lines table { width: 100%; border-collapse: collapse; }
.doc-lines th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding: 12px 8px; border-bottom: 1px solid var(--border); }
.doc-lines td { padding: 11px 8px; border-bottom: 1px solid var(--border); font-size: 12.5px; vertical-align: top; }
.doc-lines .right { text-align: right; }
.doc-totals { padding: 16px 22px 20px; display: flex; justify-content: flex-end; }
.doc-totals .totals { margin: 0; }
.doc-notes { padding: 0 22px 22px; color: var(--text-dim); font-size: 12px; }
.doc-notes h3 { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin: 14px 0 4px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.invoice-summary { display: flex; flex-direction: column; gap: 16px; }
.invoice-balance-value { font-size: 26px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.invoice-summary-rows { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.invoice-summary-rows > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--text-dim); }
.invoice-summary-rows strong { font-weight: 550; color: var(--text); font-variant-numeric: tabular-nums; }
.client-card-name { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }
.client-card-name a { color: var(--text); }
.client-card-contact { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; font-size: 12px; color: var(--text-dim); }
.client-card-contact a { color: var(--text-dim); }
.client-card-contact a:hover { color: var(--text); }
.client-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.credit-list { display: flex; flex-direction: column; gap: 0; }
.credit-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.credit-row:first-child { padding-top: 0; }
.credit-row:last-child { border-bottom: 0; padding-bottom: 0; }
.credit-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.credit-row-main strong { font-size: 13px; font-weight: 550; color: var(--text); font-variant-numeric: tabular-nums; }
.credit-row-main span { font-size: 11.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credit-row small { color: var(--text-faint); font-size: 11px; white-space: nowrap; }
.api-token-callout { padding: 14px; border: 1px solid var(--accent-line); border-radius: var(--radius); background: var(--accent-soft); margin-bottom: 16px; }
.api-token-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.api-token-row code { flex: 1 1 260px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
.api-key-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 14px 0 18px; }
.api-key-form .field { flex: 1 1 260px; margin: 0; }
.api-docs-link { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; flex-wrap: wrap; }
.api-docs-link p { flex: 1 1 260px; }

/* Dialogue */
dialog { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); padding: 0; box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
dialog::backdrop { background: rgba(6, 8, 12, .62); backdrop-filter: blur(2px); }
.dialog-head { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 15px; }
.dialog-body { padding: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }

/* Auth and error pages */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 34%), var(--bg); }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-sm); }
.auth-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 28px; }
.auth-card h1 { font-size: 24px; letter-spacing: -0.03em; margin: 0 0 20px; }
.auth-card > p { color: var(--text-dim); font-size: 13px; margin: 0 0 18px; }
.auth-note { font-size: 11.5px; color: var(--text-faint); line-height: 1.55; }
.auth-submit { width: 100%; height: 42px; justify-content: center; margin-top: 4px; }
.auth-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 14px; }
.auth-dev { margin-top: 14px; font-size: 11.5px; color: var(--text-faint); }
.auth-dev a { color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px; }
.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 24px; }
.error-page h1 { font-size: 42px; color: var(--accent); }
.error-page p { color: var(--text-dim); margin: 6px 0 20px; }

/* Portal */
.portal { min-height: 100vh; background: var(--bg); padding: 30px 16px 54px; }
.portal-top { max-width: 820px; margin: 0 auto 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--text-faint); font-size: 11.5px; }
.portal-top .brand-mark { width: 20px; height: 20px; font-size: 11px; border-radius: 5px; }
.portal-top .powered { margin-left: auto; }
.paper {
  max-width: 820px; margin: 0 auto; background: var(--paper); color: var(--paper-text);
  border-radius: 8px; box-shadow: 0 18px 50px rgba(0, 0, 0, .18); overflow: hidden;
}
.paper a { color: #2f6fd0; }
.paper-head { display: flex; align-items: flex-start; gap: 20px; padding: 34px 38px 26px; }
.paper-logo { max-width: 150px; max-height: 58px; object-fit: contain; }
.paper-org h1 { font-size: 18px; letter-spacing: -0.02em; }
.paper-org p { font-size: 12px; color: var(--paper-muted); margin-top: 2px; }
.paper-title { margin-left: auto; text-align: right; }
.paper-title .label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--paper-muted); }
.paper-title h2 { font-size: 27px; letter-spacing: -0.03em; margin-top: 2px; }
.paper-title .number { font-size: 12px; color: var(--paper-muted); margin-top: 3px; }
.paper-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 20px; padding: 0 38px 26px; border-bottom: 1px solid var(--paper-border); }
.paper-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--paper-muted); }
.paper-value { font-size: 13px; margin-top: 4px; }
.paper-value strong { font-weight: 600; }
.paper-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.paper-table-wrap {
  scrollbar-color: var(--paper-border) transparent;
  background:
    linear-gradient(to right, var(--paper) 40%, transparent) left center / 24px 100% no-repeat local,
    linear-gradient(to left, var(--paper) 40%, transparent) right center / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0% 50%, rgba(0, 0, 0, .08), transparent) left center / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .08), transparent) right center / 10px 100% no-repeat scroll;
}
.paper-table th { text-align: left; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--paper-muted); padding: 16px 38px 8px; border-bottom: 1px solid var(--paper-border); }
.paper-table th:not(:first-child), .paper-table td:not(:first-child) { text-align: right; }
.paper-table td { padding: 12px 38px; border-bottom: 1px solid var(--paper-border); font-size: 13px; vertical-align: top; }
.paper-table td:first-child { padding-right: 0; }
.paper-table th:first-child { padding-right: 0; }
.paper-line-desc { font-size: 13px; }
.paper-line-meta { font-size: 11px; color: var(--paper-muted); margin-top: 2px; }
.paper-totals { display: flex; justify-content: flex-end; padding: 18px 38px 26px; }
.paper-totals .totals { width: 290px; max-width: 100%; margin: 0; }
.paper-totals .totals-row { color: var(--paper-muted); border-color: var(--paper-border); }
.paper-totals .totals-row strong { color: var(--paper-text); }
.paper-totals .grand { border-top: 1px solid var(--paper-border); color: var(--paper-text); }
.paper-totals .grand strong { color: var(--paper-text); }
.paper-notes { padding: 0 38px 30px; border-top: 1px solid var(--paper-border); padding-top: 18px; }
.paper-notes h3 { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--paper-muted); margin-bottom: 4px; }
.paper-notes p { font-size: 12px; color: #4b5563; white-space: pre-line; }
.paper-foot { display: flex; align-items: center; gap: 12px; padding: 14px 38px; background: #fafbfc; border-top: 1px solid var(--paper-border); color: var(--paper-muted); font-size: 11px; }
.pay-panel { max-width: 820px; margin: 16px auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; display: flex; align-items: center; gap: 16px; }
.pay-panel h2 { font-size: 15px; }
.pay-panel p { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.pay-panel .btn { margin-left: auto; }
.pay-panel .amount { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.test-note { font-size: 10.5px; color: var(--text-faint); margin-top: 4px; }
.portal-actions { max-width: 820px; margin: 16px auto 0; display: flex; gap: 8px; flex-wrap: wrap; }

/* Settings */
.settings-shell { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 26px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--header) + 18px); display: flex; flex-direction: column; gap: 20px; padding-top: 4px; }
.settings-nav-group { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-label {
  padding: 0 9px 5px; font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint);
}
.settings-nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px;
  border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text-dim); font-size: 12.5px; font-weight: 500;
}
.settings-nav-item .icon { color: var(--text-faint); flex: none; }
.settings-nav-item:hover { color: var(--text); background: var(--surface-2); }
.settings-nav-item.is-active { color: var(--text); background: var(--accent-soft); border-color: var(--accent-line); }
.settings-nav-item.is-active .icon { color: var(--accent); }
.settings-main { min-width: 0; max-width: 1040px; }
.settings-readonly-note { margin-bottom: 12px; }
.settings-section { display: none; }
.settings-section.is-active { display: block; }
.settings-head { align-items: flex-start; }
.settings-head-copy h2 { font-size: 15px; }
.settings-head-copy p { margin-top: 3px; font-size: 12px; color: var(--text-faint); }
.settings-head > .badge, .settings-head > .muted { margin-left: auto; }
.settings-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.settings-block { padding: 4px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.settings-block:last-of-type { padding-bottom: 6px; margin-bottom: 0; border-bottom: 0; }
.settings-block-head { margin-bottom: 14px; }
.settings-block-head h3 { font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }
.settings-block-head p { margin-top: 3px; max-width: 72ch; font-size: 11.5px; line-height: 1.5; color: var(--text-faint); }
.settings-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0; padding: 12px 16px; margin-bottom: 18px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.settings-fact { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding-right: 16px; }
.settings-fact + .settings-fact { padding-left: 16px; border-left: 1px solid var(--border); }
.settings-fact strong { font-size: 12.5px; font-weight: 550; overflow-wrap: anywhere; }
.settings-fact-link { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--accent); }
.settings-fact-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.settings-appearance { padding: 4px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.appearance-accent {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  margin-bottom: 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.appearance-swatch {
  width: 22px; height: 22px; border-radius: 50%; flex: none; margin-top: 1px;
  background: var(--accent); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14);
}
.appearance-accent-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.appearance-accent-copy strong { font-size: 13px; font-weight: 600; }
.appearance-accent-copy .hint { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; }
.appearance-accent-copy .hint a { color: var(--accent); }
.appearance-accent-copy .hint a:hover { text-decoration: underline; text-underline-offset: 2px; }
[data-accent-sync-status] { color: var(--text-faint); }
.appearance-sync-warning {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 10px 12px; margin-bottom: 14px;
  border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border));
  border-radius: 8px; background: var(--warn-soft); font-size: 12px;
}
.appearance-sync-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.appearance-sync-copy strong { font-size: 12.5px; font-weight: 600; }
.appearance-sync-copy span { color: var(--text-dim); }
.theme-choice-row { display: flex; gap: 6px; flex-wrap: wrap; }
.settings-empty { border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.code-input { font-family: var(--mono); font-size: 12px; line-height: 1.5; }

/* Settings: brand editor */
.branding-grid { display: grid; grid-template-columns: minmax(160px, .75fr) minmax(220px, 1fr); gap: 0 18px; }
.branding-grid .wide { grid-column: 1 / -1; }
.logo-current {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.logo-empty {
  padding: 16px; border: 1px dashed var(--border-strong); border-radius: 8px;
  color: var(--text-faint); font-size: 12px;
}

/* Settings: disclosures */
.settings-disclosure {
  margin: 0 0 18px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.settings-disclosure > summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  list-style: none; cursor: pointer; user-select: none;
}
.settings-disclosure > summary::-webkit-details-marker { display: none; }
.settings-disclosure > summary::after {
  content: ""; flex: none; width: 7px; height: 7px; margin-left: auto;
  border-right: 1.5px solid var(--text-faint); border-bottom: 1.5px solid var(--text-faint);
  transform: rotate(45deg) translateY(-1px); transition: transform .15s ease;
}
.settings-disclosure[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.settings-disclosure-title { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; }
.settings-disclosure-meta { margin-left: auto; font-size: 11.5px; color: var(--text-faint); text-align: right; }
.settings-disclosure-body { padding: 14px; border-top: 1px solid var(--border); }
.template-vars { margin-top: 12px; }
.template-vars summary { cursor: pointer; }
.template-vars-list { margin-top: 8px; line-height: 1.9; }

/* Settings: email */
.email-overview {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(170px, .8fr) minmax(190px, .9fr);
  gap: 18px; align-items: start; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.email-summary { display: flex; gap: 12px; min-width: 0; }
.email-mark {
  display: grid; place-items: center; flex: none; width: 38px; height: 38px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}
.email-summary-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.email-address { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.email-address.is-unset { color: var(--warn); }
.email-meta { font-size: 11.5px; color: var(--text-faint); }
.email-domain, .email-usage { display: flex; flex-direction: column; gap: 5px; min-width: 0; padding-left: 18px; border-left: 1px solid var(--border); }
.email-domain-name { font-size: 13px; font-weight: 550; overflow-wrap: anywhere; }
.email-inline { font-family: var(--mono); font-size: 11px; color: var(--text-dim); overflow-wrap: anywhere; }
.email-domain .hint { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.email-usage-value { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.email-usage-value span { font-size: 11.5px; font-weight: 400; color: var(--text-faint); }
.email-note { margin: 10px 0 18px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.choice-card {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.choice-card:hover { border-color: var(--border-strong); }
.choice-card:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
.choice-card input { flex: none; margin-top: 2px; accent-color: var(--accent); }
.choice-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.choice-title { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text); }
.choice-desc { font-size: 11.5px; line-height: 1.45; color: var(--text-dim); }
.choice-detail { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--border); }
.email-domain-picks { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  color: var(--text-dim); font-size: 11px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }

@media (max-width: 1000px) {
  .settings-shell { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .settings-nav {
    position: static; flex-direction: row; flex-wrap: wrap; gap: 8px 14px;
    padding: 0 0 10px; border-bottom: 1px solid var(--border);
  }
  .settings-nav-group { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .settings-nav-label { display: none; }
  .settings-nav-item { padding: 7px 8px; font-size: 12px; white-space: nowrap; }
  .email-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .email-summary { grid-column: 1 / -1; }
  .email-domain { padding-left: 0; border-left: 0; }
}
@media (max-width: 640px) {
  .settings-facts, .email-overview, .choice-grid, .branding-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-fact { padding-right: 0; }
  .settings-fact + .settings-fact { padding-top: 10px; padding-left: 0; margin-top: 10px; border-top: 1px solid var(--border); border-left: 0; }
  .email-domain, .email-usage { padding-top: 10px; padding-left: 0; border-top: 1px solid var(--border); border-left: 0; }
  .settings-disclosure-meta { display: none; }
}

/* Utility */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.content:focus { outline: none; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); } .text-success { color: var(--success); } .text-warn { color: var(--warn); }
.small { font-size: 11.5px; } .tiny { font-size: 10.5px; }
.hide { display: none !important; }

/* Responsive */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .header-search { width: clamp(170px, 22vw, 260px); }
}
@media (max-width: 900px) {
  :root { --sidebar: 252px; }
  .invoice-details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-user .user-copy { display: none; }
  .sidebar {
    transform: translateX(-100%); visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0); visibility: visible; transition: transform .2s ease;
  }
  body.sidebar-open { overflow: hidden; }
  .shell { margin-left: 0; }
  .mobile-menu { display: inline-grid !important; }
  .sidebar-backdrop { display: none; position: fixed; inset: var(--header) 0 0; background: rgba(6, 8, 12, .55); z-index: 44; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .app-header { padding: 0 16px; gap: 10px; }
  .content { padding: 20px 16px 44px; }
  .header-search { width: clamp(150px, 24vw, 220px); }
  .page-heading h1 { font-size: 19px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .invoice-details-grid { grid-template-columns: minmax(0, 1fr); }
  .notes-terms { grid-template-columns: minmax(0, 1fr); }
  .surcharge-options { grid-template-columns: minmax(0, 1fr); }
  .invoice-form-summary { flex: 1 1 100%; position: static; top: auto; }
  .doc-head, .doc-meta, .doc-lines, .doc-totals, .doc-notes { padding-left: 16px; padding-right: 16px; }
  .doc-meta { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .doc-lines th:nth-child(3), .doc-lines td:nth-child(3),
  .doc-lines th:nth-child(4), .doc-lines td:nth-child(4),
  .doc-lines th:nth-child(5), .doc-lines td:nth-child(5) { display: none; }
  .invoice-payments th:nth-child(3), .invoice-payments td:nth-child(3) { display: none; }
  .paper-head, .paper-meta, .paper-notes, .paper-foot { padding-left: 20px; padding-right: 20px; }
  .paper-table th, .paper-table td { padding-left: 20px; padding-right: 20px; }
  .paper-meta { grid-template-columns: minmax(0, 1fr); }
  .pay-panel { flex-wrap: wrap; }
  .pay-panel .btn { margin-left: 0; }
}
@media (max-width: 759px) {
  .header-org { display: none; }
  .sidebar-org { display: block; }
  .sidebar-org .org-switch { margin: 0 0 8px; }
  .sidebar-org .org-menu { width: 260px; }
}
@media (max-width: 620px) {
  .cash-label { font-size: 17px; }
  .sidebar { --sidebar: 280px; }
  .header-search kbd { display: none; }
  .page-head { flex-wrap: wrap; gap: 12px; }
  .page-heading { flex: 1 1 100%; }
  .page-heading h1 { font-size: 19px; white-space: normal; overflow: visible; text-overflow: clip; }
  .page-actions { width: 100%; justify-content: flex-start; }
  .page-actions .btn-row { width: 100%; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .stat { border-right: 0; border-bottom: 1px solid var(--border); }
  .stat:last-child { border-bottom: 0; }
  .totals { width: 100%; }
  .pagination, .list-footer { flex-direction: column; gap: 8px; align-items: flex-start; }

  .filters { gap: 6px; }
  .filters .search { flex: 1 1 100%; }
  .filters select { flex: 1 1 140px; min-width: 0; }
  .filters input[type="date"] { flex: 0 1 128px; width: auto; min-width: 0; }
  .chart { gap: 6px; }
  .tabs { flex-wrap: wrap; row-gap: 2px; }

  .panel-head { flex-wrap: wrap; row-gap: 6px; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .spacer { display: none; }
  .form-actions .btn { flex: 1 1 auto; }

  .panel > .doc-meta { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  .paper-head { flex-wrap: wrap; gap: 14px; }
  .paper-title { flex: none; }
  .paper-title h2 { white-space: nowrap; font-size: 24px; }
  .paper-table th, .paper-table td { white-space: nowrap; padding-left: 8px; padding-right: 8px; }
  .paper-table td { font-size: 12px; }
  .paper-table th:first-child, .paper-table td:first-child { padding-left: 20px; padding-right: 8px; }
  .paper-table th:last-child, .paper-table td:last-child { padding-right: 20px; }
  .paper-line-desc, .paper-line-meta { white-space: normal; }

  .pay-panel { display: block; }
  .pay-panel .amount { margin-top: 10px; }
  .pay-panel form { margin-top: 14px; }
  .pay-panel .btn { width: 100%; }
}

@media (max-width: 560px) {
  .header-search {
    width: 34px; min-width: 34px; justify-content: center; padding: 0;
    border-color: transparent; background: transparent;
  }
  .header-search:hover { background: var(--surface-2); }
  .header-search:focus-within { border-color: transparent; box-shadow: none; }
  .header-search input, .header-search kbd { display: none; }
  .header-search .search-submit { width: 34px; height: 34px; color: var(--text-dim); }
}

/* Phones: the wordmark is the first thing to go, otherwise it collides with
   the search, theme and account controls on 360px screens. */
@media (max-width: 440px) {
  .app-header { padding: 0 12px; gap: 6px; }
  .header-lead { gap: 6px; }
  .app-brand-word { display: none; }
}

@media (max-width: 360px) {
  .panel > .doc-meta { grid-template-columns: minmax(0, 1fr) !important; }
}

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

@media print {
  .sidebar, .app-header, .topbar, .page-actions, .portal-top, .pay-panel, .portal-actions, .flash-stack,
  .doc-actions, .filters, .pagination, .list-footer, .list-sentinel, .tabs, dialog { display: none !important; }
  .shell { margin: 0; }
  .portal { padding: 0; background: #fff; }
  .paper { box-shadow: none; border-radius: 0; max-width: none; }
  .paper-head { padding-top: 10mm; }
  .table-wrap, .lines-wrap { overflow: visible !important; background: none; }
  .paper-table { display: table; width: 100%; }
  body { background: #fff; }
}

/* Context menus */
.context-menu {
  position: fixed; z-index: 200; min-width: 210px; max-width: min(280px, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 5px;
}
.context-menu .menu-item { width: 100%; }
.context-menu .menu-item.is-danger { color: var(--danger); }
.context-menu .menu-item.is-danger:hover { background: var(--danger-soft); }
.context-menu .menu-separator { height: 1px; background: var(--border); margin: 5px 4px; }
.context-menu .menu-label { padding: 5px 9px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.context-menu form { margin: 0; }
.is-context-target { outline: 1px solid var(--accent-line); outline-offset: -1px; }
tr[data-menu], [data-menu] { -webkit-touch-callout: none; }

/* Vendor and client analytics */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 1.1fr) minmax(60px, 1.6fr) auto; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-row:hover .bar-label a { color: var(--accent); }
.bar-label { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.bar-label a { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label small { color: var(--text-faint); font-size: 10.5px; }
.bar-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 2px; }
.bar-fill.is-vendor { background: var(--warn); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--text-dim); white-space: nowrap; }
.metric-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.metric-line span { color: var(--text-dim); }
.metric-line strong { font-variant-numeric: tabular-nums; font-weight: 600; }
.spend-chart { height: 160px; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 5px; align-items: end; padding-top: 4px; border-bottom: 1px solid var(--border); }
.spend-col { height: 100%; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.spend-value { height: 12px; font-size: 9.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: clip; max-width: 100%; }
.spend-track { width: 100%; max-width: 30px; flex: 1; display: flex; align-items: flex-end; }
.spend-label { font-size: 9.5px; color: var(--text-faint); }
.spend-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 11px; color: var(--text-faint); }
.spend-summary strong { color: var(--text-dim); font-weight: 550; }
.tbl-compact td, .tbl-compact th { padding-top: 7px; padding-bottom: 7px; }
.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 220; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 10px 14px; font-size: 12.5px; opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; max-width: min(340px, calc(100vw - 32px)); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.toast.is-success { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); }

@media (max-width: 640px) {
  .bar-row { grid-template-columns: minmax(90px, 1.2fr) minmax(50px, 1fr) auto; gap: 7px; }
  .bar-label small { display: none; }
}

.category-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.category-chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--text-dim); }
.category-chip small { font-size: 10.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.plain-list { margin: 8px 0 0; padding-left: 18px; color: var(--text-dim); }
.plain-list li { margin: 4px 0; }
.plain-list code { font-size: 11px; color: var(--text); background: var(--surface-2); padding: 2px 5px; border-radius: 4px; }

/* Email settings */
.usage-meter { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.usage-meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Sortable table headers */
th.is-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.is-sortable:hover { color: var(--text); }
th.is-sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sort-arrow { display: inline-block; width: 0; height: 0; margin-left: 5px; vertical-align: middle; border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; opacity: .3; }
th.is-sort-asc .sort-arrow { border-bottom: 5px solid currentColor; opacity: 1; }
th.is-sort-desc .sort-arrow { border-top: 5px solid currentColor; opacity: 1; }

/* ==========================================================================
   Reports page — reports-only layout and analytics visuals
   ========================================================================== */

.rpt-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}
.rpt-span-7 { grid-column: span 7; }
.rpt-span-5 { grid-column: span 5; }
.rpt-panel { display: flex; flex-direction: column; min-width: 0; }
.rpt-panel > .panel-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.rpt-panel > .pagination { margin-top: auto; }

/* Income vs expenses */
.rpt-chart-body { justify-content: flex-end; gap: 10px; }
.rpt-chart { --rpt-gap: 6px; display: flex; flex-direction: column; gap: 7px; flex: 1 1 auto; justify-content: flex-end; }
.rpt-plot {
  flex: 1 1 auto; min-height: 160px; padding-top: 4px;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: var(--rpt-gap); align-items: stretch;
  background: repeating-linear-gradient(to top, var(--border) 0 1px, transparent 1px 25%);
}
.rpt-slot { display: flex; align-items: flex-end; min-width: 0; }
.rpt-bars { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; }
.rpt-bar { flex: 1; min-width: 0; min-height: 2%; border-radius: 3px 3px 0 0; transition: filter .12s; }
.rpt-bar-income { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 86%, white 14%), color-mix(in srgb, var(--accent) 52%, var(--surface-2))); }
.rpt-bar-expense { background: linear-gradient(180deg, color-mix(in srgb, var(--warn) 80%, white 20%), color-mix(in srgb, var(--warn) 48%, var(--surface-2))); }
.rpt-bar.is-empty { background: var(--border); }
.rpt-bar:hover { filter: brightness(1.12); }
.rpt-axis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--rpt-gap); }
.rpt-axis span { font-size: 10px; color: var(--text-faint); text-align: center; overflow: hidden; white-space: nowrap; }

/* Invoice status */
.rpt-status-body { justify-content: center; }
.rpt-status-body .donut { width: 176px; height: 176px; }
.rpt-status-body .legend-value { font-size: 11.5px; }

/* Cash flow */
.rpt-cash-body { justify-content: center; }
.cash-dot { fill: var(--text); stroke: var(--surface); stroke-width: 1; }

/* Receivables aging */
.rpt-aging-body { justify-content: space-between; gap: 16px; }
.rpt-aging-body .stack-bar { margin: 0; height: 14px; }
.rpt-aging-body .stack-legend { gap: 9px; }
.rpt-aging-body .rpt-empty { padding: 0; margin: 0; }

/* Top clients */
.rpt-clients-body { justify-content: center; }
.rpt-client-layout { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap; }
.rpt-client-donut { position: relative; width: 144px; height: 144px; flex: none; }
.rpt-donut { width: 100%; height: 100%; display: block; }
.rpt-donut-track { stroke: var(--surface-2); }
.rpt-donut-seg { stroke: var(--rpt-color); transition: opacity .12s; }
.rpt-donut-seg:hover { opacity: .8; }
.rpt-donut-center {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; z-index: 1; pointer-events: none;
}
.rpt-donut-center strong { font-size: 22px; font-weight: 600; letter-spacing: -0.03em; }
.rpt-donut-center span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.rpt-client-list {
  flex: 1 1 220px; min-width: 0; margin: 0; padding: 0;
  list-style: none; display: flex; flex-direction: column;
}
.rpt-client-row {
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center; gap: 9px; padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.rpt-client-row:last-child { border-bottom: 0; }
.rpt-rank {
  display: inline-grid; place-items: center; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface-2); color: var(--text-faint);
  font-size: 9.5px; font-variant-numeric: tabular-nums;
}
.rpt-client-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rpt-client-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.rpt-client-line a {
  font-size: 12.5px; font-weight: 550; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rpt-client-line a:hover { color: var(--accent); }
.rpt-client-other { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-client-name small { font-size: 10.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-client-value { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-variant-numeric: tabular-nums; }
.rpt-client-value strong { font-size: 12.5px; font-weight: 600; }
.rpt-client-value small { font-size: 10.5px; color: var(--text-faint); }
.rpt-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rpt-color); flex: none; }
.rpt-dot.is-unlinked {
  background: repeating-linear-gradient(135deg, var(--border-strong) 0 2px, color-mix(in srgb, var(--border-strong) 45%, var(--surface-2)) 2px 4px);
}

/* Client profitability */
.rpt-margins-body { gap: 10px; }
.rpt-table-wrap { flex: 1 1 auto; }
.rpt-table { table-layout: fixed; min-width: 430px; }
.rpt-table col:nth-child(1) { width: 36%; }
.rpt-table col:nth-child(2) { width: 21%; }
.rpt-table col:nth-child(3) { width: 21%; }
.rpt-table col:nth-child(4) { width: 22%; }
.rpt-table td:first-child a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-table td.right { white-space: nowrap; }
.rpt-table-hint { margin-top: auto; padding-top: 4px; font-size: 11px; color: var(--text-faint); }
.rpt-margin-cards { display: none; }
.rpt-margin-card { padding: 10px 0; border-bottom: 1px solid var(--border); }
.rpt-margin-card:last-child { border-bottom: 0; }
.rpt-margin-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rpt-margin-top a { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-margin-value { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rpt-margin-value small { display: block; font-size: 10.5px; font-weight: 400; color: var(--text-faint); }
.rpt-margin-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 3px; font-size: 10.5px; color: var(--text-faint); }
.rpt-margin-meta strong { color: var(--text-dim); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Vendor spend */
.rpt-vendor-body { gap: 14px; }
.rpt-share { display: flex; gap: 2px; height: 16px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.rpt-share-seg { min-width: 2px; border-radius: 2px; background: var(--rpt-color); }
.rpt-share-seg.is-unlinked {
  background: repeating-linear-gradient(135deg, var(--border-strong) 0 4px, color-mix(in srgb, var(--border-strong) 45%, var(--surface-2)) 4px 8px);
}
.rpt-vendor-list {
  list-style: none; margin: 0; padding: 0; min-width: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 16px;
}
.rpt-vendor-list li { min-width: 0; }
.rpt-vcard {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  margin: 0 -6px; padding: 6px; border-radius: 6px;
}
.rpt-vcard:hover { background: var(--surface-2); }
.rpt-vcard-main { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.rpt-vcard-name { font-size: 12.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-vcard-meta { font-size: 10.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-vcard-amount { font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rpt-note { font-size: 11.5px; color: var(--text-faint); }
.rpt-note a { color: var(--accent); }
.rpt-share-foot {
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  font-size: 11px; color: var(--text-faint);
}
.rpt-share-foot strong { color: var(--text-dim); font-weight: 550; font-variant-numeric: tabular-nums; }

/* Expenses by category */
.rpt-treemap-body { justify-content: center; }
.rpt-treemap-body .expense-map { height: 250px; }

.rpt-empty { margin: 0; padding: 24px 0; text-align: center; }

@media (max-width: 1180px) {
  .rpt-grid { grid-template-columns: minmax(0, 1fr); }
  .rpt-span-7, .rpt-span-5 { grid-column: auto; }
}

@media (max-width: 640px) {
  .rpt-chart { --rpt-gap: 4px; }
  .rpt-plot { min-height: 132px; }
  .rpt-client-donut { width: 124px; height: 124px; }
  .rpt-client-list { flex-basis: 100%; }
  .rpt-vendor-list { grid-template-columns: minmax(0, 1fr); }
  .rpt-treemap-body .expense-map { height: 210px; }
  .rpt-table-wrap { display: none; }
  .rpt-margin-cards { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rpt-bar, .rpt-donut-seg { transition: none; }
}

/* Reports load motion */
@keyframes rpt-grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes rpt-grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes rpt-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rpt-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes rpt-tile-in { from { opacity: 0; transform: scale(.62); } to { opacity: 1; transform: scale(1); } }

.rpt-bar {
  transform-origin: bottom;
  animation: rpt-grow-y .62s cubic-bezier(.22, .8, .3, 1) both;
  animation-delay: calc(var(--chart-index, 0) * 35ms);
}
.cash-income {
  transform-box: fill-box; transform-origin: center bottom;
  animation: rpt-grow-y .62s cubic-bezier(.22, .8, .3, 1) both;
}
.cash-expense {
  transform-box: fill-box; transform-origin: center top;
  animation: rpt-grow-y .62s cubic-bezier(.22, .8, .3, 1) both;
}
.cash-net { stroke-dasharray: 1; stroke-dashoffset: 1; animation: rpt-draw .82s .12s ease forwards; }
.cash-dot { opacity: 0; animation: rpt-fade .3s .55s ease forwards; }
.stack-seg {
  transform-origin: left center;
  animation: rpt-grow-x .62s cubic-bezier(.22, .8, .3, 1) both;
  animation-delay: calc(var(--segment-index, 0) * 45ms);
}
.rpt-share-seg {
  transform-origin: left center;
  animation: rpt-grow-x .65s cubic-bezier(.22, .8, .3, 1) both;
  animation-delay: calc(var(--segment-index, 0) * 50ms);
}
.expense-cell {
  animation: rpt-tile-in .55s cubic-bezier(.22, .8, .3, 1) both;
  animation-delay: calc(var(--tile-index, 0) * 45ms);
}
.rpt-donut-seg {
  transition: stroke-dasharray .72s cubic-bezier(.22, .8, .3, 1),
              stroke-dashoffset .72s cubic-bezier(.22, .8, .3, 1),
              opacity .12s ease;
}

@media (prefers-reduced-motion: reduce) {
  .rpt-bar, .cash-income, .cash-expense, .cash-dot,
  .stack-seg, .rpt-share-seg, .expense-cell, .rpt-donut-seg { animation: none !important; transition: none !important; }
  .cash-net { stroke-dasharray: none; stroke-dashoffset: 0; animation: none !important; }
  .cash-dot { opacity: 1; }
  .expense-cell, .expense-map, [data-expense-summary-wrap], .legend-name,
  .donut-center span, .chart-toggle-thumb, .donut-seg { transition: none !important; }
  .donut-svg.is-switching { animation: none !important; }
}

/* Domain settings */
.domain-list { display: flex; flex-direction: column; }
.domain-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-top: 1px solid var(--border); }
.domain-row:first-child { border-top: 0; padding-top: 0; }
.domain-row p { margin-top: 3px; max-width: 620px; }
@media (max-width: 640px) { .domain-row { align-items: flex-start; flex-direction: column; } }

/* Keep the original reports column arrangement with the richer panels */
.rpt-clients-panel .rpt-client-layout { flex-direction: column; align-items: stretch; gap: 14px; }
.rpt-clients-panel .rpt-client-donut { width: 150px; height: 150px; margin: 0 auto; flex: none; }
.rpt-clients-panel .rpt-client-list { flex-basis: auto; width: 100%; }
.reports-secondary .rpt-vendor-list { grid-template-columns: minmax(0, 1fr); }
.reports-secondary .rpt-vendor-panel .rpt-share { margin-bottom: 2px; }
@media (max-width: 640px) {
  .rpt-clients-panel .rpt-client-donut { width: 128px; height: 128px; }
}

/* Vendor and client branding */
.vendor-logo-preview { width: 120px; height: 120px; object-fit: contain; border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 12px; }
.client-logo-preview { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--border); border-radius: 50%; background: #fff; padding: 8px; }
.vendor-avatar { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--border); padding: 4px; flex: none; }
.vendor-avatar-sm { width: 30px; height: 30px; border-radius: 8px; padding: 3px; }
.vendor-avatar-lg { width: 48px; height: 48px; border-radius: 12px; padding: 6px; }
.vendor-avatar.vendor-avatar-fallback { display: grid; place-items: center; color: #fff; background: var(--vendor-color, #b45309); border-color: transparent; padding: 0; font-size: 14px; font-weight: 650; letter-spacing: -0.02em; }
.vendor-avatar-sm.vendor-avatar-fallback { font-size: 11px; }
.vendor-avatar-lg.vendor-avatar-fallback { font-size: 16px; }
.vendor-avatar[src$="/aws.svg"] { padding: 7px 4px; }
.vendor-avatar-sm[src$="/aws.svg"] { padding: 6px 3px; }
.vendor-avatar-lg[src$="/aws.svg"] { padding: 8px 5px; }
.vendor-hero-logo { width: 48px; height: 48px; border-radius: 12px; object-fit: contain; background: #fff; border: 1px solid var(--border); padding: 6px; flex: none; }
.vendor-name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }

.client-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: contain; background: #fff; border: 1px solid var(--border); padding: 4px; flex: none; }
.client-avatar-xs { width: 24px; height: 24px; padding: 2px; }
.client-avatar-sm { width: 30px; height: 30px; padding: 3px; }
.client-avatar-lg { width: 64px; height: 64px; padding: 8px; }
.client-avatar.client-avatar-initial { display: grid; place-items: center; background: var(--client-color, var(--accent)); border-color: transparent; padding: 0; color: #fff; font-size: 11px; font-weight: 650; letter-spacing: -0.02em; }
.client-avatar-xs.client-avatar-initial { font-size: 8px; }
.client-avatar-sm.client-avatar-initial { font-size: 9px; }
.client-avatar-lg.client-avatar-initial { font-size: 22px; }
.client-avatar[src$="/aws.svg"] { padding: 6px 3px; }
.client-avatar-xs[src$="/aws.svg"] { padding: 4px 2px; }
.client-avatar-lg[src$="/aws.svg"] { padding: 10px 6px; }
.client-name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.client-hero-panel { margin-bottom: 18px; }
.client-hero { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.client-hero-copy { min-width: 0; flex: 1 1 auto; }
.client-hero-copy h2 { margin: 2px 0 0; font-size: 18px; letter-spacing: -0.02em; }
.client-hero-copy p { margin-top: 2px; color: var(--text-dim); font-size: 12.5px; }
.client-card-head { display: flex; align-items: center; gap: 10px; }
@media (max-width: 640px) { .client-hero { align-items: flex-start; } }

/* Suggested companies */
.suggested-panel { margin-bottom: 16px; }
.suggested-panel .panel-head { flex-wrap: wrap; }
.suggested-panel .panel-head form { margin-left: auto; }
.suggested-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.suggested-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.suggested-logo { width: 34px; height: 34px; border-radius: 9px; background: #fff; border: 1px solid var(--border); display: grid; place-items: center; flex: none; padding: 4px; }
.suggested-logo img { width: 100%; height: 100%; object-fit: contain; }
.suggested-copy { display: flex; flex-direction: column; line-height: 1.25; padding-right: 4px; }
.suggested-copy strong { font-size: 12.5px; font-weight: 600; }
.suggested-copy small { font-size: 10.5px; color: var(--text-faint); }
.suggested-card[hidden] { display: none; }
.suggested-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.suggested-foot .hint { margin: 0; }
.suggested-sentinel { flex: none; width: 100%; height: 1px; grid-column: 1 / -1; }
.suggested-sentinel[hidden] { display: none; }
.suggested-loading { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-faint); }
.suggested-loading::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: suggested-spin .7s linear infinite;
}
.suggested-loading[hidden] { display: none; }
@keyframes suggested-spin { to { transform: rotate(360deg); } }

/* Suggested companies in the new-vendor sidebar */
.vendor-form-side { position: sticky; top: calc(var(--topbar) + 18px); }
.vendor-form-side .suggested-panel { margin-bottom: 0; }
.vendor-form-side .suggested-search { margin-bottom: 10px; }
.vendor-form-side .suggested-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  max-height: min(460px, 55vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding-right: 2px;
}
.vendor-form-side .suggested-card { position: relative; flex-direction: column; align-items: center; gap: 4px; padding: 7px 5px; text-align: center; cursor: pointer; }
.vendor-form-side .suggested-logo { width: 30px; height: 30px; padding: 3px; }
.vendor-form-side .suggested-copy { align-items: center; padding: 0; }
.vendor-form-side .suggested-copy strong { font-size: 10.5px; line-height: 1.15; }
.vendor-form-side .suggested-copy small { font-size: 8.5px; line-height: 1.1; }
.vendor-form-side .suggested-hit { position: absolute; inset: 0; border: 0; border-radius: inherit; background: transparent; cursor: pointer; }
.vendor-form-side .suggested-hit::after {
  content: "+";
  position: absolute; top: 4px; right: 4px;
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 500; line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  opacity: 0; transform: scale(.7);
  transition: opacity .12s, transform .12s;
  pointer-events: none;
}
.vendor-form-side .suggested-card:hover,
.vendor-form-side .suggested-card:focus-within { border-color: var(--accent-line); background: var(--surface-3); }
.vendor-form-side .suggested-hit:hover::after,
.vendor-form-side .suggested-hit:focus-visible::after { opacity: 1; transform: scale(1); }
@media (max-width: 1100px) { .vendor-form-side { position: static; } }

/* Compact income-by-method strip */
.income-methods { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 14px; border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; }
.income-methods-label { font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.income-method { display: inline-flex; align-items: baseline; gap: 5px; font-size: 11.5px; color: var(--text-dim); }
.income-method-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; align-self: center; }
.income-method-name { color: var(--text-dim); }
.income-method strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.income-method small { color: var(--text-faint); font-size: 10.5px; }
@media (max-width: 640px) { .income-methods { gap: 6px 11px; } }

/* Two-up client metrics */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

/* Client detail polish */
.metric-stack { grid-template-columns: minmax(0, 1fr); }
.details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .details-grid { grid-template-columns: minmax(0, 1fr); } }

/* Inline help */
.help-tip { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-left: 6px; border: 1px solid var(--border-strong); border-radius: 50%; color: var(--text-faint); font-size: 10px; font-weight: 700; vertical-align: 2px; cursor: help; }
.help-tip:hover, .help-tip:focus-visible { color: var(--text); border-color: var(--text-faint); outline: none; }

/* Vendor profile header */
.vendor-hero-panel { margin-bottom: 18px; }
.vendor-hero { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.vendor-hero-copy { min-width: 0; flex: 1 1 auto; }
.vendor-hero-copy h2 { margin: 2px 0 0; font-size: 18px; letter-spacing: -0.02em; }
.vendor-hero-copy p { margin-top: 2px; color: var(--text-dim); font-size: 12.5px; }
.vendor-color-chip { display: inline-flex; align-items: center; gap: 6px; color: var(--text-faint); font-size: 10.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vendor-color-chip span { width: 10px; height: 10px; border-radius: 50%; }
@media (max-width: 640px) { .vendor-hero { align-items: flex-start; } .vendor-color-chip { display: none; } }

/* Vendor spend by category */
.spend-stack { display: flex; flex-direction: column-reverse; width: 100%; max-width: 30px; min-height: 2px; border-radius: 4px 4px 0 0; overflow: hidden; gap: 1px; }
.spend-segment { display: block; width: 100%; min-height: 2px; }
.spend-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.spend-legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-faint); }
.spend-legend-item i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.spend-legend-item strong { font-weight: 550; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Assistant */
.ai-connect {
  max-width: 420px; margin: clamp(24px, 9vh, 96px) auto 0; padding: 30px 26px;
  text-align: center;
}
.ai-connect-icon, .assistant-empty-icon {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 12px;
  border-radius: 12px; background: var(--accent-soft); color: var(--accent);
}
.ai-connect-icon { margin: 0 auto 14px; }
.ai-connect h2 { font-size: 16px; margin-bottom: 6px; }
.ai-connect > p { color: var(--text-dim); font-size: 12.5px; }
.ai-connect .btn-row { justify-content: center; margin-top: 18px; }
.ai-connect .btn:disabled, .assistant-composer .btn:disabled { opacity: .55; cursor: not-allowed; }

.assistant-layout {
  display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 14px;
  width: 100%; height: calc(100vh - 190px); min-height: 480px; margin: 0;
}
.chat-sidebar {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.chat-new {
  display: flex; align-items: center; gap: 7px; margin: 10px 10px 6px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-dim); font-size: 12.5px; font-weight: 550;
}
.chat-new:hover { border-color: var(--accent-line); background: var(--surface-2); color: var(--text); }
.chat-new .icon { color: var(--accent); }
.chat-list {
  flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px;
  min-height: 0; min-width: 0; overflow-y: auto; padding: 4px 8px 10px;
}
.chat-item {
  display: flex; flex-direction: column; gap: 1px; padding: 7px 9px;
  border-radius: var(--radius); color: var(--text-dim);
}
.chat-item-row { display: flex; align-items: center; border-radius: var(--radius); }
.chat-item-row:hover { background: var(--surface-2); }
.chat-item-row .chat-item { flex: 1 1 auto; min-width: 0; }
.chat-item-row:hover .chat-item { background: transparent; color: var(--text); }
.chat-item-row .chat-item.is-active { background: var(--accent-soft); }
/* Collapse the delete action into the row so titles keep the full width; it
   slides open only while the row is hovered or focused. */
.chat-delete {
  flex: none; margin: 0; width: 0; min-width: 0; overflow: hidden;
  transition: width .16s ease;
}
.chat-item-row:hover .chat-delete,
.chat-item-row:focus-within .chat-delete { width: 26px; }
.chat-delete-button {
  display: grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 5px; background: transparent; color: var(--text-faint);
  cursor: pointer; opacity: 0; transform: translateX(3px);
  transition: opacity .13s ease, transform .16s ease, color .12s ease;
}
.chat-item-row:hover .chat-delete-button,
.chat-item-row:focus-within .chat-delete-button,
.chat-delete-button:focus-visible { opacity: 1; transform: none; }
.chat-delete-button:hover { color: var(--danger); background: transparent; }
.chat-delete-button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
@media (hover: none) {
  .chat-delete { width: 26px; }
  .chat-delete-button { opacity: 1; transform: none; }
}
.chat-item:hover { background: var(--surface-2); color: var(--text); }
.chat-item.is-active { background: var(--accent-soft); color: var(--text); }
.chat-item-title { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-date { font-size: 10.5px; color: var(--text-faint); }
.chat-sidebar-foot { margin-top: auto; padding: 8px; border-top: 1px solid var(--border); }
.chat-sidebar-foot form { margin: 0; }
.chat-sidebar-foot .btn { width: 100%; justify-content: flex-start; color: var(--text-faint); font-size: 11.5px; }
.chat-sidebar-foot .btn:hover { color: var(--text); }

.assistant-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.assistant-log {
  flex: 1 1 auto; display: flex; flex-direction: column; gap: 14px;
  min-height: 0; overflow-y: auto; scrollbar-gutter: stable; padding: 20px 22px;
  overscroll-behavior: contain;
}
.assistant-empty { margin: auto; max-width: 460px; padding: 18px 0; text-align: center; }
.assistant-empty-icon { width: 42px; height: 42px; margin: 0 auto 12px; }
.assistant-empty-lead { color: var(--text-dim); font-size: 13px; }
.assistant-jump {
  order: 999; position: sticky; bottom: 4px; align-self: center;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-dim);
  font-size: 11px; font-weight: 550; cursor: pointer;
  box-shadow: var(--shadow-sm); z-index: 3;
}
.assistant-jump:hover { background: var(--surface-2); color: var(--text); }
.assistant-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 14px; }
.assistant-suggestion {
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); font-size: 11.5px;
  line-height: 1.35; cursor: pointer;
}
.assistant-suggestion:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--text); }

.assistant-turn { display: flex; gap: 9px; align-items: flex-start; }
.assistant-turn-user { justify-content: flex-end; }
.assistant-turn-user .assistant-bubble {
  background: var(--accent); color: var(--accent-contrast); border-color: transparent;
  border-bottom-right-radius: 3px;
}
.assistant-turn-ai .assistant-bubble {
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 3px;
}
.assistant-bubble {
  max-width: min(78%, 620px); padding: 9px 13px; border-radius: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px;
}
.assistant-bubble.is-streaming::after {
  content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 2px;
  vertical-align: -2px; background: var(--accent); animation: assistant-caret 1s steps(1) infinite;
}
.assistant-avatar {
  display: grid; place-items: center; flex: none; width: 27px; height: 27px; margin-top: 2px;
  border-radius: 8px; background: var(--accent-soft); color: var(--accent);
}
.assistant-turn-body {
  display: flex; flex-direction: column; align-items: flex-start; gap: 9px;
  min-width: 0; max-width: calc(100% - 36px);
}
.assistant-turn-body .assistant-bubble { max-width: 100%; }
.assistant-bubble.is-markdown { white-space: normal; }
.assistant-bubble.is-markdown > :first-child { margin-top: 0; }
.assistant-bubble.is-markdown > :last-child { margin-bottom: 0; }
.assistant-bubble.is-markdown p { margin: 0 0 8px; }
.assistant-bubble.is-markdown h4 { font-size: 13px; margin: 9px 0 4px; }
.assistant-bubble.is-markdown ul,
.assistant-bubble.is-markdown ol { margin: 5px 0 8px; padding-left: 20px; }
.assistant-bubble.is-markdown li { margin: 2px 0; }
.assistant-bubble.is-markdown li::marker { color: var(--text-faint); }
.assistant-bubble.is-markdown code {
  padding: 1px 4px; border-radius: 4px; background: var(--surface-3);
  font-family: var(--mono); font-size: 11.5px;
}
.assistant-bubble.is-markdown pre {
  margin: 6px 0 8px; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); overflow-x: auto;
}
.assistant-bubble.is-markdown pre code { padding: 0; background: transparent; white-space: pre; }
.assistant-bubble.is-markdown .assistant-table-wrap { max-width: 100%; margin: 6px 0 8px; overflow-x: auto; }
.assistant-bubble.is-markdown table { border-collapse: collapse; width: 100%; font-size: 12px; }
.assistant-bubble.is-markdown th,
.assistant-bubble.is-markdown td {
  padding: 5px 8px; border: 1px solid var(--border); text-align: left;
  vertical-align: top; overflow-wrap: anywhere;
}
.assistant-bubble.is-markdown th { background: var(--surface-3); font-weight: 600; white-space: nowrap; }
.assistant-bubble.is-markdown blockquote {
  margin: 6px 0; padding: 2px 0 2px 10px; border-left: 2px solid var(--border-strong);
  color: var(--text-dim);
}
.assistant-bubble.is-markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.assistant-bubble.is-markdown strong { font-weight: 650; }
.assistant-bubble.is-markdown hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }

.assistant-trace { display: flex; flex-direction: column; gap: 3px; max-width: 100%; padding-left: 14px; }
.assistant-trace-standalone { padding-left: 50px; }
.assistant-trace-line { color: var(--text-faint); font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.assistant-trace-line code {
  padding: 1px 4px; border-radius: 4px; background: var(--surface-2);
  color: var(--text-dim); font-family: var(--mono); font-size: 10.5px;
}
.assistant-trace-error { color: var(--danger); }
.assistant-thinking { display: inline-flex; align-items: center; gap: 6px; color: var(--text-faint); font-size: 11px; }
.assistant-spinner {
  width: 11px; height: 11px; border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%;
  animation: assistant-spin .7s linear infinite;
}
.assistant-live-error {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 0; color: var(--danger); font-size: 12px;
}
.assistant-retry {
  border: 1px solid var(--danger);
  border-radius: 999px;
  background: transparent;
  color: var(--danger);
  padding: 2px 9px;
  font-size: 10.5px;
  font-weight: 650;
  cursor: pointer;
}
.assistant-retry:hover { background: var(--danger-soft); }
.assistant-retry:disabled { opacity: .55; cursor: default; }
@keyframes assistant-spin { to { transform: rotate(360deg); } }
@keyframes assistant-caret { 50% { opacity: 0; } }

.ai-action {
  width: min(100%, 560px); padding: 11px 13px;
  border: 1px solid var(--border); border-left: 3px solid var(--border-strong);
  border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-sm);
}
.ai-action-pending { border-left-color: var(--warn); }
.ai-action-approved { border-left-color: var(--success); }
.ai-action-declined { border-left-color: var(--text-faint); }
.ai-action-failed { border-left-color: var(--danger); }
.ai-action-head, .ai-action-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ai-action-head { flex-wrap: wrap; }
.ai-action-title { font-size: 13px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.ai-action-head .badge, .ai-action-line .badge { flex: none; height: 20px; padding: 0 7px; font-size: 10.5px; }
.ai-action-summary { margin-top: 4px; color: var(--text-dim); font-size: 12px; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-action-rows {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px; margin: 10px 0 0; padding: 0; font-size: 12px;
}
.ai-action-rows > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ai-action-rows dt { color: var(--text-faint); font-size: 10.5px; font-weight: 500; letter-spacing: .01em; }
.ai-action-rows dd { margin: 0; min-width: 0; color: var(--text); overflow-wrap: anywhere; }
.ai-action-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 11px; padding-top: 9px; border-top: 1px solid var(--border);
}
.ai-action-actions form { margin: 0; }
.ai-action-collapsed { padding: 9px 12px; background: color-mix(in srgb, var(--surface) 82%, var(--surface-2)); }
.ai-action-collapsed .ai-action-title { flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-action-result {
  flex: 1 1 auto; min-width: 0; color: var(--text-dim); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-action-link {
  display: inline-flex; align-items: center; flex: none; gap: 4px; margin-left: auto;
  color: var(--text-dim); font-size: 11.5px; font-weight: 500;
}
.ai-action-link:hover { color: var(--accent); }
.ai-action-error { margin-top: 7px; color: var(--danger); font-size: 11.5px; }
.ai-action-details { margin-top: 7px; }
.ai-action-details > summary {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-faint); font-size: 10.5px; list-style: none; cursor: pointer;
}
.ai-action-details > summary::-webkit-details-marker { display: none; }
.ai-action-details > summary::before { content: "›"; font-size: 12px; line-height: 1; transition: transform .12s; }
.ai-action-details[open] > summary::before { transform: rotate(90deg); }
.ai-action-details > summary:hover { color: var(--text-dim); }
.ai-action-details .ai-action-rows { margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }

.assistant-approval {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 14px 12px; border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--warn-soft) 45%, var(--surface));
  max-height: 44vh; overflow-y: auto;
}
.assistant-approval-head {
  display: flex; align-items: center; gap: 6px; color: var(--warn);
  font-size: 10.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
}
.assistant-approval-list { display: flex; flex-direction: column; gap: 8px; }
.assistant-approval .ai-action {
  width: 100%; max-width: none; box-shadow: none; background: var(--surface);
}
.assistant-approval .ai-action-head .badge { display: none; }
.assistant-approval .ai-action-summary { white-space: normal; }
.assistant-approval .ai-action-actions { margin-top: 9px; padding-top: 8px; }
.assistant-composer {
  display: flex; flex-direction: column; gap: 8px; padding: 11px 14px;
  flex: none; border-top: 1px solid var(--border); background: var(--surface);
}
.assistant-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.assistant-composer-row textarea {
  flex: 1 1 auto; min-height: 40px; max-height: 150px; resize: none;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); font-size: 13px; line-height: 1.45;
}
.assistant-composer-row textarea:focus { outline: none; border-color: var(--accent); }
.assistant-composer .btn { height: 40px; }
.assistant-composer-row .assistant-send {
  width: 40px; min-width: 40px; padding: 0; display: grid; place-items: center;
}
.assistant-composer-row .assistant-send .icon { margin: 0; }
.assistant-composer.is-streaming textarea { opacity: .65; }
.btn.is-busy { position: relative; }
.btn.is-busy > * { opacity: 0; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: assistant-spin .7s linear infinite;
}
.btn-primary.is-busy::after { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
.btn.is-working::before {
  content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 6px;
  vertical-align: -1px; border-radius: 50%; border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent); animation: assistant-spin .7s linear infinite;
}
.approval-status {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text-dim); font-size: 10.5px;
}
.approval-status::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: assistant-spin .7s linear infinite;
}
.approval-row.is-busy, .ai-action.is-busy { opacity: .7; }
.approval-row, .ai-action { transition: opacity .15s ease; }
.assistant-attach {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text-dim); cursor: pointer;
}
.assistant-attach:hover { border-color: var(--accent-line); color: var(--text); }
.assistant-attach:disabled { opacity: .55; cursor: not-allowed; }
.assistant-attach-note { margin: 0; color: var(--text-faint); font-size: 10.5px; }
.assistant-attachment-list { display: flex; flex-wrap: wrap; gap: 6px; }
.assistant-attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.assistant-attachment {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 9px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); font-size: 11.5px;
}
.assistant-attachment span {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.assistant-attachment small { color: var(--text-faint); font-size: 10px; white-space: nowrap; }
.assistant-attachment.is-draft { background: var(--surface); }
.assistant-attachment-remove {
  border: 0; padding: 0 0 0 2px; background: transparent; color: var(--text-faint);
  font-size: 14px; line-height: 1; cursor: pointer;
}
.assistant-attachment-remove:hover { color: var(--text); }
.assistant-user-stack {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  max-width: min(78%, 620px);
}
.assistant-user-stack .assistant-bubble { max-width: 100%; }
.assistant-note { padding: 0 16px 12px; color: var(--text-faint); font-size: 10.5px; }
.assistant-readonly { padding: 16px; color: var(--text-dim); font-size: 12.5px; border-top: 1px solid var(--border); }

@media (max-width: 900px) {
  .assistant-layout {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    height: calc(100vh - 170px); min-height: 520px; gap: 6px;
  }
  .chat-sidebar { flex-direction: row; align-items: center; min-height: 44px; }
  .chat-new { flex: none; margin: 5px; padding: 6px 9px; white-space: nowrap; }
  .chat-list {
    flex-direction: row; align-items: center; gap: 3px; padding: 5px;
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
  }
  .chat-item { flex: none; max-width: 150px; padding: 5px 8px; }
  .chat-item-row { flex: 0 0 auto; }
  .chat-delete { width: 26px; }
  .chat-delete-button { opacity: 1; transform: none; }
  .chat-item-date { display: none; }
  .chat-sidebar-foot { flex: none; margin: 0; padding: 5px; border-top: 0; border-left: 1px solid var(--border); }
  .chat-sidebar-foot .btn { width: auto; padding: 0 8px; white-space: nowrap; }
  .assistant-log { padding: 14px; }
  .assistant-composer-row textarea { font-size: 16px; }
  .assistant-model-select { font-size: 16px; max-width: 190px; }
}
@media (max-width: 640px) {
  .ai-connect { margin-top: 20px; padding: 24px 20px; }
  .assistant-layout { height: calc(100vh - 150px); min-height: 420px; }
  .assistant-log { padding: 10px 10px 12px; gap: 10px; }
  .assistant-bubble { max-width: 88%; font-size: 13.5px; line-height: 1.5; }
  .assistant-turn-body { max-width: calc(100% - 34px); }
  .assistant-user-stack { max-width: 88%; }
  .assistant-approval { padding: 6px 8px 8px; }
  .assistant-approval .ai-action-rows { grid-template-columns: minmax(0, 1fr); }
  .assistant-composer { padding: 8px 10px; gap: 6px; }
  .assistant-composer-row { gap: 6px; }
  .assistant-composer-row textarea {
    min-height: 40px; max-height: 110px; padding: 8px 10px; font-size: 16px;
  }
  .assistant-composer .btn,
  .assistant-composer-row .assistant-send,
  .assistant-attach { height: 42px; }
  .assistant-composer-row .assistant-send { width: 42px; min-width: 42px; }
  .assistant-attach { width: 42px; }
  .chat-new { margin: 4px; padding: 5px 8px; }
  .chat-item { max-width: 120px; }
  .chat-sidebar-foot .btn { padding: 0 7px; }
  .chat-sidebar-foot .chat-foot-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .assistant-spinner, .assistant-bubble.is-streaming::after { animation-duration: 2s; }
  .chat-delete, .chat-delete-button { transition: none; }
}

/* Integrations */
.integration-mark {
  flex: none; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: color-mix(in srgb, #95bf47 16%, var(--surface));
  border: 1px solid color-mix(in srgb, #95bf47 28%, var(--border));
  color: #7cb342;
}
.integration-head-action { margin-left: auto; }
.integration-intro { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.integration-points {
  display: flex; flex-direction: column; gap: 8px;
  margin: 12px 0; padding: 0; list-style: none;
}
.integration-points li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.integration-points .badge { min-width: 68px; justify-content: center; }
.integration-help { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.integration-help summary { cursor: pointer; font-size: 12px; color: var(--text-dim); }
.integration-help summary:hover { color: var(--text); }
.integration-steps {
  display: flex; flex-direction: column; gap: 6px;
  margin: 10px 0; padding-left: 18px; font-size: 12px; color: var(--text-dim);
}
.integration-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden; margin: 16px 0;
}
.integration-stats .stat { padding: 13px 15px; }
.integration-stat-value { font-size: 15px; line-height: 1.35; letter-spacing: -0.01em; }
.integration-alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--warn) 32%, var(--border));
  border-radius: var(--radius); background: var(--warn-soft);
  font-size: 12.5px; color: var(--text-dim);
}
.integration-alert .icon { flex: none; margin-top: 1px; color: var(--warn); }
.integration-alert strong { color: var(--text); font-weight: 600; }
.integration-alert p { margin-top: 2px; }
.integration-toggles { display: flex; flex-direction: column; gap: 9px; }
.integration-connection {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border);
}
.integration-connection-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.integration-shop { font-size: 13px; font-weight: 550; }
.integration-review-actions { justify-content: flex-end; gap: 4px; flex-wrap: nowrap; }
.integration-history { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.integration-history summary { cursor: pointer; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.integration-history summary:hover { color: var(--text); }
.integration-history .table-wrap { border: 1px solid var(--border); border-radius: var(--radius); }
.integration-panel .form-section h3 { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.integration-panel .form-section-head { margin-bottom: 10px; }
.integration-panel .form-section-head p { margin-top: 2px; }
.integration-panel code {
  font-family: var(--mono); font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--border); border-radius: 4px; background: var(--surface);
}
@media (max-width: 720px) {
  .integration-stats { grid-template-columns: minmax(0, 1fr); }
  .integration-stats .stat { border-right: 0; border-bottom: 1px solid var(--border); }
  .integration-stats .stat:last-child { border-bottom: 0; }
  .integration-head-action { margin-left: 0; }
  .integration-review-actions { justify-content: flex-start; }
}
.integration-panel .form-section-head > a {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.integration-reconnect {
  display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 10px;
}
.integration-reconnect .field { flex: 1 1 220px; margin: 0; }
.integration-reconnect .btn { flex: none; }

/* Integrations page */
.integration-page-intro { max-width: 820px; margin: -4px 0 2px; }
.integration-panel-title { display: flex; align-items: center; gap: 8px; }
.integration-panel-title .integration-mark {
  width: 28px; height: 28px; border-radius: 9px;
}
.integration-mark.is-shopify {
  background: color-mix(in srgb, #95bf47 16%, var(--surface));
  border-color: color-mix(in srgb, #95bf47 28%, var(--border));
  color: #7cb342;
}
.integration-caveat {
  display: flex; gap: 6px; align-items: flex-start;
  margin: 12px 0 14px; max-width: 820px;
}
.integration-caveat .icon { flex: none; margin-top: 1px; }
.integration-panel-head { flex-wrap: wrap; }
.integration-tagline { margin: 0 0 2px; }

/* Assistant auto-approval window */
.auto-rule-dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: min(82vh, 640px);
  padding: 0; border-radius: 16px; overflow: hidden;
}
.auto-rule-dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 20px 20px 10px;
}
.auto-rule-dialog-head h2 { margin: 0 0 4px; font-size: 17px; }
.auto-rule-dialog-head p { margin: 0; max-width: 340px; }
.auto-rule-dialog-body { padding: 2px 20px 14px; max-height: min(48vh, 380px); overflow: auto; }
.auto-rule-list { display: flex; flex-direction: column; gap: 6px; }
.auto-rule-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.auto-rule-item-label { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 550; overflow-wrap: anywhere; }
.auto-rule-item .btn { flex: none; height: 26px; padding: 0 8px; font-size: 11px; }
.auto-rule-unrestricted {
  margin: 0 0 10px; padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--border));
  border-radius: 10px; background: var(--accent-soft);
  color: var(--text-dim); font-size: 12px; line-height: 1.5;
}
.auto-rule-unrestricted strong { color: var(--text); font-weight: 600; }
.auto-rule-empty { margin: 0; padding: 20px 4px; text-align: center; color: var(--text-faint); font-size: 12px; }
.auto-rule-error { margin: 0; padding: 0 20px 10px; color: var(--danger); font-size: 11.5px; }
.auto-rule-dialog-actions {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px 16px; border-top: 1px solid var(--border);
  background: var(--surface);
}
.auto-rule-dialog-actions .spacer { flex: 1; }
@media (max-width: 640px) {
  .auto-rule-dialog {
    width: calc(100vw - 16px);
    max-height: calc(var(--app-viewport-height, 100dvh) - 16px);
  }
  .auto-rule-dialog-head { padding: 16px 16px 8px; }
  .auto-rule-dialog-head p { max-width: none; }
  .auto-rule-dialog-body { padding: 2px 16px 12px; max-height: min(46vh, 340px); }
  .auto-rule-error { padding-left: 16px; padding-right: 16px; }
  .auto-rule-dialog-actions { padding: 12px 16px 16px; }
  .auto-rule-dialog-actions .btn { flex: 1; }
}

/* Assistant memory window */
.memory-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(86vh, 820px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  overflow: hidden;
}
.memory-dialog::backdrop { background: rgba(5, 8, 14, .62); backdrop-filter: blur(3px); }
.memory-dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 20px 22px 12px;
}
.memory-dialog-head h2 { margin: 0 0 4px; font-size: 18px; }
.memory-dialog-head p { max-width: 600px; margin: 0; }
.memory-usage { padding: 0 22px 12px; }
.memory-usage-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.memory-meter { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.memory-meter span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, white)); transition: width .2s ease; }
.memory-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 0 22px 14px; border-bottom: 1px solid var(--border); }
.memory-search { flex: 1 1 240px; }
.memory-list { max-height: min(44vh, 420px); overflow: auto; padding: 14px 22px 18px; display: flex; flex-direction: column; gap: 10px; }
.memory-empty { padding: 24px 22px; margin: 0; color: var(--text-faint); text-align: center; }
.memory-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); }
.memory-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.memory-card-title { margin-right: auto; font-size: 14px; }
.memory-card-content { margin: 8px 0 6px; color: var(--text); font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-card-meta { color: var(--text-faint); font-size: 11px; overflow-wrap: anywhere; }
.memory-card-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.memory-form { padding: 18px 22px 20px; border-top: 1px solid var(--border); max-height: 52vh; overflow: auto; }
.memory-form-error { color: var(--danger); font-size: 12px; margin: 8px 0 0; }
@media (max-width: 900px) {
  .memory-dialog input, .memory-dialog select, .memory-dialog textarea { font-size: 16px; }
}
@media (max-width: 640px) {
  .memory-dialog {
    width: 100vw; max-width: 100vw; height: var(--app-viewport-height, 100dvh);
    max-height: none; margin: 0; border: 0; border-radius: 0;
  }
  .memory-dialog[open] { display: flex; flex-direction: column; }
  .memory-dialog-head { flex: none; padding-top: calc(16px + env(safe-area-inset-top)); }
  .memory-usage, .memory-toolbar { flex: none; }
  .memory-list { flex: 1 1 auto; min-height: 0; max-height: none; }
  .memory-form { flex: 0 1 68%; min-height: 0; max-height: none; }
  .memory-dialog.is-editing .memory-usage,
  .memory-dialog.is-editing .memory-toolbar,
  .memory-dialog.is-editing .memory-list,
  .memory-dialog.is-editing .memory-empty { display: none; }
  .memory-dialog.is-editing .memory-form { flex: 1 1 auto; max-height: none; }
  .memory-dialog-head, .memory-usage, .memory-toolbar, .memory-list, .memory-form { padding-left: 16px; padding-right: 16px; }
  .memory-toolbar .btn { width: 100%; }
  .memory-dialog input, .memory-dialog select, .memory-dialog textarea { font-size: 16px; }
}

/* Assistant interrupt + auto-approved chips */
.assistant-queued-badge {
  display: inline-flex; align-items: center; align-self: flex-end;
  margin-bottom: 3px; padding: 2px 8px; border-radius: 999px;
  border: 1px dashed color-mix(in srgb, var(--warn) 55%, var(--border));
  background: var(--warn-soft); color: var(--warn);
  font-size: 10px; font-weight: 600;
}
.assistant-turn-user.is-queued .assistant-bubble {
  opacity: .82; border-style: dashed;
}
.assistant-turn-user.is-interrupt-error .assistant-bubble {
  border-color: var(--danger); color: var(--danger);
}
.assistant-stream-note {
  margin: 0; color: var(--text-faint); font-size: 10.5px; line-height: 1.4;
}
.approval-hint {
  margin: 0 2px 5px; color: var(--text-dim); font-size: 10.5px; line-height: 1.45;
}
.approval-hint-short { display: none; }
.approval-hint strong { color: var(--text); font-weight: 650; }
.approval-always {
  font-size: 10px; letter-spacing: .01em; white-space: nowrap;
  color: var(--accent);
}
.approval-always:hover { color: var(--text); background: var(--accent-soft); }

/* Integration list + configuration dialogs */
.integration-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.integration-row:last-child { border-bottom: 0; }
.integration-row-copy { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.integration-row-copy strong { font-size: 13.5px; font-weight: 600; }
.integration-row-copy span { font-size: 11.5px; color: var(--text-faint); }
.integration-row .integration-mark { width: 36px; height: 36px; border-radius: 10px; }
.integration-dialog { width: min(560px, calc(100vw - 32px)); }
.integration-dialog .dialog-head { display: flex; align-items: center; gap: 10px; }
.integration-dialog .dialog-head h2 { margin: 0; font-size: 15px; flex: 1; }
.integration-dialog .dialog-head .icon-button { margin-left: auto; }
.integration-dialog .dialog-body .form-actions { margin-top: 4px; padding-top: 14px; }
.integration-dialog-meta { margin-bottom: 12px; }
.integration-dialog-actions { margin-bottom: 14px; }
@media (max-width: 560px) {
  .integration-row { flex-wrap: wrap; }
  .integration-row-copy { flex: 1 1 180px; }
  .integration-row .btn { margin-left: auto; }
  .integration-dialog .form-grid { grid-template-columns: minmax(0, 1fr); }
}
.integration-mark.is-stripe {
  background: color-mix(in srgb, #635bff 16%, var(--surface));
  border-color: color-mix(in srgb, #635bff 30%, var(--border));
  color: #8b85ff;
}
.integration-logo {
  flex: none; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  background: #fff; border: 1px solid var(--border); padding: 7px;
}
.integration-dialog .integration-logo { width: 38px; height: 38px; border-radius: 10px; padding: 6px; }
.integration-logo .brand-logo,
.integration-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.integration-logo.is-aws,
.integration-logo:has(img[src$="/aws.svg"]) { padding: 10px 5px; }
.integration-dialog .integration-logo.is-aws { padding: 8px 4px; }
.integration-logo.is-paypal { padding: 8px; }
.integration-dialog .integration-logo.is-paypal { padding: 6px; }
/* Brand logos sit on a light plate so dark wordmarks stay legible in dark mode */
.vendor-logo-preview,
.client-logo-preview,
.vendor-avatar:not(.vendor-avatar-fallback),
.client-avatar:not(.client-avatar-initial),
.integration-logo { background: #fff; }
:root[data-theme="dark"] .vendor-logo-preview,
:root[data-theme="dark"] .client-logo-preview,
:root[data-theme="dark"] .vendor-avatar:not(.vendor-avatar-fallback),
:root[data-theme="dark"] .client-avatar:not(.client-avatar-initial),
:root[data-theme="dark"] .integration-logo { background: #fff; }

/* Dense approval queue. The list scrolls inside a capped bar so the action
   footer stays next to the composer instead of creeping up the screen as more
   approvals are added. */
.assistant-approval {
  /* Never let the outer flex layout squeeze the queue below its footer:
     the chat log should give up height first, otherwise Approve/Decline can be
     clipped behind the composer on short screens. */
  flex: 0 0 auto; min-width: 0; min-height: 0;
  padding: 8px 10px 10px; max-height: min(42vh, 380px); gap: 4px;
  overflow: hidden;
  position: relative; z-index: 4;
  background: color-mix(in srgb, var(--warn-soft) 38%, var(--surface));
}
@media (max-width: 900px) {
  /* visualViewport height, not 100vh: the keyboard shrinks the first, and the
     queue must give space back to the composer when it opens. */
  .assistant-approval { max-height: min(calc(var(--app-viewport-height, 100dvh) * 0.38), 340px); }
}
.approval-bar-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  flex: none; padding: 7px 2px 2px;
  border-top: 1px solid color-mix(in srgb, var(--warn) 18%, var(--border));
  background: color-mix(in srgb, var(--warn-soft) 38%, var(--surface));
  position: sticky; bottom: 0; z-index: 2;
}
.approval-hint { flex: none; }
.approval-bar-head .btn { flex: none; }
.approval-select-all { margin: 0; white-space: nowrap; }
.approval-count {
  min-width: 0; color: var(--text-dim); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.approval-bar-head .spacer { flex: 1 1 auto; }
.assistant-approval-list {
  display: flex; flex-direction: column; gap: 4px;
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-gutter: stable;
  padding-right: 2px;
}
.approval-row {
  display: grid; grid-template-columns: 18px auto minmax(0, 1fr) auto auto;
  align-items: center; gap: 8px; padding: 5px 7px;
  flex: none;
  min-width: 0; max-width: 100%; overflow: hidden;
  border: 1px solid var(--border); border-left: 2px solid var(--warn);
  border-radius: 8px; background: var(--surface);
}
.approval-check { margin: 0; min-height: 0; }
.approval-type { height: 18px; padding: 0 6px; font-size: 10px; white-space: nowrap; }
.approval-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.approval-title { color: var(--text); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.approval-summary { color: var(--text-dim); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.approval-expand { border: 0; background: transparent; color: var(--text-faint); font-size: 10.5px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.approval-expand:hover { color: var(--text); background: var(--surface-2); }
.approval-row-actions {
  display: flex; gap: 1px; flex-wrap: wrap; justify-content: flex-end;
  min-width: 0;
}
.approval-row-actions form { margin: 0; }
.approval-row-actions .btn { min-width: 28px; min-height: 26px; padding: 2px 7px; }
.approval-details { grid-column: 2 / -1; border-top: 1px solid var(--border); margin-top: 2px; padding-top: 6px; }
.approval-detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px 14px; margin: 0; font-size: 11px; }
.approval-detail-grid > div { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.approval-detail-grid dt { color: var(--text-faint); font-size: 10px; }
.approval-detail-grid dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .assistant-approval { max-height: min(calc(var(--app-viewport-height, 100dvh) * 0.31), 280px); }
  .approval-row { grid-template-columns: 18px minmax(0, 1fr) auto; gap: 6px; padding: 6px; }
  .approval-type { display: none; }
  .approval-expand { display: block; grid-column: 3; }
  .approval-row-actions { grid-column: 2 / -1; justify-content: flex-end; }
  .approval-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .approval-hint { margin-bottom: 2px; font-size: 10px; }
  .approval-hint-long { display: none; }
  .approval-hint-short { display: inline; }
  .approval-bar-head { gap: 5px; padding-top: 6px; flex-wrap: nowrap; }
  .approval-bar-head .spacer { display: none; }
  .approval-select-label { display: none; }
  .approval-select-all { min-height: 24px; }
  .approval-count {
    flex: 1 1 auto; min-width: 0; white-space: nowrap; font-size: 10.5px;
    overflow: hidden; text-overflow: ellipsis;
  }
  .approval-bar-head .btn { flex: 0 0 auto; min-height: 32px; padding: 0 9px; font-size: 11.5px; }
  .approval-bar-head:has([data-approval-status]:not([hidden])) .approval-count { display: none; }
  .approval-status { flex: 1 1 auto; }
  .approval-row-actions .btn { min-height: 30px; padding: 2px 8px; }
}

/* Assistant page owns the viewport; only chats/log/approvals scroll.
   Mobile browsers resize the visible viewport when the keyboard opens; app.js
   mirrors visualViewport into --app-viewport-height so the composer never ends
   up underneath it. 100dvh is the no-JS fallback. */
body.assistant-page {
  height: 100vh;
  height: 100dvh;
  height: var(--app-viewport-height, 100dvh);
  overflow: hidden;
}
body.assistant-page .shell {
  height: calc(100vh - var(--header));
  height: calc(100dvh - var(--header));
  height: calc(var(--app-viewport-height, 100dvh) - var(--header));
  min-height: 0;
  overflow: hidden;
}
body.assistant-page .content {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
  overflow: hidden;
}
body.assistant-page .page-head { flex: 0 0 auto; }
body.assistant-page .flash-stack { flex: 0 0 auto; }
body.assistant-page .assistant-layout {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}
@media (max-width: 900px) {
  body.assistant-page .content { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  body.assistant-page .assistant-layout { height: auto; min-height: 0; }
  body.assistant-page .toast-host {
    top: calc(var(--header) + 8px); bottom: auto; left: 12px; right: 12px;
    align-items: stretch;
  }
  body.assistant-page .toast { max-width: none; }
  /* The keyboard is open: the chat gets the space, not the page chrome. */
  body.assistant-page.keyboard-open .page-head,
  body.assistant-page.keyboard-open .chat-sidebar { display: none; }
  /* Keep only the approval footer while typing so the composer can never be
     pushed off the bottom. Close the keyboard to review the cards. */
  body.assistant-page.keyboard-open .assistant-approval { max-height: 60px; }
  body.assistant-page.keyboard-open .assistant-approval-list,
  body.assistant-page.keyboard-open .approval-hint { display: none; }
  body.assistant-page.keyboard-open .assistant-layout {
    grid-template-rows: minmax(0, 1fr); gap: 0;
  }
}
@media (max-width: 640px) {
  body.assistant-page .content { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  body.assistant-page .page-head {
    flex-wrap: nowrap; align-items: center; gap: 8px; margin-bottom: 8px;
  }
  body.assistant-page .page-heading { flex: 0 1 auto; min-width: 0; }
  body.assistant-page .page-heading h1 { font-size: 17px; line-height: 1.15; }
  body.assistant-page .page-heading p { display: none; }
  body.assistant-page .assistant-subtitle { margin-top: 2px; gap: 0; flex-wrap: nowrap; }
  body.assistant-page .auto-rule-manage {
    height: 20px; padding: 0 7px; gap: 4px; font-size: 10px;
  }
  body.assistant-page .auto-rule-manage-label { display: none; }
  body.assistant-page .auto-rule-manage-mobile { display: inline; }
  body.assistant-page .page-actions {
    flex: 1 1 auto; width: auto; justify-content: flex-end; flex-wrap: nowrap; gap: 6px;
  }
  body.assistant-page .assistant-model-select { height: 34px; max-width: 126px; font-size: 16px; }
  body.assistant-page .page-actions .btn { height: 34px; padding: 0 9px; }
}
@media (max-width: 380px) {
  body.assistant-page .page-actions { justify-content: flex-end; gap: 4px; }
  body.assistant-page .assistant-model-select { max-width: 98px; }
  body.assistant-page .page-actions .btn { padding: 0 8px; }
}
/* Landscape phones and other very short viewports: give the conversation the
   window, keep the composer. */
@media (max-width: 900px) and (max-height: 520px) {
  body.assistant-page .page-head,
  body.assistant-page .chat-sidebar { display: none; }
  body.assistant-page .assistant-layout {
    gap: 0; grid-template-rows: minmax(0, 1fr);
  }
}
.integration-list-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.integration-list-head h2 { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.integration-list-head span { font-size: 11px; color: var(--text-faint); }

/* Accounting */
.acct-tabs { margin-bottom: 16px; }
.acct-report-tabs { margin-top: -4px; }
.acct-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px; margin-bottom: 18px;
  border: 1px solid var(--info-soft); border-left: 3px solid var(--info);
  border-radius: var(--radius-lg); background: var(--info-soft);
}
.acct-banner > .icon { color: var(--info); flex: none; }
.acct-banner-copy { flex: 1; min-width: 0; }
.acct-banner-copy strong { display: block; font-size: 12.5px; }
.acct-banner form { flex: none; }

.acct-type { font-weight: 550; }
.acct-type-asset { background: var(--info-soft); color: var(--info); }
.acct-type-liability { background: var(--warn-soft); color: var(--warn); }
.acct-type-equity { background: color-mix(in srgb, #9469db 16%, transparent); color: #a37ce2; }
.acct-type-income { background: var(--success-soft); color: var(--success); }
.acct-type-expense { background: var(--surface-2); color: var(--text-dim); }
:root[data-theme="light"] .acct-type-equity { color: #6b3fb0; }

.acct-chart-empty { margin-bottom: 10px; }
.acct-source-notes { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 12px; font-size: 11.5px; }
.acct-source-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.acct-panel-note { margin-top: 11px; line-height: 1.45; font-size: 11px; color: var(--text-faint); }
.acct-health { display: flex; flex-direction: column; gap: 9px; }
.acct-health-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 12.5px; }
.acct-health-row span { color: var(--text-faint); }
.acct-health-row strong { font-variant-numeric: tabular-nums; font-weight: 600; }
.acct-health-foot {
  display: flex; align-items: center; gap: 7px;
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-faint);
}
.acct-health-foot.is-good { color: var(--success); }
.acct-health-foot.is-bad { color: var(--danger); }
.acct-health-foot .icon { flex: none; }
.acct-meta-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 11px; font-size: 11px; color: var(--text-faint);
}
.acct-links { display: flex; flex-direction: column; padding-top: 4px; padding-bottom: 4px; }
.acct-links a {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.acct-links a:last-child { border-bottom: 0; }
.acct-links a:hover { color: var(--accent); }

.acct-journal-lines { min-width: 820px; }
.acct-journal-lines .acct-col-account { min-width: 230px; }
.acct-journal-lines .acct-col-amount { width: 132px; }
.acct-journal-lines td { padding-top: 5px; padding-bottom: 5px; }
.acct-amount-input { text-align: right; font-variant-numeric: tabular-nums; }
.acct-line-remove { width: 46px; text-align: right; }
.acct-journal-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 13px 16px; border-top: 1px solid var(--border);
}
.acct-journal-actions .btn-primary { margin-left: auto; }
.acct-panel-note { display: block; }

.acct-detail-list { display: flex; flex-direction: column; gap: 10px; }
.acct-detail-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 12.5px; }
.acct-detail-list > div > span:first-child { color: var(--text-faint); flex: none; }
.acct-detail-list > div > strong, .acct-detail-list > div > a { text-align: right; }
.acct-detail-ref { margin-top: 8px; }

.acct-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.acct-account-table .is-archived { opacity: .58; }
.acct-empty { margin: 0; }
.acct-report .panel-head h2 { letter-spacing: -0.01em; }
.acct-report-table .acct-section-row td {
  padding-top: 9px; padding-bottom: 9px;
  background: var(--surface-2); color: var(--text-faint);
  font-size: 10.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
}
.acct-report-table .acct-subtotal td { font-weight: 600; border-top: 1px solid var(--border-strong); }
.acct-report-table .acct-total-row td {
  font-size: 14px; font-weight: 650;
  border-top: 2px solid var(--border-strong);
}
.acct-report-table .acct-total-row td:last-child { font-size: 17px; letter-spacing: -0.02em; }
.acct-cash-table .acct-subtotal td:first-child { font-weight: 600; }
.acct-list { display: flex; flex-direction: column; }
.acct-list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.acct-list-row:last-child { border-bottom: 0; }
.acct-list-row > span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.acct-list-row strong { font-size: 12.5px; font-weight: 550; }
.acct-list-row small { font-size: 11px; color: var(--text-faint); }
.acct-list-row:hover strong { color: var(--accent); }

@media (max-width: 700px) {
  .acct-banner { align-items: flex-start; flex-wrap: wrap; }
  .acct-banner form { width: 100%; }
  .acct-banner form .btn { width: 100%; }
  .acct-journal-actions .btn-primary { margin-left: 0; }
  .acct-journal-actions .btn { flex: 1 1 auto; }
}

@media print {
  .sidebar, .app-header, .sidebar-backdrop, .page-actions, .filters,
  .acct-tabs, .acct-report-tabs, .acct-banner, .flash-stack, .pagination,
  .list-footer, .list-sentinel,
  .toast-host { display: none !important; }
  .shell { margin-left: 0; }
  .content { max-width: none; padding: 0; }
  .panel { border: 0; break-inside: avoid; }
  .panel-head { border-bottom: 1px solid #ccc; }
  body { background: #fff; color: #111; }
  .tbl thead th { background: transparent; }
}

/* Receipt paper ----------------------------------------------------------- */

.receipt-paper {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #e0e3e9;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--paper-text);
  box-shadow: var(--shadow-sm);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
}
.receipt-paper.is-compact { padding: 16px; font-size: 10px; }
.receipt-head { text-align: center; }
.receipt-brand { width: 28px; height: 28px; margin: 0 auto 5px; object-fit: contain; }
.receipt-head h3 { margin: 0; color: var(--paper-text); font-family: var(--sans); font-size: 14px; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.receipt-paper.is-compact .receipt-head h3 { font-size: 13px; }
.receipt-sub { margin-top: 3px; color: var(--paper-muted); font-size: 9.5px; }
.receipt-ref { margin-top: 1px; color: var(--paper-muted); font-size: 8.5px; letter-spacing: .05em; text-transform: uppercase; }
.receipt-dot { padding: 0 4px; opacity: .55; }
.receipt-rule { height: 0; margin: 12px 0 8px; border-top: 1px dashed rgba(27, 30, 39, .2); }
.receipt-items { display: flex; flex-direction: column; gap: 1px; }
.receipt-item { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 2px 0; }
.receipt-item-main { min-width: 0; display: flex; flex-direction: column; }
.receipt-item-name { overflow-wrap: anywhere; }
.receipt-item-main small { color: var(--paper-muted); font-size: 8.5px; }
.receipt-item-amount { flex: none; font-variant-numeric: tabular-nums; }
.receipt-item.is-discount { color: #1f7a4d; }
.receipt-empty-line { color: var(--paper-muted); font-size: 9.5px; text-align: center; padding: 4px 0; }
.receipt-totals { display: flex; flex-direction: column; gap: 2px; }
.receipt-totals > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; color: var(--paper-muted); font-size: 10px; }
.receipt-totals > div span:last-child { color: var(--paper-text); font-variant-numeric: tabular-nums; }
.receipt-totals > div.is-discount span:last-child { color: #1f7a4d; }
.receipt-grand { margin-top: 4px; padding-top: 6px; border-top: 2px solid var(--paper-text); color: var(--paper-text) !important; font-size: 12px !important; font-weight: 600; }
.receipt-grand span:last-child { font-size: 14px !important; }
.receipt-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 11px; padding-top: 7px; border-top: 1px dashed rgba(27, 30, 39, .2); color: var(--paper-muted); font-size: 8.5px; }

.expense-receipt-panel { max-width: 900px; margin-top: 18px; }
.expense-receipt-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; padding: 16px; }
.expense-receipt-photo { display: grid; place-items: center; min-height: 220px; max-height: 480px; padding: 8px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: #0a0d13; }
.expense-receipt-photo img { max-width: 100%; max-height: 460px; object-fit: contain; }

/* Responsive -------------------------------------------------------------- */

@media (max-width: 900px) {
  .expense-receipt-layout { grid-template-columns: minmax(0, 1fr); }
  .expense-receipt-photo { max-height: 400px; }
}

@media (max-width: 640px) {
  .receipt-paper { max-width: 100%; }
  .expense-receipt-layout { padding: 12px; }
}

/* ==========================================================================
   Receipt scanner
   ========================================================================== */

.scanner-file-input { display: none !important; }

.scanner-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
  max-width: 1120px;
}
.scanner-shell.scanner-shell-single { grid-template-columns: minmax(0, 1fr); max-width: 760px; }
.scanner-shell-single .scanner-stage { max-height: 460px; }

.scanner-panel { overflow: hidden; }
.scanner-panel .panel-head { align-items: center; }
.scanner-mode-badge { margin-left: auto; }
.scanner-panel-body { padding: 16px; }

.scanner-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 520px;
  min-height: 260px;
  border: 1px solid #262b38;
  border-radius: var(--radius-lg);
  background: #06080c;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.scanner-stage.is-locked { border-color: color-mix(in srgb, var(--success) 65%, #262b38); }
.scanner-stage.is-dropping { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.scanner-stage.is-dropping::after {
  content: "Drop the receipt photo";
  position: absolute; inset: 8px; z-index: 14;
  display: grid; place-items: center;
  border: 1px dashed rgba(255, 255, 255, .4); border-radius: 6px;
  background: rgba(6, 8, 12, .6);
  color: #fff; font-size: 13px; font-weight: 550;
}

.scanner-grid {
  position: absolute; inset: 0; z-index: 0;
  background-image: radial-gradient(circle, rgba(255, 255, 255, .055) 1px, transparent 1.2px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at 50% 48%, black, transparent 80%);
  -webkit-mask-image: radial-gradient(circle at 50% 48%, black, transparent 80%);
}
.scanner-video { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: contain; background: #05070b; }
.scanner-frame { position: absolute; z-index: 2; overflow: hidden; background: #05070b; }
.scanner-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-frame .scanner-frame-enhanced { z-index: 0; }
.scanner-frame .scanner-frame-photo { z-index: 1; }
.scanner-overlay { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; }

.scanner-scanline {
  position: absolute; left: 8%; right: 8%; top: 18%; z-index: 3;
  height: 1px; opacity: 0;
  background: linear-gradient(90deg, transparent, rgba(143, 140, 244, .7), transparent);
  pointer-events: none;
}
.scanner-stage[data-state="camera"] .scanner-scanline { opacity: .55; animation: scanner-sweep 3.2s ease-in-out infinite; }
.scanner-stage.is-locked .scanner-scanline { opacity: 0; animation: none; }
@keyframes scanner-sweep {
  0% { top: 14%; opacity: 0; }
  15% { opacity: .55; }
  85% { opacity: .2; }
  100% { top: 84%; opacity: 0; }
}

.scanner-hud {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 9;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  pointer-events: none;
}
.scanner-status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 26px; padding: 0 9px;
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 999px;
  background: rgba(7, 9, 14, .65);
  color: #f2f4f8; font-size: 11px;
}
.scanner-pulse { width: 6px; height: 6px; flex: none; border-radius: 50%; background: #7d84a3; }
.scanner-pulse.is-searching { background: #a5a2ff; animation: scanner-pulse 1.4s ease-in-out infinite; }
.scanner-pulse.is-good { background: var(--warn); animation: scanner-pulse 1.2s ease-in-out infinite; }
.scanner-pulse.is-locked { background: var(--success); }
.scanner-pulse.is-idle { background: #7d84a3; }
@keyframes scanner-pulse { 50% { opacity: .35; } }

.scanner-hud-right { display: inline-flex; align-items: center; gap: 6px; }
.scanner-live-badge { height: 24px; padding: 0 8px; border: 1px solid rgba(255, 255, 255, .12) !important; background: rgba(7, 9, 14, .65) !important; color: rgba(255, 255, 255, .72) !important; font-size: 9.5px; }
.scanner-confidence {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 8px 0 4px;
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 999px;
  background: rgba(7, 9, 14, .65);
  color: #f2f4f8; font-size: 10px; font-variant-numeric: tabular-nums;
}
.scanner-confidence-ring {
  --p: 0;
  display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: conic-gradient(var(--success) calc(var(--p) * 1%), rgba(255, 255, 255, .14) 0);
}
.scanner-confidence-ring span { width: 12px; height: 12px; border-radius: 50%; background: #0a0d12; }

.scanner-hint {
  position: absolute; left: 50%; bottom: 12px; z-index: 8;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px;
  max-width: calc(100% - 24px);
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, .1); border-radius: 999px;
  background: rgba(7, 9, 14, .65);
  color: rgba(255, 255, 255, .8); font-size: 10.5px; white-space: nowrap;
}

.scanner-idle {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 7px; padding: 26px 24px; text-align: center;
  background: radial-gradient(circle at 50% 35%, rgba(91, 91, 214, .08), transparent 45%);
  color: #f2f4f8;
}
.scanner-idle-icon {
  display: grid; place-items: center;
  width: 46px; height: 46px; margin-bottom: 3px;
  border: 1px solid rgba(255, 255, 255, .1); border-radius: 10px;
  background: rgba(255, 255, 255, .055); color: rgba(255, 255, 255, .78);
}
.scanner-idle h3 { color: #fff; font-size: 15px; font-weight: 600; letter-spacing: -.015em; }
.scanner-idle p { max-width: 320px; color: rgba(227, 232, 242, .58); font-size: 11.5px; line-height: 1.5; }
.scanner-idle .btn-row { margin-top: 8px; }
.scanner-idle-note { display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; color: rgba(227, 232, 242, .36); font-size: 10px; }

.scanner-analysis { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: rgba(5, 7, 11, .72); }
.scanner-analysis-card {
  width: min(400px, 100%); padding: 18px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
.scanner-analysis-top { display: flex; align-items: flex-start; gap: 11px; }
.scanner-analysis-copy h3 { font-size: 14px; }
.scanner-analysis-copy p { margin-top: 3px; color: var(--text-dim); font-size: 11.5px; line-height: 1.5; }
.scanner-spinner {
  width: 18px; height: 18px; flex: none; margin-top: 1px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: scanner-spin .8s linear infinite;
}
@keyframes scanner-spin { to { transform: rotate(360deg); } }
.scanner-progress { height: 3px; margin-top: 16px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.scanner-progress span { display: block; width: 8%; height: 100%; border-radius: inherit; background: var(--accent); transition: width .35s ease; }
.scanner-analysis-steps { list-style: none; margin: 13px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scanner-analysis-steps li { display: flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: 11px; }
.scanner-analysis-steps li small { margin-left: auto; font-size: 9px; letter-spacing: .06em; text-transform: uppercase; }
.scanner-step-dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--border-strong); }
.scanner-analysis-steps li.is-active { color: var(--text); }
.scanner-analysis-steps li.is-active .scanner-step-dot { background: var(--accent); }
.scanner-analysis-steps li.is-done { color: var(--text-dim); }
.scanner-analysis-steps li.is-done .scanner-step-dot { background: var(--success); }
.scanner-analysis-retry { margin-top: 14px; }

.scanner-error { position: absolute; inset: 0; z-index: 12; display: grid; place-items: center; padding: 18px; background: rgba(5, 7, 11, .82); }
.scanner-error-card {
  width: min(390px, 100%); padding: 20px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
.scanner-error-icon { display: grid; place-items: center; width: 38px; height: 38px; margin: 0 auto 10px; border-radius: 50%; color: var(--danger); background: var(--danger-soft); }
.scanner-error-card h3 { font-size: 14px; }
.scanner-error-card p { margin: 4px 0 13px; color: var(--text-dim); font-size: 11.5px; line-height: 1.5; }
.scanner-error-card .btn-row { justify-content: center; }

.scanner-flash { position: absolute; inset: 0; z-index: 14; background: #fff; opacity: 0; pointer-events: none; }
.scanner-flash.is-firing { animation: scanner-flash .42s ease-out; }
@keyframes scanner-flash { 0% { opacity: .75; } 100% { opacity: 0; } }

.scanner-controls { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px 0 2px; }
.scanner-controls[hidden] { display: none; }
.scanner-shutter {
  position: relative; display: grid; place-items: center;
  width: 54px; height: 54px; padding: 0; border-radius: 50%;
  border: 2px solid var(--border-strong); background: transparent;
  cursor: pointer; transition: border-color .15s ease;
}
.scanner-shutter:hover { border-color: var(--text-faint); }
.scanner-shutter:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.scanner-shutter-core { width: 42px; height: 42px; border-radius: 50%; background: var(--text); transition: background .15s ease; }
.scanner-stage.is-locked ~ .scanner-panel-body .scanner-shutter,
.scanner-stage.is-locked + .scanner-controls .scanner-shutter { border-color: var(--success); }
.scanner-stage.is-locked + .scanner-controls .scanner-shutter-core { background: var(--success); }
.scanner-side-button {
  display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-dim);
  cursor: pointer;
}
.scanner-side-button:hover { background: var(--surface-3); color: var(--text); }
.scanner-side-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.scanner-side-button.is-active { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, var(--border)); }
.scanner-dropnote { margin-top: 7px; color: var(--text-faint); font-size: 10.5px; text-align: center; }
.scanner-inline-link { color: var(--text-dim); border-bottom: 1px dashed var(--border-strong); cursor: pointer; }
.scanner-inline-link:hover { color: var(--text); }

.scanner-aside { position: sticky; top: 82px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.scanner-tips-body { padding: 14px 16px; }
.scanner-tips-list { margin: 0; padding-left: 16px; color: var(--text-dim); font-size: 11.5px; line-height: 1.6; }
.scanner-tips-list li + li { margin-top: 3px; }
.scanner-auto { margin-top: 12px; align-items: flex-start; line-height: 1.4; }
.scanner-auto input { margin-top: 1px; }
.scanner-live-body { padding: 13px 16px; }
.scanner-metric + .scanner-metric { margin-top: 11px; }
.scanner-metric-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--text-dim); font-size: 10.5px; }
.scanner-metric-row strong { color: var(--text); font-size: 10.5px; font-weight: 550; font-variant-numeric: tabular-nums; }
.scanner-meter { height: 3px; margin-top: 4px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.scanner-meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.scanner-note { display: flex; align-items: flex-start; gap: 8px; color: var(--text-faint); font-size: 10.5px; line-height: 1.5; padding: 0 2px; }
.scanner-note .icon { flex: none; margin-top: 1px; }
.scanner-noscript { max-width: 560px; margin-top: 16px; }
.scanner-noscript h2 { font-size: 14px; }
.scanner-noscript p { margin: 6px 0 12px; font-size: 12px; }
.scanner-noscript input[type="file"] { margin-bottom: 10px; }

/* Review ------------------------------------------------------------------ */

.scan-review {
  display: grid;
  grid-template-columns: minmax(290px, 350px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  max-width: 1120px;
}
.scan-review-preview { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.scan-image-panel { overflow: hidden; }
.scan-image-panel .panel-head { align-items: center; }
.scan-image-tabs { margin: 0; padding: 0 14px; }
.scan-image-tabs .tab {
  height: 34px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent;
  background: transparent; font: inherit; font-size: 12px; cursor: pointer;
}
.scan-image-tabs .tab + .tab { margin-left: 14px; }
.scan-image-tabs .tab.is-active { border-bottom-color: var(--accent); }
.scan-image-frame { display: grid; place-items: center; height: 300px; overflow: hidden; background: #0a0d13; }
.scan-preview { display: grid; place-items: center; min-height: 220px; max-height: 420px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.scan-preview img { display: block; max-width: 100%; max-height: 420px; object-fit: contain; }
.scan-preview-empty { gap: 6px; color: var(--text-faint); font-size: 11.5px; }
.scan-image-frame img { max-width: 100%; max-height: 300px; object-fit: contain; }
.scan-image-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: rgba(255, 255, 255, .42); font-size: 11px; }
.scan-image-caption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--text-faint); font-size: 10px; }
.scan-paper-panel .panel-body { padding: 16px; }
.scan-warning-list { margin: 0; }
.scan-read-details { margin: 0; display: flex; flex-direction: column; }
.scan-read-details > div { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.scan-read-details > div:first-child { padding-top: 0; }
.scan-read-details > div:last-child { padding-bottom: 0; border-bottom: 0; }
.scan-read-details dt { color: var(--text-faint); font-size: 10.5px; }
.scan-read-details dd { margin: 0; color: var(--text-dim); font-size: 11px; overflow-wrap: anywhere; }
.scan-raw { overflow: hidden; }
.scan-raw summary { display: flex; align-items: center; gap: 7px; padding: 10px 14px; color: var(--text-dim); font-size: 11px; cursor: pointer; list-style: none; }
.scan-raw summary::-webkit-details-marker { display: none; }
.scan-raw summary::after { content: "+"; margin-left: auto; color: var(--text-faint); }
.scan-raw[open] summary::after { content: "−"; }
.scan-raw pre { max-height: 260px; margin: 0; padding: 0 14px 12px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-faint); font: 10px/1.55 var(--mono); }

.scan-review-form { overflow: hidden; }
.scan-review-form > .panel-head { align-items: center; gap: 10px; }
.scan-review-form > .panel-head .badge { margin-left: auto; }
.scan-summary-line { display: flex; align-items: center; gap: 7px; margin-bottom: 16px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text-dim); font-size: 11.5px; }
.scan-summary-line .icon { color: var(--success); flex: none; }
.scan-field-source { max-width: 48%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase; }
.scan-input-with-logo { position: relative; display: flex; align-items: center; gap: 7px; }
.scan-input-with-logo input { flex: 1; min-width: 0; }
.scan-vendor-logo { width: 24px; height: 24px; flex: none; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); padding: 3px; }
.scan-suggestions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.scan-suggestion { height: 23px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text-dim); font: inherit; font-size: 10px; cursor: pointer; }
.scan-suggestion:hover { background: var(--surface-3); color: var(--text); }
.scan-suggestion.is-active { border-color: var(--accent-line); background: var(--accent-soft); color: var(--text); }
.scan-document-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.scan-doc-choice { position: relative; display: block; cursor: pointer; }
.scan-doc-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scan-doc-choice-body { display: flex; align-items: center; gap: 8px; min-height: 60px; padding: 7px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); transition: border-color .13s, background .13s; }
.scan-doc-choice-body img { width: 42px; height: 42px; flex: none; object-fit: cover; border: 1px solid var(--border); border-radius: 4px; background: #0a0d13; }
.scan-doc-choice-body > span:nth-child(2) { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.scan-doc-choice-body strong { font-size: 10.5px; font-weight: 550; }
.scan-doc-choice-body small { color: var(--text-faint); font-size: 9.5px; line-height: 1.35; }
.scan-doc-check { display: none; margin-left: auto; flex: none; width: 17px; height: 17px; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); }
.scan-doc-choice input:checked + .scan-doc-choice-body { border-color: var(--accent-line); background: var(--accent-soft); }
.scan-doc-choice input:checked + .scan-doc-choice-body .scan-doc-check { display: grid; }
.scan-doc-choice input:focus-visible + .scan-doc-choice-body { outline: 2px solid var(--focus); outline-offset: 2px; }
.scan-advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.scan-advanced > summary { display: flex; align-items: center; gap: 7px; color: var(--text-dim); font-size: 11.5px; font-weight: 550; cursor: pointer; list-style: none; }
.scan-advanced > summary::-webkit-details-marker { display: none; }
.scan-advanced > summary span { margin-left: auto; color: var(--text-faint); font-size: 10px; font-weight: 400; }
.scan-advanced[open] > summary { margin-bottom: 13px; }
.scan-review-actions { padding: 13px 16px; margin: 0; }
.scan-save-button { min-width: 138px; }

/* Receipt paper ----------------------------------------------------------- */

.receipt-paper {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #e0e3e9;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--paper-text);
  box-shadow: var(--shadow-sm);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
}
.receipt-paper.is-compact { padding: 16px; font-size: 10px; }
.receipt-head { text-align: center; }
.receipt-brand { width: 28px; height: 28px; margin: 0 auto 5px; object-fit: contain; }
.receipt-head h3 { margin: 0; color: var(--paper-text); font-family: var(--sans); font-size: 14px; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.receipt-paper.is-compact .receipt-head h3 { font-size: 13px; }
.receipt-sub { margin-top: 3px; color: var(--paper-muted); font-size: 9.5px; }
.receipt-ref { margin-top: 1px; color: var(--paper-muted); font-size: 8.5px; letter-spacing: .05em; text-transform: uppercase; }
.receipt-dot { padding: 0 4px; opacity: .55; }
.receipt-rule { height: 0; margin: 12px 0 8px; border-top: 1px dashed rgba(27, 30, 39, .2); }
.receipt-items { display: flex; flex-direction: column; gap: 1px; }
.receipt-item { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 2px 0; }
.receipt-item-main { min-width: 0; display: flex; flex-direction: column; }
.receipt-item-name { overflow-wrap: anywhere; }
.receipt-item-main small { color: var(--paper-muted); font-size: 8.5px; }
.receipt-item-amount { flex: none; font-variant-numeric: tabular-nums; }
.receipt-item.is-discount { color: #1f7a4d; }
.receipt-empty-line { color: var(--paper-muted); font-size: 9.5px; text-align: center; padding: 4px 0; }
.receipt-totals { display: flex; flex-direction: column; gap: 2px; }
.receipt-totals > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; color: var(--paper-muted); font-size: 10px; }
.receipt-totals > div span:last-child { color: var(--paper-text); font-variant-numeric: tabular-nums; }
.receipt-totals > div.is-discount span:last-child { color: #1f7a4d; }
.receipt-grand { margin-top: 4px; padding-top: 6px; border-top: 2px solid var(--paper-text); color: var(--paper-text) !important; font-size: 12px !important; font-weight: 600; }
.receipt-grand span:last-child { font-size: 14px !important; }
.receipt-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 11px; padding-top: 7px; border-top: 1px dashed rgba(27, 30, 39, .2); color: var(--paper-muted); font-size: 8.5px; }

.expense-receipt-panel { max-width: 900px; margin-top: 18px; }
.expense-receipt-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; padding: 16px; }
.expense-receipt-photo { display: grid; place-items: center; min-height: 220px; max-height: 480px; padding: 8px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: #0a0d13; }
.expense-receipt-photo img { max-width: 100%; max-height: 460px; object-fit: contain; }

/* Responsive -------------------------------------------------------------- */

@media (max-width: 1100px) {
  .scanner-shell, .scan-review { grid-template-columns: minmax(0, 1fr) 280px; }
  .scanner-aside { padding: 0; }
}

@media (max-width: 900px) {
  .scanner-shell { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .scanner-aside { position: static; }
  .scanner-stage { aspect-ratio: 3 / 4; max-height: 62dvh; }
  .scan-review { display: flex; flex-direction: column; gap: 14px; max-width: 720px; margin: 0 auto; }
  .scan-review-preview { display: contents; }
  .scan-warning-list { order: 1; }
  .scan-paper-panel { order: 2; }
  .scan-review-form { order: 3; }
  .scan-image-panel { order: 4; }
  .scan-details-panel { order: 5; }
  .scan-raw { order: 6; }
  .scan-image-frame { height: 240px; }
  .scan-image-frame img { max-height: 240px; }
  .expense-receipt-layout { grid-template-columns: minmax(0, 1fr); }
  .expense-receipt-photo { max-height: 400px; }
}

@media (max-width: 640px) {
  .scanner-panel-body { padding: 12px; }
  .scanner-stage { min-height: 300px; max-height: 60dvh; }
  .scanner-idle { padding: 20px 16px; }
  .scanner-idle h3 { font-size: 14px; }
  .scanner-idle p { font-size: 11px; }
  .scanner-idle .btn { flex: 1 1 120px; }
  .scanner-analysis-card, .scanner-error-card { padding: 15px; }
  .scanner-controls { gap: 12px; }
  .scanner-dropnote { font-size: 10px; }
  .scan-document-choices { grid-template-columns: minmax(0, 1fr); }
  .scan-review-form input:not([type="radio"]):not([type="checkbox"]),
  .scan-review-form select,
  .scan-review-form textarea { font-size: 16px; }
  .scan-review-actions { padding: 11px 12px; }
  .scan-review-actions .btn-ghost { padding: 0 7px; }
  .scan-save-button { flex: 1; }
  .receipt-paper { max-width: 100%; }
  .expense-receipt-layout { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .scanner-scanline, .scanner-pulse, .scanner-spinner, .scanner-analysis-steps li.is-active .scanner-step-dot { animation: none !important; }
  .scanner-meter span { transition: none; }
}

/* Bank import */
.bank-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 30px 20px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .14s, background .14s;
}
.bank-drop:hover,
.bank-drop.is-dragging,
.bank-drop.has-file { border-color: var(--accent-line); background: var(--accent-soft); }
.bank-drop > .icon { color: var(--accent); margin-bottom: 3px; }
.bank-drop strong { font-size: 13px; font-weight: 600; }
.bank-drop input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.bank-file { display: inline-flex; align-items: center; gap: 5px; margin-top: 5px; padding: 3px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 10.5px; color: var(--text-dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank-drop.has-file .bank-file { border-color: var(--accent-line); color: var(--text); }

.bank-action-summary { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.bank-action-summary > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; }
.bank-action-summary span { color: var(--text-faint); }
.bank-action-summary strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.bank-meta { display: flex; flex-direction: column; gap: 8px; }
.bank-meta > div { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; font-size: 12px; }
.bank-meta span { color: var(--text-faint); flex: none; }
.bank-meta strong { font-weight: 550; text-align: right; overflow-wrap: anywhere; }

.mt-12 { margin-top: 12px; }

/* Quiet status text: no chips, pills or filled badges. */
.badge {
  display: inline;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: inherit;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-dim);
  white-space: normal;
}
.badge-success { color: var(--success); }
.badge-warn, .badge-warning { color: var(--warn); }
.badge-danger { color: var(--danger); }
.badge-info { color: var(--text-dim); }
.badge-muted, .badge-plain { color: var(--text-faint); }

/* Stat cards are separate panels, not a segmented strip. */
.stats {
  gap: 14px;
  border: 0;
  background: none;
  overflow: visible;
}
.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.stat:last-child { border-right: 1px solid var(--border); }
