:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --line: #d0d5dd;
  --line-soft: #eaecf0;
  --surface: #fcfcfd;
  --surface-muted: #f8fafc;
  --neutral-050: #f2f4f7;
  --text: #111827;
  --muted: #475467;
  --muted-soft: #667085;
  --primary: #14532d;
  --primary-600: #1a6b3a;
  --primary-050: #ecfdf3;
  --primary-border: rgba(20, 83, 45, 0.35);
  --primary-border-soft: rgba(20, 83, 45, 0.24);
  --primary-ink: #ffffff;
  --ring: rgba(20, 83, 45, 0.18);
  --danger: #b42318;
  --danger-050: #fef3f2;
  --danger-border: rgba(180, 35, 24, 0.48);
  --danger-border-soft: rgba(180, 35, 24, 0.38);
  --danger-line: #fecdca;
  --info: #175cd3;
  --info-050: #eff8ff;
  --warning: #b54708;
  --warning-050: #fffaeb;
  --warning-border: rgba(245, 158, 11, 0.42);
  --warning-border-soft: rgba(245, 158, 11, 0.35);
  --required: #f59e0b;
  --chart-track: #eef2f6;
  --overlay: rgba(247, 248, 250, 0.66);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 18px rgba(16, 24, 40, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

.brand-mark {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 12px;
  letter-spacing: 0;
}

.brand.active,
.brand:hover {
  color: var(--primary);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.125em;
}

.brand .nav-icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
}

.top-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.top-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.top-link:hover {
  color: var(--primary);
  background: var(--primary-050);
}

.top-link.active {
  color: var(--primary);
  background: var(--primary-050);
}

.top-link.active::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: 3px;
  left: 10px;
  height: 2px;
  border-radius: 999px;
  background: var(--primary);
}

.license-nav {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

.license-user,
.license-offline {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--neutral-050);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.license-offline {
  background: var(--warning-050);
  color: var(--warning);
}

.steps {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  white-space: nowrap;
}

.step {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.step.active {
  color: var(--primary);
  border-color: var(--primary-border);
  background: var(--primary-050);
}

.demo-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--warning-border-soft);
  background: var(--warning-050);
  color: var(--text);
}

.demo-banner strong {
  color: var(--warning);
  font-weight: 900;
}

.demo-banner form {
  margin-left: auto;
}

.page { padding: 28px; }

.panel {
  max-width: 1280px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px;
  box-shadow: var(--shadow-sm);
}

.panel + .panel,
.history-panel {
  margin-top: 18px;
}

.panel.narrow { max-width: 760px; }

.login-panel {
  max-width: 520px;
}

.login-form {
  max-width: 420px;
}

.login-error {
  border: 1px solid var(--danger-border-soft);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--danger-050);
  color: var(--danger);
  font-weight: 700;
}

.home-dashboard {
  display: grid;
  grid-template-columns: minmax(420px, 460px) 1fr;
  gap: 20px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
}

.home-dashboard .panel {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin: 0;
}

.home-dashboard .panel + .panel,
.home-dashboard .history-panel {
  margin-top: 0;
}

.home-data-panel {
  grid-column: 1 / -1;
}

h1 {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
}

.muted {
  margin: 4px 0 0;
  color: var(--muted-soft);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.actions,
.toolbar,
.tabs,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid label,
.form-row label,
.filter-bar label,
.tieout-bar label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.form-grid label:has(> input[type="checkbox"]),
.form-row label:has(> input[type="checkbox"]) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}

.form-grid label:has(> input[type="radio"]),
fieldset label:has(> input[type="radio"]) {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

input,
select,
button {
  font: inherit;
}

input:not([type="checkbox"]):not([type="radio"]),
select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: none;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

input[type="radio"] {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 13px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
.button:hover {
  border-color: var(--primary-border-soft);
  background: var(--primary-050);
}

button:focus-visible,
.button:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
  font-weight: 800;
}

.primary:hover {
  background: var(--primary-600);
  border-color: var(--primary-600);
}

.danger-button {
  color: var(--danger);
  border-color: var(--danger-border-soft);
}

.danger-button:hover {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-050);
}

