:root {
  --sidebar: #131b2e;
  --sidebar-text: #bec6e0;
  --sidebar-muted: #bec6e0;
  --accent: #006e2f;
  --accent-2: #005321;
  --accent-bright: #4ae176;
  --accent-container: #22c55e;
  --bg: #f8f9ff;
  --surface: #f8f9ff;
  --surface-low: #eff4ff;
  --surface-container: #e5eeff;
  --surface-high: #dce9ff;
  --surface-highest: #d3e4fe;
  --card: #ffffff;
  --text: #0b1c30;
  --text-variant: #3d4a3d;
  --muted: #565e74;
  --muted-dim: #bec6e0;
  --line: #bccbb9;
  --line-soft: rgba(188, 203, 185, 0.35);
  --danger: #ba1a1a;
  --danger-container: #ffdad6;
  --warn: #9a6b09;
  --info: #2e86c1;
  --radius: 0.5rem;
  --radius-xl: 0.75rem;
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
  --font: "Hanken Grotesk", "Segoe UI", Tahoma, sans-serif;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: "liga";
  font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  width: 1.15em;
  height: 1.15em;
  overflow: hidden;
  flex-shrink: 0;
  speak: never;
}

/* —— Login —— */
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #131b2e, #006e2f 160%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line-soft);
}
.login-brand { font-size: 22px; font-weight: 700; color: var(--text); text-align: center; }
.login-brand img {
  display: block;
  width: 90px;
  height: auto;
  margin: 0 auto 8px;
  background: transparent;
}
.login-sub { color: var(--muted); margin: 6px 0 22px; text-align: center; font-size: 14px; }
.login-card label, .form-grid label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-variant);
  margin-bottom: 12px;
}
.pwd-field {
  position: relative;
  display: block;
  margin-top: 6px;
}
.pwd-field input {
  margin-top: 0;
  padding-right: 44px;
}
.pwd-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-xl);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.pwd-toggle:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.04);
}
.pwd-toggle .material-symbols-outlined {
  font-size: 20px;
}
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 110, 47, 0.15);
}
textarea { min-height: 70px; resize: vertical; }
.form-error { color: var(--danger); font-size: 13px; }
.login-hint {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-variant);
}
.login-hint.muted { color: var(--muted); }
.login-qr-wrap {
  display: flex;
  justify-content: center;
  margin: 0 0 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
}
.login-secret {
  font-size: 12px;
  word-break: break-all;
  margin: 0 0 16px;
}
.login-secret code {
  font-size: 12px;
  letter-spacing: 0.04em;
}
.login-backup-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}
.login-backup-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--surface-low);
  border-radius: var(--radius-xl);
  border: 1px solid var(--line-soft);
}
.login-backup-list code {
  font-size: 13px;
  letter-spacing: 0.06em;
}

