:root {
  color-scheme: light;
  --canvas: #f2f3ef;
  --surface: #ffffff;
  --surface-soft: #f8f8f5;
  --ink: #1f2724;
  --muted: #6d7671;
  --line: #dde1dc;
  --green: #176b52;
  --green-soft: #e7f3ee;
  --amber: #9a6200;
  --amber-soft: #fff1d5;
  --red: #a33a36;
  --red-soft: #fbe9e7;
  --blue: #315f9a;
  --blue-soft: #e9f0fa;
  --shadow: 0 16px 45px rgba(34, 48, 42, 0.08);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 14%, rgba(33, 116, 88, 0.12), transparent 30%),
    radial-gradient(circle at 85% 84%, rgba(209, 168, 85, 0.16), transparent 32%),
    var(--canvas);
}

.login-card {
  width: min(460px, 100%);
  padding: 48px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--green);
  color: #fff;
  font-family: "STSong", "Songti SC", serif;
  font-size: 28px;
  box-shadow: 0 10px 24px rgba(23, 107, 82, 0.22);
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 21px;
  box-shadow: none;
}

.eyebrow {
  margin: 22px 0 8px;
  color: var(--green);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.login-card h1 {
  margin-bottom: 10px;
  font-size: clamp(30px, 6vw, 42px);
  letter-spacing: -0.04em;
}

.login-intro,
.form-message {
  color: var(--muted);
  line-height: 1.65;
}

.login-intro {
  margin-bottom: 34px;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 82, 0.12);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 720;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.button.primary {
  background: var(--green);
  color: #fff;
}

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button.danger {
  background: var(--red-soft);
  color: var(--red);
}

.button.compact {
  min-height: 34px;
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 12px;
}

.button.full {
  width: 100%;
}

.notice {
  display: grid;
  gap: 5px;
  margin: 0 0 24px;
  border-radius: 14px;
  background: var(--green-soft);
  padding: 14px 16px;
  color: var(--green);
  font-size: 13px;
  line-height: 1.5;
}

.recovery-entry {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.recovery-entry summary {
  margin-bottom: 16px;
  text-align: center;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(248, 248, 245, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 30px;
}

.brand > div:last-child {
  display: grid;
  gap: 3px;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  color: var(--muted);
  font-size: 11px;
}

nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  width: 100%;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  padding: 11px 13px;
  text-align: left;
  font-size: 14px;
  font-weight: 650;
}

.nav-item:hover,
.nav-item.active {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 5px 20px rgba(35, 48, 42, 0.05);
}

.sidebar-bottom {
  margin-top: auto;
  padding: 16px 8px 4px;
  border-top: 1px solid var(--line);
}

.user-pill {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 12px;
}

.main-column {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 34px clamp(24px, 4vw, 58px) 22px;
}

.topbar .eyebrow {
  margin: 0 0 7px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(26px, 3.5vw, 38px);
  letter-spacing: -0.035em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.refresh-time {
  color: var(--muted);
  font-size: 12px;
}

.page-content {
  padding: 8px clamp(24px, 4vw, 58px) 60px;
}

.loading-card,
.empty-card {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--muted);
}

.safety-hero {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.4fr);
  gap: 18px;
  margin-bottom: 18px;
}

.status-card,
.panel,
.metric-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 8px 30px rgba(35, 48, 42, 0.04);
}

.status-card {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: 22px;
  padding: 26px;
}

