:root {
  color-scheme: light;
  --ink: #17211d;
  --ink-2: #526059;
  --forest: #142820;
  --forest-2: #1f4737;
  --sage: #dce8df;
  --sage-2: #edf3ef;
  --paper: #f6f4ef;
  --white: #fffefa;
  --line: #d8ddd8;
  --terracotta: #bd5c42;
  --gold: #d3a857;
  --blue: #426b85;
  --danger: #ad3f36;
  --shadow: 0 18px 55px rgba(30, 48, 39, 0.1);
  --radius: 18px;
  --radius-sm: 11px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.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; }

.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; color: var(--ink-2); }
.brand-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--forest); color: white; font: 500 27px/1 "Iowan Old Style", Georgia, serif; box-shadow: 0 12px 28px rgba(20, 40, 32, .18); }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 1.05fr) minmax(400px, .95fr); background: var(--white); }
.auth-story { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(38px, 7vw, 88px); color: #f7f1e8; background: var(--forest); }
.auth-story::before { content: ""; position: absolute; width: 620px; height: 620px; border: 1px solid rgba(255,255,255,.13); border-radius: 50%; right: -260px; top: -300px; box-shadow: 0 0 0 80px rgba(255,255,255,.025), 0 0 0 170px rgba(255,255,255,.018); }
.wordmark { position: relative; display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: -.02em; font-size: 20px; }
.wordmark .brand-mark { background: #e9c985; color: var(--forest); box-shadow: none; }
.auth-panel { display: grid; place-items: center; padding: clamp(26px, 7vw, 92px); background: var(--white); }
.auth-card { width: min(450px, 100%); }
.eyebrow { margin: 0 0 12px; color: var(--terracotta); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; }
.auth-card h2, .page-title { font: 500 38px/1.08 "Iowan Old Style", Georgia, serif; margin: 0; letter-spacing: -.025em; }
.auth-card .lead { color: var(--ink-2); line-height: 1.6; margin: 14px 0 32px; }

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label, .field-label { font-size: 12px; font-weight: 700; color: #435049; }
.input, input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); color: var(--ink); padding: 12px 13px; outline: none; transition: border-color .2s, box-shadow .2s; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: #6d8b7c; box-shadow: 0 0 0 3px rgba(31,71,55,.1); }
input[type="checkbox"] { width: auto; accent-color: var(--forest-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: 1 / -1; }
.hint { color: var(--ink-2); font-size: 12px; line-height: 1.5; }

.button { border: 0; border-radius: var(--radius-sm); padding: 11px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 13px; transition: transform .15s, box-shadow .2s, background .2s; text-decoration: none; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button-primary { background: var(--forest); color: white; box-shadow: 0 8px 18px rgba(20,40,32,.16); }
.button-primary:hover { background: #1d3a2f; }
.button-secondary { background: var(--sage-2); color: var(--forest); }
.button-ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.button-danger { background: #faece8; color: var(--danger); }
.button-full { width: 100%; padding-block: 14px; }
.button-small { padding: 8px 11px; font-size: 12px; border-radius: 9px; }
.icon-button { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); background: white; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 25px 18px 18px; color: #e9f0ec; background: var(--forest); z-index: 10; }
.sidebar .wordmark { padding: 0 10px 24px; }
.sidebar .brand-mark { width: 39px; height: 39px; border-radius: 12px; background: #e9c985; color: var(--forest); }
.sidebar-label { margin: 18px 11px 8px; color: #81988b; font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.nav { display: grid; gap: 4px; }
.nav-button { border: 0; border-radius: 10px; padding: 10px 11px; display: flex; align-items: center; gap: 11px; background: transparent; color: #aec1b7; text-align: left; font-size: 13px; font-weight: 600; }
.nav-button:hover { background: rgba(255,255,255,.06); color: white; }
.nav-button.active { background: #29483c; color: white; box-shadow: inset 2px 0 #e9c985; }
.nav-icon { width: 19px; height: 19px; display: grid; place-items: center; font-size: 16px; }
.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.09); }
.profile-chip { display: grid; grid-template-columns: 35px 1fr auto; align-items: center; gap: 10px; padding: 8px; }
.avatar { width: 35px; height: 35px; border-radius: 50%; display: grid; place-items: center; background: #456557; color: white; font-size: 12px; font-weight: 700; }
.profile-chip strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-chip span { display: block; color: #8ea397; font-size: 10px; text-transform: capitalize; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 8; height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 clamp(22px, 4vw, 48px); background: rgba(246,244,239,.9); border-bottom: 1px solid rgba(216,221,216,.78); backdrop-filter: blur(14px); }
.merchant-switch { display: flex; align-items: center; gap: 10px; }
.merchant-switch label { color: var(--ink-2); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.merchant-switch select { min-width: 200px; padding: 8px 34px 8px 10px; border: 0; background-color: transparent; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.mobile-menu { display: none; }
.content { width: min(1440px, 100%); margin: 0 auto; padding: 35px clamp(22px, 4vw, 48px) 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 25px; margin-bottom: 28px; }
.page-head p { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 24px; }
.metric { position: relative; overflow: hidden; min-height: 138px; padding: 20px; background: var(--white); border: 1px solid #e3e4df; border-radius: var(--radius); box-shadow: 0 6px 25px rgba(30,48,39,.035); }
.metric::after { content: ""; position: absolute; width: 70px; height: 70px; border-radius: 50%; right: -28px; bottom: -30px; background: var(--sage); opacity: .7; }
.metric.accent { color: white; background: var(--forest-2); border-color: var(--forest-2); }
.metric.accent::after { background: #e9c985; opacity: .25; }
.metric-label { color: var(--ink-2); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.metric.accent .metric-label { color: #bbd0c4; }
.metric-value { margin: 19px 0 8px; font: 500 30px/1 "Iowan Old Style", Georgia, serif; letter-spacing: -.02em; }
.metric-sub { color: var(--ink-2); font-size: 11px; }
.metric.accent .metric-sub { color: #bbd0c4; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .7fr); gap: 20px; }
.dashboard-grid > *, .split-layout > * { min-width: 0; }
.card { min-width: 0; background: var(--white); border: 1px solid #e2e4df; border-radius: var(--radius); box-shadow: 0 8px 30px rgba(30,48,39,.04); }
.card-header { min-height: 65px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px 20px; border-bottom: 1px solid #e8e9e5; }
.card-header h3 { margin: 0; font-size: 14px; }
.card-body { padding: 20px; }
.empty { padding: 50px 24px; text-align: center; color: var(--ink-2); }
.empty-symbol { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 15px; display: grid; place-items: center; background: var(--sage-2); color: var(--forest-2); font-size: 22px; }
.empty h3 { color: var(--ink); margin: 0 0 6px; }
.empty p { max-width: 420px; margin: 0 auto 18px; font-size: 13px; line-height: 1.55; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: 12px 16px; color: #758078; background: #faf9f5; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 9px; text-transform: uppercase; letter-spacing: .09em; }
.data-table td { padding: 14px 16px; border-bottom: 1px solid #ecece8; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background .15s; }
.data-table tbody tr.clickable:hover { background: #f7faf8; cursor: pointer; }
.invoice-ref { font-weight: 700; color: var(--forest-2); }
.muted { color: var(--ink-2); }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 99px; font-size: 9px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-paid { color: #267050; background: #e6f2eb; }
.status-unpaid, .status-overdue, .status-past_due, .status-rejected { color: #aa4937; background: #f9e9e4; }
.status-partially_paid { color: #896213; background: #fbf1d9; }
.status-draft { color: #65716b; background: #edf0ed; }
.status-credit { color: #3f6f88; background: #e8f1f5; }
.status-void { color: #777; background: #eee; text-decoration: line-through; }
.status-open { color: #315f78; background: #e7f1f6; }
.status-pending_approval { color: #765b18; background: #faf0d4; }
.status-approved, .status-scheduled { color: #3c5f4e; background: #e6f0eb; }
.status-uncollectible { color: #6c5960; background: #eee8ea; }

.filters { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters .search { min-width: 240px; flex: 1; position: relative; }
.filters input, .filters select { padding: 9px 11px; background: var(--white); }
.filter-count { margin-left: auto; color: var(--ink-2); font-size: 11px; }

.split-layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 20px; align-items: start; }
.detail-panel { position: sticky; top: 92px; }
.invoice-hero { padding: 24px; color: white; background: var(--forest); border-radius: var(--radius) var(--radius) 0 0; }
.invoice-hero .eyebrow { color: #e9c985; }
.invoice-hero h2 { margin: 5px 0 7px; font: 500 28px/1 "Iowan Old Style", Georgia, serif; }
.invoice-hero p { margin: 0; color: #afc2b8; }
.detail-section { padding: 18px 20px; border-bottom: 1px solid #e8e9e5; }
.detail-section:last-child { border-bottom: 0; }
.detail-section h4 { margin: 0 0 13px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: #738078; }
.key-value { display: flex; justify-content: space-between; gap: 15px; margin: 9px 0; font-size: 12px; }
.key-value span:first-child { color: var(--ink-2); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline { display: grid; gap: 12px; }
.timeline-item { padding-left: 16px; border-left: 2px solid var(--sage); }
.timeline-item p { margin: 0 0 3px; font-size: 12px; line-height: 1.45; }
.timeline-item time { color: var(--ink-2); font-size: 10px; }

.editor { max-width: 980px; }
.section-card { margin-bottom: 18px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title h3 { margin: 0; font-size: 14px; }
.line-items { width: 100%; border-collapse: collapse; }
.line-items th { padding: 8px 6px; color: var(--ink-2); font-size: 9px; text-transform: uppercase; text-align: left; }
.line-items td { padding: 5px; vertical-align: top; }
.line-items input { padding: 9px; min-width: 75px; }
.line-items .description { min-width: 230px; }
.line-total { padding-top: 15px !important; text-align: right; font-weight: 700; white-space: nowrap; }
.remove-line { margin-top: 3px; border: 0; background: transparent; color: var(--danger); font-size: 18px; }
.editor-total { margin-left: auto; width: min(340px, 100%); padding: 18px 0 0; }
.editor-total .key-value:last-child { padding-top: 12px; border-top: 2px solid var(--forest); font-size: 16px; }

.drop-zone { display: grid; place-items: center; min-height: 150px; padding: 26px; border: 1px dashed #9caaa2; border-radius: 14px; background: #fafbf8; text-align: center; transition: border .2s, background .2s; }
.drop-zone:hover { border-color: var(--forest-2); background: var(--sage-2); }
.drop-zone input { display: none; }
.drop-zone strong { display: block; margin: 8px 0 4px; }
.preview-list { display: grid; gap: 9px; margin-top: 18px; }
.preview-row { display: grid; grid-template-columns: 1.2fr .8fr auto; align-items: center; gap: 15px; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: white; }
.warning { padding: 10px 12px; border-radius: 10px; color: #7a5312; background: #fcf1d8; font-size: 11px; line-height: 1.5; }
.info-box { padding: 14px; border-radius: 12px; background: var(--sage-2); color: #385044; font-size: 12px; line-height: 1.55; }
.danger-box { background: #faece8; color: #853f33; }

.settings-grid { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 20px; }
.settings-nav { display: grid; gap: 5px; align-content: start; }
.settings-nav button { border: 0; border-radius: 9px; padding: 10px 12px; background: transparent; color: var(--ink-2); text-align: left; font-size: 12px; font-weight: 700; }
.settings-nav button.active { background: var(--sage); color: var(--forest); }
.settings-pane { min-width: 0; }
.inline-form { display: flex; gap: 9px; align-items: end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 145px; margin: 0; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(12,25,20,.58); backdrop-filter: blur(5px); animation: fade .15s ease-out; }
.modal { width: min(610px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--white); border-radius: 20px; box-shadow: 0 30px 90px rgba(0,0,0,.22); animation: rise .2s ease-out; }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--white); }
.modal-header h3 { margin: 0; font: 500 24px/1 "Iowan Old Style", Georgia, serif; }
.modal-body { padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 9px; padding: 16px 22px; border-top: 1px solid var(--line); }

.toast-region { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: grid; gap: 9px; width: min(360px, calc(100vw - 40px)); }
.toast { padding: 13px 15px; display: flex; gap: 10px; border-radius: 12px; background: var(--forest); color: white; box-shadow: var(--shadow); font-size: 12px; animation: rise .2s ease-out; }
.toast.error { background: #8d3f35; }
.skeleton { min-height: 16px; border-radius: 7px; background: linear-gradient(90deg,#ecece7 25%,#f7f7f3 50%,#ecece7 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }

@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) } }
@keyframes shimmer { to { background-position: -200% 0 } }
@keyframes spin { to { transform: rotate(360deg) } }

@media (max-width: 1080px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .split-layout { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
}
@media (max-width: 820px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-story { min-height: 340px; padding: 35px 28px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; width: 246px; left: -260px; box-shadow: 20px 0 60px rgba(0,0,0,.22); transition: left .2s; }
  .sidebar.open { left: 0; }
  .mobile-menu { display: grid; }
  .merchant-switch label { display: none; }
  .merchant-switch select { min-width: 130px; max-width: 190px; }
  .topbar { padding-inline: 16px; }
  .content { padding: 25px 16px 70px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { display: flex; overflow-x: auto; }
  .settings-nav button { white-space: nowrap; }
}
@media (max-width: 560px) {
  .auth-story { min-height: 280px; }
  .auth-panel { padding: 38px 22px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 116px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-actions { width: 100%; }
  .page-actions .button { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .filters { align-items: stretch; flex-direction: column; }
  .filters .search { min-width: 0; }
  .filter-count { margin: 0; }
  .preview-row { grid-template-columns: 1fr; }
  .auth-card h2, .page-title { font-size: 32px; }
}
