:root {
  --bg: #f3f4ef;
  --panel: #fcfcf9;
  --panel-strong: #ffffff;
  --ink: #18332c;
  --ink-soft: #67766f;
  --line: #dde2dc;
  --accent: #d8f879;
  --accent-strong: #b9df52;
  --green: #193a31;
  --green-mid: #2f6555;
  --cream: #f5f0df;
  --danger: #b6453c;
  --warning: #a26c16;
  --shadow: 0 16px 42px rgba(22, 51, 43, 0.08);
  --radius: 18px;
  --radius-sm: 13px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.auth-root { min-height: 100vh; padding: 24px; background: #e9ede5; }
.auth-layout { display: grid; grid-template-columns: minmax(340px, .9fr) minmax(420px, 1.1fr); width: min(1040px, 100%); min-height: calc(100vh - 48px); margin: 0 auto; overflow: hidden; border: 1px solid rgba(24,51,44,.08); border-radius: 28px; background: var(--panel-strong); box-shadow: 0 28px 80px rgba(22,51,43,.12); }
.auth-welcome { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; min-height: 620px; padding: 42px; background: var(--green); color: white; }
.auth-welcome::after { content: ""; position: absolute; right: -150px; bottom: -165px; width: 390px; height: 390px; border: 76px solid rgba(216,248,121,.08); border-radius: 50%; }
.auth-brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; width: fit-content; }
.auth-brand strong { display: block; font-size: 20px; letter-spacing: -.6px; }
.auth-brand small { display: block; margin-top: 2px; color: #aebeb8; font-size: 11px; }
.auth-welcome > div { position: relative; z-index: 1; max-width: 470px; }
.auth-welcome .eyebrow { color: var(--accent); }
.auth-welcome h1 { margin: 13px 0 16px; font-size: clamp(34px, 4vw, 50px); line-height: 1.02; letter-spacing: -2.1px; }
.auth-welcome p:not(.eyebrow) { margin: 0; color: #bdcbc6; font-size: 16px; line-height: 1.6; }
.auth-card { align-self: center; width: min(430px, calc(100% - 64px)); margin: 48px auto; }
.auth-card h2 { margin: 9px 0 7px; font-size: 31px; line-height: 1.12; letter-spacing: -1.1px; }
.auth-subtitle { margin: 0 0 27px; color: var(--ink-soft); line-height: 1.55; }
.auth-form { display: grid; gap: 15px; }
.auth-form .field { margin: 0; }
.auth-form .field label { margin-bottom: 7px; }
.auth-form input { min-height: 48px; }
.auth-submit { width: 100%; min-height: 48px; margin-top: 2px; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 3px; }
.auth-hint { margin: -3px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.auth-message { margin: 0 0 18px; padding: 12px 14px; border: 1px solid #d5e4bd; border-radius: 11px; background: #f2f8e7; color: var(--green); font-size: 13px; line-height: 1.45; }
.auth-message.error { border-color: #eed0cc; background: #fff0ee; color: #91372f; }
.development-reset-link { display: block; margin: -7px 0 18px; padding: 12px 14px; border: 1px dashed var(--green-mid); border-radius: 11px; color: var(--green-mid); font-size: 13px; font-weight: 750; text-align: center; }
.auth-verification-loading { min-height: 150px; }

.app-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 25px 16px 18px;
  background: var(--green);
  color: #eef4ed;
  z-index: 10;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 0 9px 30px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: var(--green);
  background: var(--accent);
  font-size: 23px;
  font-weight: 850;
}
.brand strong { display: block; font-size: 18px; letter-spacing: -0.5px; }
.brand small { display: block; margin-top: 2px; color: #9eb0a9; font-size: 10px; }
.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  color: #b9c8c2;
  font-weight: 650;
  transition: 160ms ease;
}
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: var(--green); background: var(--accent); }
.sidebar-logout { width: 100%; border: 0; background: transparent; cursor: pointer; font: inherit; text-align: left; }
.nav-icon { display: grid; place-items: center; width: 22px; height: 22px; }
.nav-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-bottom { display: grid; gap: 12px; margin-top: auto; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; min-height: 96px; padding: 24px 42px 18px; gap: 18px; }
.topbar h1 { margin: 3px 0 0; font-size: clamp(27px, 3vw, 34px); letter-spacing: -1.25px; line-height: 1; }
.eyebrow { margin: 0; color: var(--ink-soft); font-size: 10px; font-weight: 800; letter-spacing: 1.7px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.content { padding: 0 42px 48px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-weight: 750;
  transition: 150ms ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(25,58,49,.14); }
.button:active { transform: translateY(0); }
.button:focus-visible, .icon-button:focus-visible, .nav-item:focus-visible, .text-button:focus-visible { outline: 3px solid rgba(185,223,82,.72); outline-offset: 2px; }
.button.secondary { background: var(--panel-strong); color: var(--ink); border-color: var(--line); }
.button.accent { background: var(--accent); color: var(--green); }
.button.danger { background: #fff0ee; color: var(--danger); border-color: #f0d3d0; }
.button.small { min-height: 34px; padding: 0 12px; border-radius: 9px; font-size: 13px; }
.button.ghost { min-height: 34px; padding: 0 9px; color: var(--ink-soft); background: transparent; }
.button:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.topbar-actions .button b { display: none; }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-strong); cursor: pointer; font-size: 19px; }
.mobile-menu { display: none; }

.hero-card {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(250px, .55fr);
  gap: 24px;
  min-height: 168px;
  padding: 27px 30px;
  border-radius: 22px;
  background: var(--green);
  color: white;
  box-shadow: var(--shadow);
}
.hero-card::after { content: ""; position: absolute; right: -85px; top: -125px; width: 300px; height: 300px; border: 58px solid rgba(216,248,121,.09); border-radius: 50%; }
.hero-card h2 { max-width: 650px; margin: 10px 0 8px; font-size: clamp(27px, 3vw, 36px); line-height: 1.06; letter-spacing: -1.45px; }
.hero-card p { max-width: 590px; margin: 0; color: #bdcbc6; line-height: 1.55; }
.hero-card .eyebrow { color: var(--accent); }
.hero-actions { display: flex; flex-wrap: wrap; align-items: flex-end; align-content: flex-end; gap: 10px; z-index: 1; }
.hero-actions .button.secondary { color: white; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18); }

.section-heading { display: flex; align-items: flex-end; gap: 20px; margin: 25px 0 13px; }
.section-heading h2 { margin: 0; font-size: 21px; letter-spacing: -.6px; }
.section-heading p { margin: 3px 0 0; color: var(--ink-soft); font-size: 13px; }
.section-heading > :last-child:not(:first-child) { margin-left: auto; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.stat-card, .panel { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); }
.stat-card { min-height: 116px; padding: 18px; }
.stat-card .label { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 650; }
.stat-card strong { display: block; margin-top: 13px; font-size: clamp(21px, 2.2vw, 28px); letter-spacing: -1px; }
.stat-card small { display: block; margin-top: 5px; color: var(--ink-soft); }
.stat-card.highlight { background: var(--accent); border-color: var(--accent-strong); }
.mini-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-mid); }
.mini-dot.orange { background: #d89424; }
.mini-dot.red { background: #ce5f55; }
.mini-dot.lime { background: var(--accent-strong); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); gap: 14px; }
.panel { padding: 21px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 20px; }
.panel-header h3 { margin: 0; font-size: 17px; letter-spacing: -.4px; }
.panel-header p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }

.chart { display: flex; align-items: flex-end; gap: 12px; height: 190px; padding-top: 15px; }
.chart-empty { display: grid; place-items: center; min-height: 190px; color: var(--ink-soft); text-align: center; }
.chart-column { display: flex; flex: 1; flex-direction: column; align-items: center; gap: 8px; height: 100%; min-width: 22px; }
.bars { display: flex; align-items: flex-end; justify-content: center; gap: 4px; width: 100%; height: 155px; }
.bar { width: min(18px, 36%); min-height: 3px; border-radius: 6px 6px 2px 2px; background: var(--green-mid); transition: height .4s ease; }
.bar.expense { background: #d6c7a7; }
.chart-column small { color: var(--ink-soft); font-size: 10px; text-transform: capitalize; }
.legend { display: flex; gap: 14px; color: var(--ink-soft); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }

.tax-breakdown { display: grid; gap: 15px; }
.tax-row { display: grid; grid-template-columns: 1fr auto; gap: 5px; }
.tax-row span { color: var(--ink-soft); font-size: 12px; }
.tax-row strong { font-size: 13px; }
.tax-track { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 99px; background: #e8ebe4; }
.tax-track i { display: block; height: 100%; border-radius: inherit; background: var(--green-mid); }
.tax-total { display: flex; justify-content: space-between; align-items: center; padding-top: 16px; border-top: 1px solid var(--line); }
.tax-total strong { font-size: 24px; letter-spacing: -.7px; }
.info-note { padding: 12px 14px; border-radius: 11px; background: var(--cream); color: #706849; font-size: 11px; line-height: 1.5; }

.table-panel { overflow: hidden; padding: 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink-soft); text-align: left; font-size: 10px; letter-spacing: .8px; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 120ms; }
tbody tr:hover { background: rgba(255,255,255,.8); }
.cell-main { font-weight: 700; }
.cell-sub { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 11px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 750; white-space: nowrap; }
.muted { color: var(--ink-soft); }
.actions-cell { display: flex; justify-content: flex-end; gap: 4px; }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 99px; background: #edf0ea; color: #596861; font-size: 11px; font-weight: 750; white-space: nowrap; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.paid, .status-pill.signed, .status-pill.active { color: #2e705a; background: #e1f2e9; }
.status-pill.sent { color: #4a668a; background: #e8eef6; }
.status-pill.overdue, .status-pill.terminated { color: var(--danger); background: #fae8e6; }
.status-pill.completed { color: #5d6570; background: #e9ebee; }
.status-pill.income { color: #2e705a; background: #e1f2e9; }
.status-pill.expense { color: #9b6316; background: #f7ecd9; }
.chain-count { font-weight: 750; white-space: nowrap; }

.empty-state { display: grid; place-items: center; min-height: 260px; padding: 34px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 62px; height: 62px; margin-bottom: 18px; border-radius: 20px; background: var(--cream); font-size: 26px; }
.empty-state h3 { margin: 0; font-size: 20px; }
.empty-state p { max-width: 430px; margin: 8px auto 20px; color: var(--ink-soft); line-height: 1.55; }

.filter-row { display: flex; flex-wrap: wrap; align-items: end; gap: 9px; }
.filter-row .field { min-width: 150px; margin: 0; }
.search-field { position: relative; min-width: 230px; }
.search-field input { padding-left: 37px; }
.search-field::before { content: "⌕"; position: absolute; left: 13px; top: 10px; color: var(--ink-soft); z-index: 1; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .55fr); gap: 15px; }
.settings-card h3 { margin: 0 0 5px; font-size: 18px; }
.settings-card > p { margin: 0 0 23px; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.account-settings-card { grid-column: 1 / -1; }
.account-settings-card .panel-header { margin-bottom: 18px; }
.account-settings-card .panel-header p strong { color: var(--ink); }
.account-settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.account-settings-form { display: grid; align-content: start; gap: 17px; padding: 19px; border: 1px solid var(--line); border-radius: 14px; background: #f8f9f5; }
.account-settings-form h4 { margin: 0 0 4px; font-size: 15px; }
.account-settings-form > div > p { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.account-settings-form .form-grid { grid-template-columns: 1fr; }
.account-settings-form .button { justify-self: start; }
.numbering-settings { grid-column: 1 / -1; }
.numbering-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.numbering-card { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.numbering-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.numbering-card h4 { margin: 3px 0 0; font-size: 17px; }
.document-kind { color: var(--green-mid); font-size: 9px; font-weight: 850; letter-spacing: 1.2px; }
.number-preview { max-width: 52%; padding: 9px 11px; border-radius: 10px; background: var(--cream); text-align: right; }
.number-preview small, .number-preview strong { display: block; }
.number-preview small { margin-bottom: 2px; color: var(--ink-soft); font-size: 9px; text-transform: uppercase; letter-spacing: .7px; }
.number-preview strong { overflow-wrap: anywhere; font-size: 13px; font-variant-numeric: tabular-nums; }
.token-palette { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 18px; }
.number-token { display: inline-flex; align-items: center; gap: 6px; min-height: 31px; padding: 5px 8px; border: 1px solid #dce2d9; border-radius: 8px; background: #f8faf6; color: var(--ink); cursor: pointer; }
.number-token:hover { border-color: #bdccbf; background: #f1f6ed; }
.number-token code { color: var(--green-mid); font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.number-token span { color: var(--ink-soft); font-size: 9px; }
.numbering-options { display: grid; grid-template-columns: minmax(145px, .55fr) minmax(230px, 1.45fr); gap: 16px; align-items: start; }
.prefixes-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.prefixes-heading strong, .prefixes-heading small { display: block; }
.prefixes-heading strong { font-size: 11px; }
.prefixes-heading small { max-width: 290px; margin-top: 3px; color: var(--ink-soft); font-size: 9px; line-height: 1.35; }
.prefix-list { display: grid; gap: 7px; }
.prefix-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 40px; gap: 7px; align-items: center; }
.prefix-row > input { min-height: 39px; }
.prefix-row .icon-button { width: 39px; height: 39px; }
.prefix-default { display: flex; align-items: center; gap: 6px; min-height: 39px; padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; background: #f8faf6; color: var(--ink-soft); cursor: pointer; font-size: 9px; font-weight: 750; }
.prefix-default input { width: 15px; min-height: 15px; margin: 0; accent-color: var(--green); }
.numbering-note { margin-top: 15px; }
.template-settings { grid-column: 1 / -1; }
.template-settings-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.template-settings-header h3 { margin-bottom: 5px; }
.template-settings-header p { max-width: 670px; margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.template-tabs { display: inline-flex; flex: 0 0 auto; padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: #f2f5ef; }
.template-tabs button { min-height: 34px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 12px; font-weight: 750; }
.template-tabs button.active { background: #fff; color: var(--green); box-shadow: 0 2px 8px rgba(25,58,49,.09); }
.template-editor-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 310px); gap: 14px; align-items: start; }
.template-editor-main { min-width: 0; }
.wysiwyg-toolbar { display: flex; flex-wrap: wrap; gap: 7px; padding: 8px; border: 1px solid #d9ded7; border-bottom: 0; border-radius: 12px 12px 0 0; background: #f6f8f4; }
.wysiwyg-toolbar > div { display: flex; gap: 3px; padding-right: 7px; border-right: 1px solid var(--line); }
.wysiwyg-toolbar > div:last-child { padding-right: 0; border-right: 0; }
.wysiwyg-toolbar button { display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink); cursor: pointer; font-size: 12px; }
.wysiwyg-toolbar button:hover { border-color: #d4dbd2; background: #fff; }
.wysiwyg-toolbar .font-size-tools { align-items: center; }
.wysiwyg-toolbar .font-size-tools button { display: inline-flex; gap: 1px; align-items: baseline; font-weight: 750; }
.wysiwyg-toolbar .font-size-tools button span { font-size: 13px; }
.wysiwyg-toolbar .font-size-tools select { width: 76px; height: 32px; min-height: 32px; padding: 0 23px 0 8px; border-radius: 7px; background-color: #fff; font-size: 11px; font-weight: 700; }
.wysiwyg-toolbar button[data-action="open-table-dialog"] { display: inline-flex; gap: 6px; white-space: nowrap; }
.wysiwyg-toolbar button:nth-child(2)[data-command^="justify"] { text-align: center; }
.wysiwyg-toolbar button:nth-child(3)[data-command^="justify"] { text-align: right; }
.table-inspector { padding: 12px; border: 1px solid #cdd8cf; border-bottom: 0; background: #eef4ec; }
.table-inspector > header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.table-inspector > header > div { min-width: 0; }
.table-inspector > header strong, .table-inspector > header small { display: block; }
.table-inspector > header strong { font-size: 12px; }
.table-inspector > header small { margin-top: 2px; color: var(--ink-soft); font-size: 9px; }
.table-inspector > header .icon-button { width: 28px; height: 28px; margin-left: auto; }
.table-inspector-grid { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 8px; }
.table-inspector-grid > label { display: grid; gap: 4px; min-width: 0; color: #50615a; font-size: 9px; font-weight: 750; }
.table-inspector-grid input, .table-inspector-grid select { min-height: 34px; padding: 6px 8px; border-radius: 8px; background: #fff; font-size: 11px; }
.table-inspector-grid input[type="color"] { padding: 4px; cursor: pointer; }
.input-suffix, .size-with-unit, .color-action { display: flex; min-width: 0; }
.input-suffix input, .size-with-unit input { min-width: 0; border-radius: 8px 0 0 8px; }
.input-suffix b { display: grid; place-items: center; min-width: 34px; border: 1px solid #d7ded5; border-left: 0; border-radius: 0 8px 8px 0; background: #f8faf6; color: var(--ink-soft); font-size: 9px; }
.size-with-unit select { width: 58px; border-left: 0; border-radius: 0 8px 8px 0; }
.color-action { gap: 5px; }
.color-action input { min-width: 48px; }
.color-action button { padding: 0 8px; border: 1px solid #d7ded5; border-radius: 8px; background: #fff; color: var(--ink-soft); cursor: pointer; font-size: 9px; white-space: nowrap; }
.table-structure-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.table-structure-actions button { min-height: 29px; padding: 0 9px; border: 1px solid #cbd6cc; border-radius: 7px; background: #fff; color: var(--green); cursor: pointer; font-size: 9px; font-weight: 750; }
.table-structure-actions button:hover { border-color: var(--green-mid); }
.table-structure-actions button.danger { margin-left: auto; color: var(--danger); }
.wysiwyg-editor.document-sheet { min-height: 620px; padding: 38px 42px; border-radius: 0 0 12px 12px; box-shadow: none; outline: none; overflow-wrap: anywhere; }
.wysiwyg-editor:focus { border-color: var(--green-mid); box-shadow: inset 0 0 0 2px rgba(47,101,85,.09); }
.wysiwyg-editor .template-custom-table { margin: 10px 0; }
.wysiwyg-editor .template-cell-selected { position: relative; outline: 2px solid #5e8f78; outline-offset: -2px; box-shadow: inset 0 0 0 2px rgba(216,248,121,.5); }
.template-editor-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; }
.template-fields { max-height: 704px; overflow-y: auto; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: #f7f9f5; }
.template-fields-heading { margin-bottom: 10px; }
.template-fields-heading strong, .template-fields-heading small { display: block; }
.template-fields-heading strong { font-size: 13px; }
.template-fields-heading small { margin-top: 3px; color: var(--ink-soft); font-size: 9px; }
.template-fields details { border-top: 1px solid var(--line); }
.template-fields summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; cursor: pointer; font-size: 11px; font-weight: 800; list-style: none; }
.template-fields summary::-webkit-details-marker { display: none; }
.template-fields summary span { color: var(--ink-soft); font-size: 9px; }
.template-token-list { display: grid; gap: 5px; padding: 0 0 10px; }
.template-token-list button { display: grid; gap: 2px; width: 100%; padding: 8px 9px; border: 1px solid #dce2d9; border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; text-align: left; }
.template-token-list button:hover { border-color: var(--green-mid); background: #f4f8f0; }
.template-token-list code { overflow: hidden; color: var(--green-mid); font: 750 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.template-token-list span { color: var(--ink-soft); font-size: 9px; }
.template-note { margin-top: 15px; }
.profile-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.profile-card + .profile-card { margin-top: 10px; }
.profile-card header { display: flex; gap: 8px; align-items: center; }
.profile-card h4 { margin: 0; font-size: 14px; }
.profile-card header .status-pill { margin-left: auto; }
.profile-rates { display: flex; gap: 15px; margin-top: 12px; color: var(--ink-soft); font-size: 11px; }
.profile-actions { display: flex; gap: 5px; margin-top: 13px; }

.modal { width: min(920px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 24px; background: transparent; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(14, 35, 29, .62); backdrop-filter: blur(4px); }
.modal-card { overflow: hidden; background: var(--panel-strong); border-radius: 24px; }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; padding: 21px 24px 17px; border-bottom: 1px solid var(--line); background: var(--panel-strong); }
.modal-header h2 { margin: 3px 0 0; font-size: 24px; letter-spacing: -.7px; }
.modal-header .icon-button { margin-left: auto; }
.modal-body { padding: 22px 24px 24px; max-height: calc(100vh - 122px); overflow-y: auto; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.field { display: grid; align-content: start; gap: 7px; margin-bottom: 14px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #50615a; font-size: 11px; font-weight: 750; }
.field small { color: var(--ink-soft); font-size: 10px; line-height: 1.4; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--green-mid); cursor: pointer; font-size: 11px; font-weight: 800; }
.check-field { display: flex; align-items: flex-start; gap: 11px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 11px; background: #f8faf5; cursor: pointer; }
.check-field input { flex: 0 0 auto; width: 17px; min-height: 17px; margin: 2px 0 0; accent-color: var(--green); }
.check-field strong, .check-field small { display: block; }
.check-field strong { font-size: 12px; }
.check-field small { margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
input, select, textarea {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid #d7ded5;
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
  transition: 130ms ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--green-mid); box-shadow: 0 0 0 3px rgba(47,101,85,.1); }
textarea { min-height: 86px; resize: vertical; }
.form-actions { position: sticky; bottom: -24px; z-index: 2; display: flex; justify-content: flex-end; gap: 9px; padding: 15px 0 0; margin-top: 8px; border-top: 1px solid var(--line); background: linear-gradient(to bottom, rgba(255,255,255,.94), #fff 28%); }
.inline-fields { display: grid; grid-template-columns: 1fr 90px 100px 120px 36px; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--line); }
.inline-fields .field { margin: 0; }
.line-item-translations { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, .35fr); grid-column: 1 / -1; gap: 8px; margin-top: 2px; padding: 10px; border: 1px solid #d6e0d5; border-radius: 10px; background: #f5f8f2; }
.bilingual-toggle { margin: 4px 0 5px; border-color: #c9dba9; background: #f3f9e7; }
.translation-tools { display: flex; align-items: center; gap: 10px; padding: 7px 2px 2px; }
.translation-tools span { color: var(--ink-soft); font-size: 9px; line-height: 1.35; }
.translation-tools span[data-state="loading"] { color: var(--warning); }
.translation-tools span[data-state="ready"] { color: var(--green-mid); }
.translation-tools span[data-state="error"] { color: var(--danger); }
.inline-fields.is-translating [name="item_description_en"] { background: #fbfdea; box-shadow: inset 3px 0 0 var(--accent-strong); }
.line-items { margin-bottom: 18px; }
.hidden { display: none !important; }
.source-banner { display: flex; gap: 11px; align-items: center; margin-bottom: 17px; padding: 13px 15px; border: 1px solid #cbe1b0; border-radius: 12px; background: #f1f8e5; }
.source-banner > span { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: var(--accent); font-weight: 900; }
.source-banner strong, .source-banner small { display: block; }
.source-banner small { margin-top: 2px; color: var(--ink-soft); font-size: 10px; }
.inline-create { margin: 4px 0 18px; padding: 17px; border: 1px solid #cdd9d1; border-radius: 15px; background: #f5f8f3; }
.inline-create-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.inline-create-heading > div { flex: 1; }
.inline-create-heading strong, .inline-create-heading small { display: block; }
.inline-create-heading small { margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
.inline-create-heading .icon-button { width: 30px; height: 30px; }
.inline-counterparty-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.document-totals { width: min(390px, 100%); margin: 8px 0 22px auto; padding: 14px 17px; border-radius: 14px; background: #f3f5ef; }
.document-totals > div { display: flex; justify-content: space-between; gap: 20px; padding: 6px 0; color: var(--ink-soft); font-size: 12px; }
.document-totals strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.document-totals .grand { margin-top: 5px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--ink); font-size: 15px; }
.document-totals .grand strong { font-size: 18px; }

.document-preview { padding: 10px 4px; }
.document-sheet { min-height: 760px; padding: 42px 46px 34px; border: 1px solid #d9ddd8; background: #fff; color: #111; font: 12px/1.4 Arial, sans-serif; box-shadow: 0 10px 35px rgba(21,42,34,.06); }
.document-sheet .doc-header { padding: 0 0 16px; border-bottom: 2px solid #111; text-align: center; }
.document-sheet h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.document-sheet .doc-header p { margin: 5px 0 0; }
.act-intro { margin: 20px 0 16px; line-height: 1.55; text-align: justify; }
.doc-parties { display: grid; gap: 10px; margin: 21px 0 16px; }
.doc-parties section { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; padding-bottom: 10px; border-bottom: 1px solid #c7cbc7; }
.doc-parties section > span { font-weight: 700; }
.doc-parties section > div > strong { display: block; margin-bottom: 4px; font-size: 13px; }
.doc-parties dl { display: grid; gap: 2px; margin: 0; }
.doc-parties dl div { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 7px; }
.doc-parties dt { color: #555; }
.doc-parties dd { margin: 0; overflow-wrap: anywhere; }
.doc-empty { color: #777; }
.doc-context { display: grid; gap: 4px; margin: 0 0 17px; }
.doc-context > div { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; }
.doc-context span { font-weight: 700; }
.document-sheet .doc-table { width: 100%; margin-top: 8px; border: 1px solid #111; border-collapse: collapse; }
.document-sheet .doc-table th { padding: 7px 6px; border: 1px solid #111; background: #f0f0f0; color: #111; font-size: 9px; line-height: 1.25; text-transform: none; }
.document-sheet .doc-table td { padding: 8px 6px; border: 1px solid #111; vertical-align: top; }
.document-sheet .doc-table th:first-child, .document-sheet .doc-table td:first-child { width: 30px; text-align: center; }
.document-sheet .doc-table th:nth-child(3), .document-sheet .doc-table td:nth-child(3),
.document-sheet .doc-table th:nth-child(4), .document-sheet .doc-table td:nth-child(4) { width: 58px; text-align: center; }
.document-sheet .doc-table th:nth-last-child(-n+2), .document-sheet .doc-table td:nth-last-child(-n+2) { width: 105px; text-align: right; }
.doc-summary { width: 335px; margin: 14px 0 13px auto; }
.doc-summary > div { display: flex; justify-content: space-between; gap: 18px; padding: 4px 0; }
.doc-summary .total { margin-top: 4px; padding-top: 8px; border-top: 2px solid #111; font-size: 14px; }
.doc-summary .total strong { font-size: 15px; }
.doc-amount-words { margin: 12px 0 18px; padding-top: 11px; border-top: 1px solid #bfc4bf; }
.doc-amount-words p { margin: 3px 0; }
.doc-note { margin: 14px 0; padding: 11px 13px; border: 1px solid #c8ccc8; }
.doc-note p { margin: 4px 0 0; line-height: 1.5; }
.payment-box, .acceptance-text { margin-top: 16px; padding: 13px 14px; border: 1px solid #aaa; line-height: 1.5; }
.payment-box p { margin: 5px 0; font-size: 13px; font-weight: 700; }
.payment-box small { color: #333; line-height: 1.5; }
.signature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 55px; margin-top: 38px; }
.invoice-sheet .signature-grid { grid-template-columns: minmax(260px, 48%); }
.signature-grid > div > span { font-weight: 700; }
.signature-grid > div > strong { display: block; min-height: 24px; margin-top: 5px; }
.signature-line { padding-top: 20px; border-bottom: 1px solid #111; }
.signature-grid small { display: block; margin-top: 5px; color: #555; }
.bilingual-sheet { min-height: 0; padding: 24px 18px; font-size: 7.5px; line-height: 1.28; }
.bilingual-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.document-language-column { min-width: 0; padding: 0 12px; overflow-wrap: anywhere; }
.document-language-column + .document-language-column { border-left: 1px solid #8e9691; }
.language-label { margin-bottom: 7px; color: #68716d; font-size: 6.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; }
.bilingual-sheet .doc-header { padding-bottom: 9px; border-bottom-width: 1.5px; }
.bilingual-sheet h2 { font-size: 13px; }
.bilingual-sheet .doc-header p { margin-top: 3px; }
.bilingual-sheet .act-intro { margin: 10px 0 8px; line-height: 1.35; }
.bilingual-sheet .doc-parties { gap: 5px; margin: 10px 0 8px; }
.bilingual-sheet .doc-parties section { grid-template-columns: 55px minmax(0, 1fr); gap: 6px; padding-bottom: 5px; }
.bilingual-sheet .doc-parties section > div > strong { margin-bottom: 2px; font-size: 8px; }
.bilingual-sheet .doc-parties dl { gap: 0; }
.bilingual-sheet .doc-parties dl div { grid-template-columns: 48px minmax(0, 1fr); gap: 4px; }
.bilingual-sheet .doc-context { gap: 2px; margin-bottom: 8px; }
.bilingual-sheet .doc-context > div { grid-template-columns: 63px minmax(0, 1fr); gap: 5px; }
.bilingual-sheet .doc-table { margin-top: 4px; table-layout: fixed; }
.bilingual-sheet .doc-table th { padding: 3px 2px; font-size: 5.4px; line-height: 1.1; overflow-wrap: anywhere; word-break: break-word; white-space: normal !important; }
.bilingual-sheet .doc-table td { padding: 4px 2px; font-size: 6.3px; overflow-wrap: anywhere; }
.bilingual-sheet .doc-table th:first-child, .bilingual-sheet .doc-table td:first-child { width: 17px; }
.bilingual-sheet .doc-table th:nth-child(3), .bilingual-sheet .doc-table td:nth-child(3),
.bilingual-sheet .doc-table th:nth-child(4), .bilingual-sheet .doc-table td:nth-child(4) { width: 32px; }
.bilingual-sheet .doc-table th:nth-last-child(-n+2), .bilingual-sheet .doc-table td:nth-last-child(-n+2) { width: 54px; }
.bilingual-sheet .doc-summary { width: 205px; margin: 7px 0 6px auto; }
.bilingual-sheet .doc-summary > div { gap: 8px; padding: 2px 0; }
.bilingual-sheet .doc-summary .total { margin-top: 2px; padding-top: 4px; font-size: 8px; }
.bilingual-sheet .doc-summary .total strong { font-size: 8.5px; }
.bilingual-sheet .doc-amount-words { margin: 6px 0 8px; padding-top: 5px; }
.bilingual-sheet .doc-amount-words p { margin: 2px 0; }
.bilingual-sheet .doc-note { margin: 7px 0; padding: 6px; }
.bilingual-sheet .payment-box, .bilingual-sheet .acceptance-text { margin-top: 8px; padding: 7px; line-height: 1.35; }
.bilingual-sheet .payment-box p { margin: 3px 0; font-size: 7.5px; }
.bilingual-sheet .signature-grid, .bilingual-sheet.invoice-sheet .signature-grid { grid-template-columns: 1fr; gap: 15px; margin-top: 18px; }
.bilingual-sheet .signature-line { padding-top: 10px; }
.preview-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 14px; }

.toast-region { position: fixed; right: 24px; bottom: 24px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 380px; padding: 14px 17px; border-radius: 12px; background: var(--green); color: white; box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { background: #8f3933; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

.loading-state { display: grid; place-items: center; min-height: 55vh; color: var(--ink-soft); }
.spinner { width: 28px; height: 28px; border: 3px solid #d8ded6; border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.print-area { display: none; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .hero-card { grid-template-columns: 1fr auto; }
  .hero-actions { align-items: center; align-content: center; }
  .numbering-grid { grid-template-columns: 1fr; }
  .template-editor-panel { grid-template-columns: 1fr; }
  .template-fields { max-height: 390px; }
  .table-inspector-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}

@media (max-width: 760px) {
  .auth-root { padding: 0; }
  .auth-layout { display: block; min-height: 100vh; border: 0; border-radius: 0; }
  .auth-welcome { min-height: auto; padding: 25px 22px 29px; }
  .auth-welcome > div { margin-top: 45px; }
  .auth-welcome h1 { max-width: 500px; font-size: 34px; }
  .auth-card { width: auto; margin: 0; padding: 34px 22px 45px; }
  .account-settings-grid { grid-template-columns: 1fr; }
  .app-shell { display: block; }
  .sidebar { position: fixed; width: 242px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; }
  .topbar { min-height: 84px; padding: 18px 16px 15px; }
  .topbar h1 { font-size: 27px; }
  .content { padding: 0 16px 32px; }
  .topbar-actions .button span { display: none; }
  .topbar-actions .button b { display: inline; font-size: 18px; }
  .topbar-actions .button { width: 42px; min-width: 42px; padding: 0; }
  .hero-card { grid-template-columns: 1fr; min-height: auto; padding: 24px 22px; border-radius: 19px; }
  .hero-card h2 { font-size: 29px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { min-height: 115px; padding: 17px; }
  .section-heading { align-items: flex-start; flex-direction: column; margin-top: 22px; }
  .section-heading > :last-child:not(:first-child) { margin-left: 0; width: 100%; }
  .filter-row, .filter-row .field, .search-field { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .inline-fields { grid-template-columns: 1fr 1fr 1fr; }
  .inline-fields .field:first-child { grid-column: 1 / -1; }
  .line-item-translations { grid-template-columns: 1fr; }
  .translation-tools { align-items: flex-start; flex-direction: column; }
  .inline-counterparty-grid { grid-template-columns: 1fr; }
  .numbering-options { grid-template-columns: 1fr; gap: 4px; }
  .number-preview { max-width: 60%; }
  .template-settings-header { align-items: stretch; flex-direction: column; }
  .template-tabs { align-self: flex-start; }
  .wysiwyg-editor.document-sheet { min-height: 520px; padding: 26px 20px; }
  .table-inspector-grid { grid-template-columns: 1fr; }
  .table-structure-actions button.danger { margin-left: 0; }
  .modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); border-radius: 20px; }
  .modal-card { border-radius: 20px; }
  .modal-header { padding: 18px 18px 15px; }
  .modal-body { padding: 18px; max-height: calc(100vh - 104px); }
  .form-actions { bottom: -18px; }
  .document-sheet { padding: 25px 20px; }
  .doc-parties { grid-template-columns: 1fr; gap: 18px; }
  .document-sheet .doc-header { flex-direction: column; }
  .doc-status-block { text-align: left; }
  .signature-grid { grid-template-columns: 1fr; gap: 35px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .button.secondary { display: none; }
  .hero-actions { display: grid; grid-template-columns: 1fr; }
  .hero-actions .button { width: 100%; }
  .section-heading .filter-row { gap: 8px; }
  .panel { padding: 18px; }
}

@media print {
  body > *:not(.print-area) { display: none !important; }
  .modal, .modal::backdrop { display: none !important; border: 0 !important; outline: 0 !important; box-shadow: none !important; }
  .print-area { display: block !important; border: 0 !important; outline: 0 !important; box-shadow: none !important; }
  .document-sheet { min-height: 0; padding: 0; border: 0; box-shadow: none !important; filter: none !important; }
  .bilingual-sheet { font-size: 7.1px; }
  .bilingual-sheet .bilingual-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bilingual-sheet .document-language-column { padding: 0 10px; }
  @page { size: A4; margin: 18mm; }
}