/* —— App shell —— */
.app-body { display: flex; min-height: 100%; }
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow-y: auto;
  z-index: 50;
}
.brand {
  padding: 24px 24px 8px;
  font-weight: 700;
  color: #fff;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}
.brand img {
  width: 100%;
  max-width: 100px;
  height: auto;
  display: block;
  background: transparent;
}
.sidebar nav {
  flex: 1;
  padding: 8px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 12px 16px;
  border-radius: var(--radius-xl);
  border-left: 4px solid transparent;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a .material-symbols-outlined {
  font-size: 22px;
  color: inherit;
  transition: color 0.15s;
}
.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}
.sidebar nav a:hover .material-symbols-outlined {
  color: var(--accent-bright);
}
.sidebar nav a.active {
  background: rgba(34, 197, 94, 0.2);
  color: var(--accent-bright);
  border-left-color: var(--accent-bright);
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}
.topbar {
  background: var(--card);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
  color: var(--text);
}
.topbar-actions { display: flex; gap: 16px; align-items: center; }
.user-name {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
#btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  box-shadow: none;
}
#btn-logout:hover {
  background: transparent;
  color: var(--danger);
}
#btn-logout .material-symbols-outlined { font-size: 18px; }
.content {
  padding: 24px 32px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* —— KPIs / cards —— */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line-soft);
}
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.kpi .hint { color: var(--muted-dim, #8a96a3); font-size: 11px; margin-top: 4px; }
.kpi.received .value { color: var(--accent); }
.kpi.pending .value { color: var(--warn); }

.accounts-ledger-kpis { margin-bottom: 16px; }
.accounts-opening-wrap { margin-bottom: 14px; }
.accounts-opening-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  text-align: left;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 13px;
}
.accounts-opening-toggle .material-symbols-outlined {
  color: var(--muted);
  font-size: 20px;
}
.accounts-opening-toggle.is-open {
  border-color: var(--line);
  margin-bottom: 8px;
}
.accounts-opening-card .form-grid.readonly input,
.accounts-opening-card .form-grid.readonly select {
  opacity: 0.85;
  background: var(--surface-container, #f3f5f7);
}
.kpi-split {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}
.kpi-split > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  line-height: 1.3;
}
.kpi-split-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: 11px;
}
.kpi-split-val { font-weight: 600; }
.kpi.received .kpi-split > div:last-child .kpi-split-val { color: var(--accent); }
.kpi.pending .kpi-split > div:last-child .kpi-split-val { color: var(--warn); }
.accounts-ledger-table th.grp-pay,
.accounts-ledger-table td:nth-child(n+4):nth-child(-n+6) { color: var(--accent); }
.accounts-ledger-table th.grp-exp,
.accounts-ledger-table td:nth-child(n+7):nth-child(-n+9) { color: var(--warn); }
.accounts-ledger-table td.num,
.accounts-ledger-table th.grp-pay,
.accounts-ledger-table th.grp-exp,
.accounts-ledger-table th.grp-bal {
  text-align: right;
  white-space: nowrap;
}
.accounts-ledger-table thead th {
  vertical-align: bottom;
}
.accounts-ledger-opening td {
  background: rgba(86, 94, 116, 0.06);
  font-weight: 500;
}
.accounts-ledger-closing td {
  background: rgba(0, 110, 47, 0.08);
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.collections-summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}
.collections-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.collections-tile {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.collections-tile:hover {
  border-color: var(--line);
}
.collections-tile.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 110, 47, 0.25);
}
.collections-tile-title {
  font-weight: 700;
  font-size: 15px;
}
.collections-tile-sub {
  font-size: 12px;
  margin-top: 2px;
}
@media (max-width: 960px) {
  .collections-tiles { grid-template-columns: 1fr; }
}
.collections-stat {
  font-weight: 700;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.collections-stat-count {
  color: #334155;
  background: rgba(51, 65, 85, 0.1);
}
.collections-stat-total {
  color: #1d4ed8;
  background: rgba(29, 78, 216, 0.1);
}
.collections-stat-received {
  color: var(--accent);
  background: rgba(0, 110, 47, 0.1);
}
.collections-stat-pending {
  color: var(--warn);
  background: rgba(154, 107, 9, 0.12);
}
.collections-table .th-sum.collections-stat-total { color: #1d4ed8; }
.collections-table .th-sum.collections-stat-received { color: var(--accent); }
.collections-table .th-sum.collections-stat-pending { color: var(--warn); }

.dash-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.dash-chart-card .dash-chart-body {
  height: 280px;
  padding: 8px 16px 4px;
}
.dash-chart-note {
  padding: 0 20px 16px;
  margin: 0;
  font-size: 12px;
}
@media (max-width: 960px) {
  .dash-charts { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
}
.card-title-block {
  min-width: 0;
  flex: 1;
}
.th-sum {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  width: auto;
  min-width: 160px;
  margin: 0;
  padding: 8px 14px;
  font-size: 14px;
}

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th, table.data td {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(188, 203, 185, 0.25);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
table.data th {
  background: var(--surface-low);
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
table.data td.r, table.data th.r { text-align: center; }
table.data tbody tr:hover { background: rgba(248, 249, 255, 0.6); }
.cell-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  white-space: normal;
  line-height: 1.25;
}
.cell-title { font-weight: 600; color: var(--text); }
.cell-desc { font-size: 11px; color: var(--muted-dim); font-weight: 500; }
.cell-desc .badge { margin-top: 2px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: capitalize;
  width: fit-content;
}
.badge.draft { background: var(--surface-container); color: var(--muted); }
.badge.published, .badge.sent, .badge.accepted, .badge.paid {
  background: rgba(0, 110, 47, 0.1);
  color: var(--accent);
}
.badge.unpaid, .badge.rejected { background: var(--danger-container); color: #93000a; }
.badge.partial, .badge.converted { background: #fef6e6; color: var(--warn); }
.badge.cancelled { background: #eef1f4; color: #566573; }
.badge.completed { background: #e8f5e9; color: #1b5e20; }

.proposal-tabs {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--surface-container);
  flex-shrink: 0;
}
.proposal-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-right: 1px solid var(--line);
}
.proposal-tab:last-child { border-right: 0; }
.proposal-tab:hover { background: var(--surface-high); color: var(--accent); }
.proposal-tab.is-active {
  background: var(--accent);
  color: #fff;
}
.proposal-embed {
  border-top: 1px solid var(--line);
  background: var(--bg);
  min-height: 280px;
}
.proposal-embed .table-wrap {
  background: var(--card);
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface-container);
  color: var(--accent);
  padding: 8px 16px;
  border-radius: var(--radius-xl);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-high); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 110, 47, 0.25);
}
.btn-primary:hover {
  background: var(--accent-container);
  border-color: var(--accent-container);
  color: #004b1e;
}
.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: #f5c6cb;
}
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 10px; font-size: 12px; letter-spacing: 0; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
}
.btn-icon:hover {
  background: rgba(0, 110, 47, 0.06);
  color: var(--accent);
}
.btn-icon svg { display: block; }
.toolbar select { min-width: 140px; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; justify-content: center; }
.row-cancelled td {
  background: #fdecea !important;
  color: #b71c1c;
}
.row-cancelled .badge {
  background: #ffcdd2;
  color: #b71c1c;
}
.checkbox-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent, #1b7a4a);
}
.row-actions-inline { flex-wrap: nowrap; white-space: nowrap; }
.company-status-btn {
  min-width: 72px;
  padding: 4px 10px !important;
  font-size: 12px !important;
  font-weight: 600;
  border: 0 !important;
  color: #fff !important;
}
.company-status-btn.is-active {
  background: #1b7a4a !important;
}
.company-status-btn.is-inactive {
  background: #c62828 !important;
}
.company-status-btn:hover { filter: brightness(1.05); }