.button[aria-pressed="true"] {
  border-color: var(--danger-border);
  color: var(--danger);
  background: var(--danger-050);
  font-weight: 800;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

fieldset:not(.form-section) {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

legend {
  padding: 0 4px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.filter-bar,
.tieout-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tieout-bar input { width: 240px; }

.tabs {
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.tab {
  min-height: 38px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}

.tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-050);
  font-weight: 800;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--neutral-050);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.error-badge {
  background: var(--danger-050);
  color: var(--danger);
}

.save-status {
  min-width: 92px;
  color: var(--muted-soft);
  font-size: 12px;
}

.save-status.error { color: var(--danger); }

.policy-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.policy-list {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.policy-list-title {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.policy-list table tr { cursor: pointer; }

.policy-list table tr.selected-row td {
  background: var(--primary-050);
  color: var(--primary);
  font-weight: 800;
}

.policy-form {
  align-content: start;
}

.form-section {
  display: grid;
  gap: 14px;
  padding: 20px;
  border-radius: 10px;
  background: var(--surface);
}

.form-section legend {
  margin-left: -4px;
}

.policy-form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}

.grid {
  width: 100%;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.master-grid { min-height: 520px; }

.handsontable td.invalid-cell {
  background: var(--danger-050) !important;
}

.handsontable td.unused-cap-warning-cell {
  background: var(--warning-050) !important;
  box-shadow: inset 0 -2px 0 var(--warning-border);
}

.handsontable td.required-cell {
  box-shadow: inset 3px 0 0 var(--required);
}

.handsontable td.auto-liability-preview,
.handsontable td.accrual-suggested-cell {
  background: var(--neutral-050) !important;
  color: var(--muted-soft);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 15px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  line-height: 1.2;
}

.status-ok strong { color: var(--primary); }
.status-error strong { color: var(--danger); }
.status-muted strong { color: var(--muted); }

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-badge.status-calculated {
  border-color: var(--primary-border-soft);
  background: var(--primary-050);
  color: var(--primary);
}

.status-badge.status-closed {
  border-color: var(--warning-border);
  background: var(--warning-050);
  color: var(--warning);
}

.emp-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.emp-type-continuing {
  background: var(--neutral-050);
  color: var(--muted);
}

.emp-type-new {
  background: var(--info-050);
  color: var(--info);
}

.emp-type-prior-only {
  background: var(--danger-050);
  color: var(--danger);
  border: 1px solid var(--danger-line);
}

.result-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.result-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 10px;
  white-space: nowrap;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover td {
  background: var(--surface);
}

.table-caption {
  caption-side: top;
  padding: 9px 10px;
  text-align: left;
  color: var(--muted);
  font-weight: 800;
}

.amount-cell { text-align: right; }

#runs-table th,
#runs-table td {
  padding-top: 6px;
  padding-bottom: 6px;
}

#runs-table {
  min-width: 700px;
}

#runs-table .row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

#runs-table .run-actions-header,
#runs-table .run-actions-cell {
  width: 136px;
  min-width: 136px;
}

#runs-table .run-actions-cell {
  padding-left: 6px;
  padding-right: 6px;
}

#runs-table .row-actions .button {
  flex: 0 0 auto;
  min-width: 38px;
  min-height: 28px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.1;
}

.cash-reference-cell {
  color: var(--muted-soft);
  font-weight: 400;
}

.drilldown-row { cursor: pointer; }
.drilldown-row:hover { background: var(--surface-muted); }

.positive {
  color: var(--danger);
  font-weight: 800;
}

.negative {
  color: var(--info);
  font-weight: 800;
}

.cash-banner {
  position: sticky;
  bottom: 0;
  margin-top: 20px;
  padding: 12px 20px;
  background: var(--warning-050);
  border-top: 1px solid var(--warning-border-soft);
  color: var(--warning);
  text-align: center;
  font-weight: 800;
}

.remap-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.remap-control input {
  width: 110px;
  height: 32px;
}

.bridge-chart {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.bridge-verification {
  margin-bottom: 10px;
  font-weight: 800;
}

.bridge-waterfall {
  display: grid;
  gap: 10px;
}

.bridge-step {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr minmax(100px, auto);
  align-items: center;
  gap: 10px;
}

.bridge-step span {
  color: var(--muted);
  font-size: 13px;
}

.bridge-step strong { text-align: right; }

.bridge-bar-track {
  height: 16px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--chart-track);
}

.bridge-bar {
  height: 100%;
  min-width: 2px;
  background: var(--info);
}

.bridge-down .bridge-bar { background: var(--danger); }
.bridge-base .bridge-bar { background: var(--primary); }

.trend-chart {
  min-height: 280px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.trend-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.trend-chart text {
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  font-size: 12px;
  fill: var(--muted);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 14px;
  color: var(--muted);
  text-align: center;
  background: var(--panel);
}

.rollup-parent {
  background: var(--surface-muted);
  font-weight: 800;
  cursor: pointer;
}

.rollup-child td:first-child { background: var(--panel); }

.row-toggle {
  min-height: 24px;
  width: 26px;
  padding: 0;
  margin-right: 4px;
  border-color: transparent;
  background: transparent;
  font-weight: 800;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  display: grid;
  gap: 8px;
  max-width: min(360px, calc(100vw - 40px));
}

.toast {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--text);
  color: var(--primary-ink);
  box-shadow: var(--shadow-md);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-success { background: var(--primary); }
.toast-error { background: var(--danger); }

.toast-hide {
  opacity: 0;
  transform: translateY(8px);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  background: var(--overlay);
}

.loading-overlay[hidden] { display: none; }

.loading-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  font-weight: 800;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
  }

  .top-links {
    justify-content: flex-start;
  }

  .license-nav {
    justify-content: flex-start;
  }

  .steps {
    justify-content: flex-start;
  }

  .home-dashboard {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .page { padding: 14px; }

  .panel {
    padding: 20px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .policy-layout {
    grid-template-columns: 1fr;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .bridge-step {
    grid-template-columns: 1fr;
  }

  .bridge-step strong {
    text-align: left;
  }
}