.status-card.sufficient {
  background: linear-gradient(145deg, #f5fbf8, #fff);
}

.status-card.transfer_required {
  background: linear-gradient(145deg, #fff8e9, #fff);
}

.status-card.shortfall {
  background: linear-gradient(145deg, #fff1ef, #fff);
}

.status-card.needs_confirmation {
  background: linear-gradient(145deg, #f1f5fb, #fff);
}

.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 7px color-mix(in srgb, currentColor 14%, transparent);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--green);
  font-weight: 750;
}

.transfer_required .status-line {
  color: var(--amber);
}

.shortfall .status-line {
  color: var(--red);
}

.needs_confirmation .status-line {
  color: var(--blue);
}

.status-card h2 {
  margin: 14px 0 8px;
  font-size: 42px;
  letter-spacing: -0.04em;
}

.status-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.horizon {
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  min-height: 132px;
  border-radius: 18px;
  padding: 20px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(23px, 2.8vw, 32px);
  letter-spacing: -0.035em;
}

.metric-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(310px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  border-radius: 20px;
  padding: 22px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 18px;
}

.panel-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.reason-list,
.alert-list,
.plain-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reason-list li {
  position: relative;
  padding-left: 18px;
  color: #4f5954;
  font-size: 13px;
  line-height: 1.55;
}

.reason-list li::before {
  content: "";
  position: absolute;
  top: 0.65em;
  left: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.chart {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 64px 1fr 100px;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0ec;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, #1d795d, #52a88b);
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.alert-item {
  display: grid;
  grid-template-columns: 9px 1fr;
  gap: 12px;
  border-radius: 13px;
  background: var(--surface-soft);
  padding: 13px;
}

.alert-item .severity {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--amber);
}

.alert-item.critical .severity {
  background: var(--red);
}

.alert-item strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}

.alert-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.section-stack {
  display: grid;
  gap: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid #eceeeb;
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small-text {
  font-size: 11px;
}

.account-name {
  display: grid;
  gap: 4px;
  min-width: 190px;
}

.account-name span {
  color: var(--muted);
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.green {
  background: var(--green-soft);
  color: var(--green);
}

.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.red {
  background: var(--red-soft);
  color: var(--red);
}

.badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--line);
}

.summary-item {
  background: var(--surface);
  padding: 18px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.summary-item strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

.payroll-boundary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border: 1px solid #cfe2da;
  border-radius: 18px;
  background: linear-gradient(135deg, #eef8f3, #fff);
  padding: 18px 22px;
  color: var(--green);
}

.payroll-boundary strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.payroll-boundary p {
  margin: 0;
  color: #557067;
  font-size: 12px;
  line-height: 1.55;
}

.payroll-boundary > span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
  color: #557067;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.payroll-grid {
  align-items: stretch;
}

.baseline-list {
  display: grid;
  gap: 2px;
}

.baseline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid #eceeeb;
}

.baseline-row:last-child {
  border-bottom: 0;
}

.baseline-row > div {
  display: grid;
  gap: 4px;
}

.baseline-row strong {
  font-size: 13px;
}

.baseline-row span,
.baseline-row small {
  color: var(--muted);
  font-size: 11px;
}

.adjustment-list li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid #eceeeb;
}

.adjustment-list li:last-child {
  border-bottom: 0;
}

.adjustment-list li > div:first-child {
  display: grid;
  gap: 5px;
}

.adjustment-list li > div:first-child strong {
  font-size: 12px;
}

.adjustment-list li > div:first-child span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.adjustment-value {
  display: grid;
  justify-items: end;
  gap: 6px;
  flex: 0 0 auto;
}

.adjustment-value > strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.danger-text {
  color: var(--red);
}

.warning-copy {
  color: var(--amber) !important;
}

.warning-notice {
  background: var(--amber-soft);
  color: var(--amber);
}

.split-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 12px;
}

.filter-pill.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
}

.checkbox-label input {
  width: auto;
}

.dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  border: 0;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 30px 90px rgba(24, 36, 31, 0.24);
}

.dialog::backdrop {
  background: rgba(22, 30, 27, 0.38);
  backdrop-filter: blur(3px);
}

.dialog > form,
.recovery-dialog > div {
  padding: 24px;
}

.dialog header,
.dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.dialog header {
  margin-bottom: 22px;
}

.dialog header .eyebrow {
  margin: 0 0 5px;
}

.dialog h2 {
  margin: 0;
  font-size: 24px;
}

.dialog footer {
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.dialog-body {
  overflow-y: auto;
  max-height: calc(100vh - 210px);
  padding: 2px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 22px;
}

.recovery-dialog pre {
  border-radius: 14px;
  background: #17221e;
  color: #eaf3ef;
  padding: 18px;
  font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  transform: translateY(20px);
  border-radius: 13px;
  background: #1f2c27;
  color: #fff;
  padding: 13px 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  font-size: 13px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--red);
}

@media (max-width: 980px) {
  .safety-hero,
  .grid-two {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    display: block;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .sidebar .brand,
  .sidebar-bottom {
    display: none;
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
  }

  .nav-item {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
    justify-content: center;
    padding: 7px 2px;
    text-align: center;
    font-size: 9px;
  }

  .nav-item span {
    font-size: 17px;
  }

  .topbar {
    align-items: flex-start;
    padding: 24px 18px 16px;
  }

  .topbar-actions .refresh-time {
    display: none;
  }

  .page-content {
    padding: 5px 14px 100px;
  }

  .hero-metrics,
  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }

  .status-card h2 {
    font-size: 34px;
  }

  .metric-card {
    min-height: 116px;
    padding: 16px;
  }

  .metric-card strong {
    font-size: 21px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .split-controls {
    align-items: flex-start;
    flex-direction: column;
  }

  .payroll-boundary {
    align-items: flex-start;
    flex-direction: column;
  }

  .payroll-boundary > span {
    white-space: normal;
  }

  .adjustment-list li {
    flex-direction: column;
  }

  .adjustment-value {
    width: 100%;
    grid-auto-flow: column;
    justify-content: start;
    justify-items: start;
  }

  .login-card {
    padding: 34px 26px;
  }
}
