:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-alt: #eef2ec;
  --ink: #1d2422;
  --muted: #65706c;
  --line: #dce2dc;
  --primary: #0f7a6c;
  --primary-dark: #0a5e53;
  --accent: #b7791f;
  --danger: #b42318;
  --success: #247a38;
  --steel: #3d5360;
  --shadow: 0 18px 42px rgba(23, 32, 30, 0.08);
  --radius: 8px;
  --sidebar: #17201d;
  --sidebar-soft: #23302c;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 122, 108, 0.12), rgba(183, 121, 31, 0.10)),
    var(--bg);
}

.login-card {
  width: min(960px, 100%);
  min-height: 560px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  align-items: flex-start;
  flex-direction: column;
  justify-content: flex-end;
  padding: 34px;
  background: var(--sidebar);
  color: #ffffff;
}

.login-brand .brand-mark {
  width: 72px;
  height: 72px;
}

.login-brand h1 {
  font-size: 2.4rem;
}

.login-brand p {
  color: #c5d7d0;
}

.login-form {
  display: grid;
  align-content: center;
  gap: 16px;
  padding: 34px;
}

.login-form h2 {
  margin: 6px 0 0;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.login-form input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 122, 108, 0.14);
}

.login-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.sidebar {
  background: var(--sidebar);
  color: #f8faf8;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: var(--radius);
  background: #f5b544;
  color: #17201d;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 1.18rem;
}

.brand p {
  margin: 4px 0 0;
  color: #bac7c1;
  font-size: 0.86rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: #d8e2dd;
  text-align: left;
  padding: 0 14px;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.nav-btn:hover,
.nav-btn.active {
  background: var(--sidebar-soft);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  min-height: 44px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: #d8e2dd;
  font-size: 0.9rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}

.status-dot.online {
  background: #36c06d;
}

.status-dot.offline {
  background: #e05043;
}

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

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

.eyebrow,
.section-kicker,
.alert-kicker {
  margin: 0;
  color: var(--primary);
  font-size: 0.76rem;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.topbar h2,
.panel h3 {
  margin: 5px 0 0;
}

.topbar h2 {
  font-size: clamp(1.7rem, 2vw, 2.35rem);
}

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

.pill,
.summary-pills span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.9rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-top: 4px solid var(--primary);
}

.stat-card:nth-child(2n) {
  border-top-color: var(--accent);
}

.stat-card:nth-child(3n) {
  border-top-color: var(--steel);
}

.stat-card strong {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.alert-band {
  min-height: 74px;
  background: #fff8e7;
  border: 1px solid #ead8a5;
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin: 18px 0;
}

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

.split-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.split-layout.single-column {
  grid-template-columns: 1fr;
}

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

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

.panel-heading h3 {
  font-size: 1.08rem;
}

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

.form-grid label,
.filters label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.filters input,
.filters select,
.compact-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.form-grid textarea {
  resize: vertical;
  min-height: 86px;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus,
.filters input:focus,
.filters select:focus,
.compact-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 122, 108, 0.14);
}

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

.form-actions,
.filters {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.tab-btn {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-btn {
  background: var(--primary);
  color: #ffffff;
}

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

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

.secondary-btn:hover,
.ghost-btn:hover,
.tab-btn:hover {
  border-color: var(--primary);
}

.ghost-btn {
  background: transparent;
  color: var(--primary-dark);
  border-color: #c4d9d3;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

.tall-table {
  max-height: 640px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8faf8;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  font-size: 0.92rem;
}

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

.actions-col {
  width: 220px;
  text-align: right;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn {
  min-width: 38px;
  min-height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.icon-btn.danger {
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-alt);
  color: var(--steel);
  font-weight: 800;
  font-size: 0.78rem;
}

.badge.low {
  background: #fff1d0;
  color: #8a5707;
}

.badge.critical {
  background: #ffe4e1;
  color: var(--danger);
}

.badge.good {
  background: #e3f5e8;
  color: var(--success);
}

.role-guide {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: #f8faf8;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

button:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.muted {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.empty-cell {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.report-subtables {
  margin-top: 18px;
}

.report-subtables h3 {
  font-size: 0.96rem;
  margin: 0 0 10px;
}

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  background: #ffffff;
  border-color: var(--line);
  color: var(--muted);
}

.tab-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.filters {
  align-items: end;
}

.filters label {
  min-width: 150px;
  flex: 1;
}

.filter-panel {
  margin-bottom: 16px;
}

.summary-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cycle-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.cycle-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.cycle-card {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf8;
  padding: 12px;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.cycle-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cycle-card strong {
  font-size: 1.22rem;
  font-variant-numeric: tabular-nums;
}

.cycle-insight {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: #eef7f4;
  padding: 12px 14px;
  color: var(--steel);
}

.cycle-insight strong {
  color: var(--primary-dark);
  white-space: nowrap;
}

.ledger-groups {
  display: grid;
  gap: 18px;
}

.ledger-group {
  min-width: 860px;
}

.ledger-group-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}

.ledger-group-heading h3 {
  margin: 4px 0 0;
  font-size: 1rem;
}

.ledger-flow-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.total-row td {
  background: #f8faf8;
}

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  background: var(--ink);
  color: #ffffff;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  transform: translateY(120%);
  transition: transform 180ms ease;
  z-index: 30;
}

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

canvas {
  width: 100%;
  min-height: 260px;
}

@media (max-width: 1180px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .cycle-flow {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .split-layout,
  .dashboard-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .login-card {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .login-brand {
    min-height: 220px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

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

  .main {
    padding: 18px;
  }

  .topbar,
  .alert-band,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

@media (max-width: 560px) {
  .stats-grid,
  .nav-list,
  .cycle-flow {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .filters label,
  .filters button {
    width: 100%;
  }
}
