/* ==========================================================================
   M. Ramlov · Bogføring — design system
   Minimalistisk, skandinavisk: varm off-white flade, sort blæk, hårfine linjer.
   ========================================================================== */

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f7f6f3;
  --surface-3: #eeece7;
  --border: #e6e4de;
  --border-strong: #d2cfc7;

  --ink: #17171a;
  --ink-2: #4a4a50;
  --ink-3: #85858c;
  --ink-4: #b5b5bb;

  --success: #2f6f4e;
  --success-bg: #e7f0ea;
  --warning: #96661c;
  --warning-bg: #f6eedd;
  --danger: #a8392e;
  --danger-bg: #f7e6e3;
  --info: #3b5c7c;
  --info-bg: #e5edf4;

  --focus: rgba(23, 23, 26, 0.16);
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.05);
  --shadow: 0 12px 32px rgba(20, 20, 20, 0.10);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --sidebar-w: 248px;
}

/* --------------------------------------------------------------------------
   Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
a { color: inherit; text-decoration: none; }
a.link { text-decoration: underline; text-decoration-color: var(--ink-4); text-underline-offset: 3px; }
a.link:hover { text-decoration-color: var(--ink); }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
code, .code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; word-break: break-all; }
strong, .strong { font-weight: 600; }
small, .text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--ink-3); }
.text-2 { color: var(--ink-2); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-info { color: var(--info); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.icon { flex-shrink: 0; vertical-align: -0.15em; }
.eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3);
}

/* --------------------------------------------------------------------------
   Layout: sidebar + content
   -------------------------------------------------------------------------- */
.app { min-height: 100vh; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform 0.25s ease;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px 18px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--ink); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.brand > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 3px; }

.nav { padding: 6px 12px; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: transparent transparent; }
.nav:hover { scrollbar-color: var(--border-strong) transparent; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.nav:hover::-webkit-scrollbar-thumb { background: var(--border-strong); }
.nav-group { margin-top: 12px; padding: 0 8px 5px; }
.nav-group:first-child { margin-top: 4px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 7px 10px; margin-bottom: 1px;
  border-radius: 8px;
  color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav a .icon { color: var(--ink-3); }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.is-active { background: var(--surface-3); color: var(--ink); }
.nav a.is-active .icon { color: var(--ink); }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-chip > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-3); color: var(--ink-2);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; text-transform: uppercase;
}
.user-chip .name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .role { font-size: 11px; color: var(--ink-3); }

.topbar {
  display: none;
  position: sticky; top: 0; z-index: 30;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between;
}
.topbar .brand-name { font-size: 14px; }
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(20, 20, 20, 0.35); z-index: 35;
}

.main { margin-left: var(--sidebar-w); padding: 40px 48px 64px; }
.container { max-width: 1240px; margin: 0 auto; }

