:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #162033;
  --muted: #6b7280;
  --line: #dde3ec;
  --primary: #116a7b;
  --primary-strong: #0b4d59;
  --accent: #d58a2a;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --ok: #157f3b;
  --warn: #a15c07;
  --shadow: 0 18px 40px rgba(24, 38, 63, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #10283a;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.24);
}

.login-status {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #e5b8b0;
  border-radius: 6px;
  background: #fff4f2;
  color: #9f2d20;
  font-size: 13px;
  line-height: 1.5;
}

.login-brand {
  padding: 0 0 8px;
  color: var(--ink);
}

.login-brand p {
  color: var(--muted);
}

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

.sidebar {
  background: #10283a;
  color: #ffffff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 6px 24px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #111827;
  border-radius: 8px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.brand p,
.eyebrow {
  margin: 3px 0 0;
  color: #b7c4d3;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.utility-button,
.seg {
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.nav-item {
  width: 100%;
  color: #d9e4ee;
  background: transparent;
  padding: 12px;
  justify-content: flex-start;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-item svg,
.primary-button svg,
.utility-button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.topbar h2 {
  margin: 2px 0 0;
  font-size: 28px;
}

.top-actions,
.form-actions,
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.role-badge {
  min-height: 40px;
  display: grid;
  align-content: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.role-badge span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.role-badge strong {
  font-size: 14px;
}

.permission-list {
  margin: 0;
  padding-left: 20px;
  color: #334155;
  line-height: 1.9;
}

.primary-button {
  min-height: 40px;
  padding: 0 14px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.primary-button.danger {
  background: var(--danger);
}

.secondary-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.ghost-button,
.seg {
  min-height: 36px;
  padding: 0 12px;
  background: #eef3f7;
  color: var(--ink);
}

.table-action {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.table-action svg {
  width: 15px;
  height: 15px;
}

.table-action.delete {
  color: var(--danger);
}

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

.inline-bank-action {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 300px;
}

.inline-bank-action select {
  min-width: 220px;
  max-width: 320px;
}

.seg.active {
  background: #d6efe9;
  color: var(--primary-strong);
  font-weight: 700;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
}

.compact-icon-button {
  width: 32px;
  height: 32px;
}

.compact-icon-button svg {
  width: 15px;
  height: 15px;
}

.utility-button {
  min-height: 40px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
  white-space: nowrap;
}

.utility-button:hover {
  background: #eef3f7;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-grid.five-column {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi,
.panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.kpi.warning strong {
  color: var(--danger);
}

.content-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.panel,
.form-panel {
  padding: 16px;
}

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

.panel-heading h3 {
  margin: 0;
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.audit-table {
  min-width: 980px;
}

.bank-table {
  min-width: 1120px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.audit-detail {
  white-space: normal;
  min-width: 320px;
  line-height: 1.6;
}

.wrap-cell {
  min-width: 180px;
  white-space: normal;
  line-height: 1.55;
}

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

textarea {
  width: 100%;
  min-height: 120px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: #ffffff;
  resize: vertical;
  font: inherit;
}

th {
  background: #f0f4f8;
  color: #39465a;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

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

.annual-table {
  max-height: calc(100vh - 170px);
}

.annual-table table {
  min-width: 3600px;
}

.activity-list {
  display: grid;
  gap: 10px;
}

.activity {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.activity strong {
  display: block;
  margin-bottom: 4px;
}

.activity span {
  color: var(--muted);
  font-size: 13px;
}

.notice-panel {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid #cfe0ea;
  border-radius: 8px;
  background: #f7fbfd;
  color: #334155;
  line-height: 1.7;
}

.notice-panel strong {
  display: block;
  margin-bottom: 4px;
  color: var(--primary-strong);
}

.notice-panel p {
  margin: 4px 0 0;
}

.toolbar-summary {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.reconciliation-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 4px solid #94a3b8;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.reconciliation-panel > div {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.reconciliation-panel > div:last-child {
  border-right: 0;
}

.reconciliation-panel span,
.reconciliation-panel strong {
  display: block;
}

.reconciliation-panel span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.reconciliation-panel strong {
  overflow-wrap: anywhere;
  font-size: 18px;
}

.reconciliation-panel.ok {
  border-left-color: var(--ok);
}

.reconciliation-panel.error {
  border-left-color: var(--danger);
}

.reconciliation-panel.error > div:last-child strong,
.reconciliation-panel.blocked > div:last-child strong {
  color: var(--danger);
}

.initial-import-table {
  min-width: 1540px;
}

.initial-import-table-wrap {
  max-height: 52vh;
}

.monthly-import-table-wrap {
  max-height: 52vh;
}

.monthly-import-error-table {
  min-width: 860px;
}

.monthly-import-error-table th:nth-child(3),
.monthly-import-error-table th:nth-child(4) {
  min-width: 260px;
}

.workflow-status {
  min-height: 42px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 4px solid var(--primary);
  background: #eef6f7;
  color: #334155;
  line-height: 1.55;
}

.initial-import-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.confirmation-check {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: flex-start;
  gap: 10px;
  font-weight: 600;
  line-height: 1.6;
}

.confirmation-check input {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  margin-top: 2px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: #ffffff;
}

input:focus,
select:focus {
  outline: 3px solid rgba(17, 106, 123, 0.16);
  border-color: var(--primary);
}

.wide {
  grid-column: span 3;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.form-error {
  margin: 0;
  padding: 9px 11px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.toolbar label {
  min-width: 220px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  width: 100%;
}

.inline-form label {
  min-width: 220px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.active,
.status.ok {
  background: #e7f7ed;
  color: var(--ok);
}

.status.inactive,
.status.overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.status.dueToday {
  background: #fff7df;
  color: var(--warn);
}

.status.missing {
  background: #eef2ff;
  color: #3442a8;
}

.status.review {
  background: #fff7df;
  color: var(--warn);
}

.status.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.mt {
  margin-top: 16px;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.26);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.46);
}

dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-surface {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.ledger-dialog {
  width: min(1080px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
}

.ledger-dialog .dialog-surface {
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}

.detail-command-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.ledger-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.overpayment-amount {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--warning-line, var(--line));
  border-radius: 8px;
  background: var(--warning-soft, #fff8e8);
}

.overpayment-amount[hidden] {
  display: none;
}

.overpayment-amount span {
  color: var(--muted);
  font-size: 13px;
}

.overpayment-amount strong {
  color: var(--danger);
  font-size: 20px;
}

.ledger-summary > div {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.ledger-summary > div:last-child {
  border-right: 0;
}

.ledger-summary span,
.ledger-summary strong {
  display: block;
}

.ledger-summary span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.ledger-summary strong {
  overflow-wrap: anywhere;
  font-size: 18px;
}

.ledger-section {
  min-width: 0;
}

.ledger-section .panel-heading h3 {
  font-size: 15px;
}

.ledger-table {
  min-width: 880px;
}

.detail-action-list {
  display: flex;
  width: 176px;
  gap: 6px;
  flex-wrap: wrap;
}

.payment-dialog {
  width: min(760px, calc(100vw - 28px));
}

.allocation-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.allocation-table {
  min-width: 640px;
}

.allocation-table-wrap {
  max-height: 280px;
}

.allocation-input {
  width: 128px;
  min-height: 36px;
}

.locked-dialog {
  width: min(460px, calc(100vw - 28px));
}

.locked-dialog::backdrop {
  background: rgba(15, 23, 42, 0.72);
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-heading h3 {
  margin: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #10283a;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(90px);
  opacity: 0;
  transition: 0.2s ease;
}

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

@media (max-width: 960px) {
  .app-shell {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 12px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    width: auto;
    white-space: nowrap;
  }

  .main {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 16px;
  }

  .kpi-grid,
  .kpi-grid.five-column,
  .content-grid,
  .form-grid,
  .reconciliation-panel,
  .ledger-summary {
    grid-template-columns: 1fr;
  }

  .reconciliation-panel > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .reconciliation-panel > div:last-child {
    border-bottom: 0;
  }

  .ledger-summary > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .ledger-summary > div:last-child {
    border-bottom: 0;
  }

  .initial-import-confirm {
    align-items: stretch;
    flex-direction: column;
  }

  .initial-import-confirm .primary-button {
    width: 100%;
  }

  .wide {
    grid-column: span 1;
  }

  .topbar {
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-actions > *,
  .top-actions .year-picker input {
    width: 100%;
    min-width: 0;
  }

  .toolbar,
  .form-panel,
  .notice-panel,
  .table-wrap {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .toolbar .primary-button {
    flex: 1 1 150px;
  }

  .monthly-import-toolbar > button {
    flex: 1 1 170px;
  }

  .allocation-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

.year-picker {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.year-picker input {
  width: 88px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}