.gst-paid-select {
  width: auto !important;
  min-width: 0;
  max-width: 118px;
  margin: 0 !important;
  padding: 4px 6px !important;
  font-size: 11px !important;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--radius-xl);
  cursor: pointer;
}
.gst-paid-select.is-paid {
  background: rgba(0, 110, 47, 0.1);
  color: var(--accent);
  border-color: rgba(0, 110, 47, 0.25);
}
.gst-paid-select.is-unpaid {
  background: var(--danger-container);
  color: #93000a;
  border-color: #f5c6cb;
}

.company-workspace {
  margin-bottom: 24px;
}
.company-workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line-soft);
}
.company-workspace-toolbar label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}
.company-workspace-toolbar select {
  min-width: min(420px, 100%);
  font-weight: 500;
}
.company-view-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: var(--surface-container);
  border-radius: var(--radius-xl);
  border: 1px solid var(--line-soft);
}
.company-view-tabs .btn {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
.company-view-tabs .btn.is-active {
  background: var(--card);
  color: var(--accent);
  border-color: var(--line);
  box-shadow: 0 1px 3px rgba(15, 39, 68, 0.08);
}
.company-iframe-shell {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--bg);
  min-height: 420px;
  max-height: calc(100vh - 260px);
  overflow: auto;
}
.company-view-pane {
  padding: 24px;
}
.company-view-pane[hidden] { display: none; }
.company-view-pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.company-view-pane-head h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
}
.company-view-pane-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.company-view-pane.readonly input,
.company-view-pane.readonly select,
.company-view-pane.readonly textarea {
  background: var(--surface-low);
  pointer-events: none;
  color: var(--text);
}
.email-section-card {
  margin: 0 0 16px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  background: var(--card);
}
.email-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.email-section-head h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.email-section-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.mail-body-frame {
  padding: 12px;
  background: var(--surface-low);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.mail-fixed-line {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.mail-signature-preview {
  margin-top: 12px;
  white-space: pre-line;
  color: var(--muted, #64748b);
  font-weight: 400;
}
.mail-body-frame textarea {
  margin-top: 4px;
  background: #fff;
}

.modal { position: fixed; inset: 0; z-index: 20; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 39, 68, 0.45); }
.modal-panel {
  position: relative;
  z-index: 1;
  background: #fff;
  width: min(980px, calc(100% - 32px));
  max-height: calc(100% - 40px);
  overflow: auto;
  margin: 20px auto;
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-panel.wide { width: min(1180px, calc(100% - 24px)); }
.modal-panel h2 { margin: 0 0 4px; font-weight: 600; }
.doc-form-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.doc-form-head-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.doc-serial {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.doc-serial strong { color: var(--text); font-size: 16px; font-weight: 600; }
.doc-serial-input {
  width: min(220px, 100%);
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.invoice-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  gap: 24px;
  align-items: start;
  padding: 8px 0 0;
}
.invoice-lines-col { min-width: 0; }
.invoice-calc-col {
  position: sticky;
  top: 80px;
  align-self: start;
}
#notes-rte, #notes-rte * { font-weight: 400; }
#notes-rte b, #notes-rte strong { font-weight: 700; }

.line-card {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-bottom: 16px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.line-card-saved {
  padding: 12px 16px;
  background: var(--card);
}
.line-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.line-card-head strong {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.line-card-saved .line-card-head { margin-bottom: 0; }
.line-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.line-expand {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  text-align: left;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-expand:hover { color: var(--accent); }
.line-card label { margin-bottom: 12px; }
.line-money, .line-discount {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* —— Rich text (mockup style) —— */
.rte-box {
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rte-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 110, 47, 0.15);
}
.rte-bar {
  display: flex;
  gap: 4px;
  padding: 8px;
  margin: 0;
  background: var(--surface-low);
  border-bottom: 1px solid rgba(188, 203, 185, 0.5);
}
.rte-bar .rte-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.rte-bar .rte-btn:hover {
  background: var(--surface-highest);
  color: var(--text);
}
.rte-bar .rte-btn .material-symbols-outlined {
  font-size: 18px;
}
.rte {
  min-height: 88px;
  border: 0;
  border-radius: 0;
  padding: 14px 16px;
  background: transparent;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  color: var(--text);
}
.rte:focus { border-color: transparent; box-shadow: none; }
.rte:empty:before {
  content: attr(data-placeholder);
  color: var(--muted-dim);
  pointer-events: none;
}
.line-card .rte { min-height: 80px; }

.sticky-totals {
  position: sticky;
  top: 80px;
  width: 100%;
  margin: 0;
  padding: 24px;
  border: 1px solid rgba(188, 203, 185, 0.2);
  border-radius: var(--radius-xl);
  background: var(--surface-highest);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.sticky-totals h3 {
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 20px;
  font-weight: 600;
}
.sticky-totals .grand {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px solid rgba(188, 203, 185, 0.5);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
}
.payment-breakup {
  background: var(--surface-highest);
  border: 1px solid rgba(188, 203, 185, 0.2);
  border-radius: var(--radius-xl);
  padding: 16px 20px;
  max-width: 420px;
}
.payment-breakup h3 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}
.payment-breakup div {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  color: var(--muted);
  font-size: 14px;
}
.payment-breakup .grand {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  color: var(--accent);
  font-weight: 700;
}
.payment-tds-confirm {
  color: var(--text) !important;
  display: block !important;
  font-size: 13px;
  font-weight: 600;
}
.payment-tds-confirm select {
  width: auto !important;
  min-width: 200px;
  margin-top: 6px;
  display: block;
}
.payment-line { background: var(--card); }
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.preview-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 140px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--bg);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
}
.form-grid.doc-meta {
  grid-template-columns: minmax(0, 1.4fr) minmax(140px, 1fr) minmax(140px, 1fr);
}
.form-grid.client-meta-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.form-grid .full { grid-column: 1 / -1; }
.expand-panel {
  margin: 0 0 24px;
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}
.expand-panel[hidden] { display: none; }
.expand-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--card);
}
.expand-panel-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
}
.expand-panel-actions { display: flex; gap: 10px; flex-shrink: 0; }
.expand-panel-body { padding: 24px; }
.expand-panel-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line-soft);
  background: var(--card, #fff);
}
.expand-panel.readonly input,
.expand-panel.readonly select {
  background: var(--surface-low);
  pointer-events: none;
  color: var(--text);
}
.expand-panel.readonly .rte-box {
  background: var(--surface-low);
}
.expand-panel.readonly .rte {
  background: transparent;
  pointer-events: none;
}
.logo-empty-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  min-width: 160px;
  padding: 12px 16px;
  border: 1px dashed var(--line-soft, #c9d4e0);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-low, #f4f8fb);
}
.logo-scale-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}
.logo-scale-row input[type="range"] {
  flex: 1;
  padding: 0;
  background: transparent;
}
.logo-scale-row span {
  min-width: 48px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.line-card-summary .line-expand {
  cursor: default;
}
.items-table input, .items-table select { margin: 0; padding: 6px; }
.totals {
  margin-top: 12px;
  margin-left: auto;
  width: 100%;
}
.totals div { display: flex; justify-content: space-between; padding: 6px 0; color: var(--muted); }
.totals .grand {
  font-weight: 700;
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
  padding-top: 8px;
  color: var(--accent);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 900px) {
  .app-body { flex-direction: column; }
  .sidebar {
    position: relative;
    left: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    box-shadow: none;
    z-index: 1;
  }
  .main { margin-left: 0; }
  .sidebar nav {
    flex-direction: row;
    overflow: auto;
    padding: 8px;
  }
  .sidebar nav a {
    white-space: nowrap;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }
  .sidebar nav a.active {
    border-radius: var(--radius-xl);
    border-left: 0;
    border-bottom-color: var(--accent-bright);
  }
  .brand { padding: 16px; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .form-grid, .form-grid.doc-meta, .form-grid.client-meta-3 { grid-template-columns: 1fr; }
  .invoice-split, .line-money, .line-discount { grid-template-columns: 1fr; }
  .invoice-calc-col, .sticky-totals { position: static; }
}