/* Page header */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
  margin-bottom: 28px; flex-wrap: wrap;
}
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.page-sub { color: var(--ink-3); font-size: 13.5px; margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
.section-title { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   Cards & stats
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.card.is-sticky { position: sticky; top: 24px; }
.card.tone-success { border-color: rgba(47, 111, 78, 0.35); }
.card.tone-warning { border-color: rgba(150, 102, 28, 0.35); }
.card.tone-info { border-color: rgba(59, 92, 124, 0.3); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.stat-success .stat-value { color: var(--success); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }
.stat-info .stat-value { color: var(--info); }
.stat-ink { background: var(--ink); border-color: var(--ink); color: #fff; }
.stat-ink .stat-label { color: rgba(255, 255, 255, 0.6); }
.stat-ink .stat-sub { color: rgba(255, 255, 255, 0.6); }
.stat-ink.is-negative { background: var(--danger); border-color: var(--danger); }
.stat.is-link:hover { border-color: var(--border-strong); }

/* Key-value lists */
.kv { margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv > div:last-child { border-bottom: 0; }
.kv > div.total { font-weight: 600; font-size: 15px; border-top: 1px solid var(--ink); border-bottom: 0; margin-top: 4px; padding-top: 12px; }
.kv dt, .kv .k { color: var(--ink-2); }
.kv dd, .kv .v { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

/* --------------------------------------------------------------------------
   Grid & spacing utilities
   -------------------------------------------------------------------------- */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1fr) 360px; }
.grid-side-left { grid-template-columns: 380px minmax(0, 1fr); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.start { align-items: flex-start; }
.stack > * + * { margin-top: 16px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; } .mt-4 { margin-top: 28px; } .mt-5 { margin-top: 40px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; } .mb-4 { margin-bottom: 28px; }
.ml-auto { margin-left: auto; }
.w-100 { width: 100%; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.flex-1 { flex: 1; min-width: 0; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 13.5px; font-weight: 500; line-height: 1;
  cursor: pointer; white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-4); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn .icon { color: var(--ink-3); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2b2b30; border-color: #2b2b30; }
.btn-primary .icon { color: rgba(255, 255, 255, 0.8); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #275d41; border-color: #275d41; }
.btn-success .icon { color: rgba(255, 255, 255, 0.85); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: transparent; }
.btn-danger .icon { color: var(--danger); }
.btn-outline-danger { border-color: rgba(168, 57, 46, 0.4); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-outline-danger .icon { color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; gap: 6px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 7px; background: transparent; border-color: transparent; }
.btn-icon:hover { background: var(--surface-3); border-color: transparent; }
.btn-icon .icon { color: var(--ink-2); }
.btn-icon.btn-danger .icon { color: var(--danger); }
.btn-icon.btn-danger:hover { background: var(--danger-bg); }
.btn-icon.btn-success-text .icon { color: var(--success); }
.btn-icon.btn-success-text:hover { background: var(--success-bg); }
.btn-block { width: 100%; }
.actions { display: inline-flex; align-items: center; gap: 2px; }
.actions form { display: inline; }

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; letter-spacing: 0.01em; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.badge .icon { width: 12px; height: 12px; }
.badge-neutral { background: var(--surface-3); color: var(--ink-2); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-ink { background: var(--ink); color: #fff; }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--ink-2); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 11px 16px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .sub { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.table td.actions-cell { text-align: right; white-space: nowrap; }
.table tr.is-muted td { color: var(--ink-3); }
.table tr.is-highlight td { background: var(--success-bg); }
.table tr.is-current td { background: var(--warning-bg); }
.table tfoot td { font-weight: 600; border-top: 1px solid var(--ink); border-bottom: 0; background: var(--surface-2); }
.table.compact th { padding: 8px 12px; }
.table.compact td { padding: 9px 12px; }
.table .primary-cell { font-weight: 500; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { margin-bottom: 16px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.label .req { color: var(--danger); margin-left: 2px; }
.input {
  display: block; width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  min-width: 0;
}
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2385858c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
textarea.input { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--focus); }
.input::placeholder { color: var(--ink-4); }
.input[readonly], .input:disabled { background: var(--surface-2); color: var(--ink-2); }
.input-sm { height: 32px; font-size: 13px; padding: 0 10px; border-radius: 7px; }
.input-lg { height: 46px; font-size: 16px; }
.input-auto { width: auto; display: inline-block; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.hint { display: block; font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.input-group { display: flex; }
.input-group .input { border-radius: 8px 0 0 8px; }
.input-group .addon {
  display: flex; align-items: center; padding: 0 12px;
  border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 8px 8px 0;
  background: var(--surface-2); color: var(--ink-3); font-size: 13px; white-space: nowrap;
}
.input-group .btn { border-radius: 0 8px 8px 0; margin-left: -1px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; cursor: pointer; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--ink); flex-shrink: 0; }
.check .sub { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
input[type="file"].input { padding: 7px 12px; }
input[type="date"].input, input[type="time"].input { padding-right: 10px; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Line editors (faktura / tilbud / lejeaftale) */
.lines { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.line-row { display: grid; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.line-row:last-child { border-bottom: 0; }
.line-head { background: var(--surface-2); padding: 8px 14px; }
.line-head span { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.line-row .input { height: 34px; font-size: 13.5px; }
.line-row .cell-label { display: none; }
.lines-invoice .line-row { grid-template-columns: 1.3fr 1.7fr 0.6fr 0.8fr 0.9fr 34px; }
.lines-quote .line-row { grid-template-columns: 2.4fr 0.6fr 0.9fr 0.9fr 34px; }
.lines-rental .line-row { grid-template-columns: 1.3fr 1.5fr 0.5fr 0.5fr 0.8fr 0.8fr 0.8fr 34px; }
.lines .input[readonly] { background: transparent; border-color: transparent; text-align: right; font-weight: 500; }
.lines-foot { display: flex; gap: 8px; margin-top: 12px; }
.totals { width: 100%; max-width: 360px; margin-left: auto; border-collapse: collapse; }
.totals td { padding: 8px 0; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-size: 17px; font-weight: 600; border-top: 1px solid var(--ink); border-bottom: 0; padding-top: 12px; }
.totals tr.deposit td { color: var(--warning); font-weight: 500; border-bottom: 0; }

/* --------------------------------------------------------------------------
   Alerts, notices
   -------------------------------------------------------------------------- */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px; margin-bottom: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
}
.alert .icon { margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-close { background: none; border: 0; padding: 2px; margin: -2px -4px 0 0; cursor: pointer; color: inherit; opacity: 0.6; border-radius: 4px; }
.alert-close:hover { opacity: 1; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(47, 111, 78, 0.2); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(168, 57, 46, 0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(150, 102, 28, 0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: rgba(59, 92, 124, 0.2); }
.notice { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; color: var(--ink-2); }
.notice strong { color: var(--ink); }
.notice.success { background: var(--success-bg); border-color: rgba(47, 111, 78, 0.2); color: var(--success); }
.notice.warning { background: var(--warning-bg); border-color: rgba(150, 102, 28, 0.2); color: var(--warning); }
.notice.danger { background: var(--danger-bg); border-color: rgba(168, 57, 46, 0.2); color: var(--danger); }
.notice.info { background: var(--info-bg); border-color: rgba(59, 92, 124, 0.2); color: var(--info); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* --------------------------------------------------------------------------
   Dialog (native <dialog>)
   -------------------------------------------------------------------------- */
dialog.dialog {
  border: 0; padding: 0; margin: auto;
  width: min(560px, calc(100vw - 32px));
  border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 48px);
}
dialog.dialog-lg { width: min(800px, calc(100vw - 32px)); }
dialog.dialog-xl { width: min(1000px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: rgba(20, 20, 20, 0.45); backdrop-filter: blur(2px); }
dialog.dialog[open] { animation: dialog-in 0.16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(0.99); } to { opacity: 1; transform: none; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.dialog-title { font-size: 15px; font-weight: 600; }
.dialog-body { padding: 22px; overflow-y: auto; max-height: calc(100vh - 220px); }
.dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* --------------------------------------------------------------------------
   Dropdown (native <details>)
   -------------------------------------------------------------------------- */
details.dropdown { position: relative; display: inline-block; }
details.dropdown > summary { list-style: none; cursor: pointer; }
details.dropdown > summary::-webkit-details-marker { display: none; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 6px; border: 0; background: none;
  font: inherit; font-size: 13.5px; color: var(--ink); text-align: left; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.menu a .icon, .menu button .icon { color: var(--ink-3); }
.menu hr { margin: 6px 0; }

/* --------------------------------------------------------------------------
   Segmented filters, tabs
   -------------------------------------------------------------------------- */
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 9px; flex-wrap: wrap; }
.segment { padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--ink-2); transition: background 0.12s ease; }
.segment:hover { color: var(--ink); }
.segment.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* --------------------------------------------------------------------------
   Empty state, toast, misc
   -------------------------------------------------------------------------- */
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty .icon { color: var(--ink-4); }
.empty p { margin: 10px 0 14px; font-size: 13.5px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px;
  font-size: 13.5px; box-shadow: var(--shadow); z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: calc(100vw - 32px);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.timer-value { font-size: 44px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.timer-amount { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--success); line-height: 1; }
.pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.chart { position: relative; height: 280px; }
.chart-sm { height: 220px; }

.sigpad { position: relative; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.sigpad canvas { display: block; width: 100%; height: 180px; cursor: crosshair; touch-action: none; }
.sigpad .btn { position: absolute; top: 8px; right: 8px; }
.signature-img { max-width: 260px; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px; display: block; }

.tile-link { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); transition: border-color 0.12s ease; }
.tile-link:hover { border-color: var(--ink-4); }
.tile-link .v { font-weight: 600; font-variant-numeric: tabular-nums; display: block; margin-top: 2px; }

.progress { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ink); border-radius: 999px; }

.divider-v { width: 1px; height: 24px; background: var(--border); }

.attach-link { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-3); }
.attach-link:hover { color: var(--ink); }

/* --------------------------------------------------------------------------
   Public pages (accept / view) & login
   -------------------------------------------------------------------------- */
body.public { background: var(--bg); }
.public-wrap { max-width: 780px; margin: 0 auto; padding: 32px 16px 48px; }
.public-brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.public-brand .brand { padding: 0; }
.doc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 30px 36px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.doc-kicker { font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.doc-number { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.doc-body { padding: 32px 36px; }
.doc-body + .doc-body { border-top: 1px solid var(--border); }
.doc-foot { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 24px; line-height: 1.7; }
.doc-meta { display: grid; gap: 4px 24px; grid-template-columns: auto 1fr; font-size: 13.5px; }
.doc-meta dt { color: var(--ink-3); }
.doc-meta dd { margin: 0; font-weight: 500; text-align: right; }
.doc-lines { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc-lines th { text-align: left; padding: 8px 0; border-bottom: 1px solid var(--ink); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.doc-lines td { padding: 12px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-lines .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-lines th.num { text-align: right; }
.terms-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 18px 20px; font-size: 13px; white-space: pre-line; max-height: 320px; overflow-y: auto; line-height: 1.6; }
.result { text-align: center; padding: 56px 24px; }
.result .icon { width: 44px; height: 44px; }
.result h2 { margin-top: 14px; }
.result p { color: var(--ink-3); margin-top: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px; box-shadow: var(--shadow-sm); }
.login .brand { padding: 0 0 22px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .hide-lg { display: none !important; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-side, .grid-side-left, .grid-main { grid-template-columns: minmax(0, 1fr); }
  .card.is-sticky { position: static; }
}
@media (max-width: 900px) {
  .hide-md { display: none !important; }
  .main { padding: 24px 20px 48px; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row-3, .form-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lines .line-head { display: none; }
  .lines .line-row { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 14px; }
  .lines .line-row > div { display: flex; flex-direction: column; gap: 4px; }
  .lines .line-row .cell-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
  .lines .line-row > .cell-wide { grid-column: span 2; }
  .lines .input[readonly] { text-align: left; background: var(--surface-2); border-color: transparent; }
  .totals { max-width: none; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow); }
  .overlay.is-open { display: block; }
  .topbar { display: flex; }
  .main { margin-left: 0; padding: 20px 16px 40px; }
  .page-head { margin-bottom: 20px; }
  .page-title { font-size: 21px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-row, .form-row-3, .form-row-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .table th, .table td { padding: 11px 12px; }
  .doc-head, .doc-body { padding: 22px 20px; }
  .doc-number { font-size: 22px; }
  .timer-value { font-size: 34px; }
  .dialog-body { max-height: calc(100vh - 200px); }
}
@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .lines .line-row { grid-template-columns: minmax(0, 1fr) !important; }
  .lines .line-row > .cell-wide { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 18px; }
  .page-actions { width: 100%; }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .overlay, .no-print, .toast, .page-actions, .actions { display: none !important; }
  .main { margin: 0; padding: 0; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  .public-wrap { max-width: none; padding: 0; }
  .doc-card { border: 0; box-shadow: none; border-radius: 0; }
  .doc-head, .doc-body { padding: 16px 0; }
  .terms-box { max-height: none; overflow: visible; }
}
