:root {
  --ink: #17211f;
  --muted: #66736f;
  --line: #d8dfdc;
  --paper: #fbfcfb;
  --surface: #ffffff;
  --sidebar: #12231f;
  --sidebar-soft: #1d3831;
  --green: #287f62;
  --green-dark: #1f654e;
  --amber: #b96f17;
  --red: #ba3c3c;
  --blue: #326f9f;
  --shadow: 0 12px 32px rgba(22, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #edf2f0;
}

.login-screen.hidden {
  display: none;
}

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

.login-brand {
  padding: 0 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

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

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.login-hint {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  color: #f4faf8;
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  color: #12231f;
  background: #a6dcc8;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.brand p,
.eyebrow {
  margin: 3px 0 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

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

.nav-tab {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  background: transparent;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  color: #ffffff;
  background: var(--sidebar-soft);
}

.side-summary {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.side-summary span {
  display: block;
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
}

.side-summary strong {
  display: block;
  margin-top: 5px;
}

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

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

.topbar .eyebrow {
  color: var(--muted);
  text-transform: uppercase;
}

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

.top-actions,
.form-actions,
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary,
.secondary,
.danger,
.ghost {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  white-space: nowrap;
}

.primary {
  color: white;
  background: var(--green);
}

.primary:hover {
  background: var(--green-dark);
}

.secondary,
.ghost {
  color: var(--ink);
  background: #edf2f0;
}

.secondary:hover,
.ghost:hover {
  background: #e2eae7;
}

.danger {
  color: #ffffff;
  background: var(--red);
}

.primary:disabled,
.secondary:disabled,
.danger:disabled,
.ghost:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.metric.emphasis {
  border-color: rgba(40, 127, 98, 0.35);
}

.metric.alert {
  border-color: rgba(186, 60, 60, 0.35);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.panel {
  margin-bottom: 16px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.filters {
  align-items: flex-start;
}

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

.pdf-import {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 14px;
  padding: 16px 16px 0;
}

.file-picker {
  align-content: start;
}

.file-picker input {
  padding: 8px 10px;
}

.pdf-result {
  min-height: 64px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.pdf-result strong {
  display: block;
  font-size: 13px;
}

.pdf-result p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pdf-candidate-select {
  margin-top: 10px;
}

.pdf-import-all {
  margin-top: 10px;
}

label {
  display: grid;
  gap: 6px;
}

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

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

input:focus,
select:focus {
  outline: 3px solid rgba(50, 111, 159, 0.18);
  border-color: var(--blue);
}

.wide {
  grid-column: span 2;
}

.form-actions {
  align-self: end;
  justify-content: flex-end;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf0ef;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #f7faf8;
  font-weight: 700;
}

td.num,
th.num {
  text-align: right;
}

td.select-col,
th.select-col {
  width: 42px;
  min-width: 42px;
  padding-right: 6px;
  text-align: center;
}

.select-col input {
  width: 17px;
  height: 17px;
  accent-color: var(--green);
}

.sort-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

th.num .sort-header {
  justify-content: flex-end;
  text-align: right;
}

.sort-header:hover,
.sort-header:focus-visible {
  color: var(--ink);
}

.sort-indicator {
  display: inline-flex;
  justify-content: center;
  min-width: 1em;
  color: var(--green);
  font-size: 11px;
}

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

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

.status.paid {
  color: #176146;
  background: #dff4eb;
}

.status.partial {
  color: #7d5215;
  background: #fff0d6;
}

.status.unpaid {
  color: #325d89;
  background: #e4f0fb;
}

.status.overdue {
  color: #9e2727;
  background: #ffe4e4;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions button {
  min-height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  color: var(--ink);
  background: #edf2f0;
}

.row-actions button:disabled {
  cursor: not-allowed;
  color: #8a9692;
  background: #f1f4f3;
}

.balance-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px 18px;
}

.balance-item {
  display: grid;
  gap: 8px;
}

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

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eeee;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--green);
}

.empty {
  padding: 22px 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #17211f;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .nav-tabs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-tab {
    text-align: center;
  }

  .side-summary {
    display: none;
  }

  .metrics,
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 680px) {
  .main {
    padding: 16px;
  }

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

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 30%;
  }

  .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics,
  .dashboard-grid,
  .form-grid,
  .pdf-import {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-row {
    width: 100%;
  }

  th,
  td {
    padding: 10px;
    font-size: 13px;
  }
}
