:root {
  --bg: #f6f8fd;
  --bg-accent: linear-gradient(150deg, rgba(143, 210, 255, 0.18), rgba(167, 236, 207, 0.2));
  --card: rgba(255, 255, 255, 0.76);
  --text: #1f3040;
  --muted: #5d7386;
  --line: #d9e4ed;
  --primary: #5ca8f6;
  --primary-soft: #d9ebff;
  --danger: #ef7f9a;
  --warning: #f8bf73;
  --success: #77cfa8;
  --radius: 18px;
  --shadow: 0 10px 26px rgba(62, 101, 137, 0.16);
}

* {
  box-sizing: border-box;
}

html.preload body {
  visibility: hidden;
}

html body {
  visibility: visible;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg-accent), var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  backdrop-filter: blur(12px);
  background: rgba(246, 248, 253, 0.85);
  border-bottom: 1px solid var(--line);
}

.topbar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.25rem;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.menu {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.menu a {
  padding: 0.58rem 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.menu a:hover {
  background: var(--primary-soft);
}

.userbox {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.container {
  width: min(1160px, 92vw);
  margin: 1.4rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.page-head.with-action {
  align-items: end;
}

.header-actions,
.table-actions,
.action-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.header-actions form,
.table-actions form,
.history-actions form {
  margin: 0;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 3vw, 1.8rem);
}

.muted {
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

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

.detail-card {
  display: grid;
  gap: 0.8rem;
}

.accent-card {
  background: linear-gradient(145deg, rgba(217, 235, 255, 0.72), rgba(255, 255, 255, 0.82));
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
}

.feature-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
}

.feature-list li + li {
  margin-top: 0.35rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stats-grid,
.history-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.stats-grid dt,
.history-grid dt {
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-grid dd,
.history-grid dd {
  margin: 0.12rem 0 0;
  font-weight: 700;
}

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

.kpi p {
  margin: 0.7rem 0 0;
  font-size: 1.45rem;
  font-weight: 800;
}

.chart-card {
  overflow: hidden;
}

#yearChart {
  min-height: 320px;
}

.list-grid {
  display: grid;
  gap: 0.8rem;
}

.supply-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.7rem;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.status.green {
  background: rgba(119, 207, 168, 0.26);
}

.status.yellow {
  background: rgba(248, 191, 115, 0.3);
}

.status.red {
  background: rgba(239, 127, 154, 0.27);
}

.status.gray {
  background: rgba(151, 163, 173, 0.2);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.meta-grid dt {
  font-size: 0.8rem;
  color: var(--muted);
}

.meta-grid dd {
  margin: 0.1rem 0 0;
  font-weight: 600;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.62rem 0.95rem;
  cursor: pointer;
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: var(--danger);
}

.btn:hover {
  filter: brightness(0.96);
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

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

.span-full {
  grid-column: 1 / -1;
}

.form-grid label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--muted);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.66rem 0.72rem;
  background: rgba(255, 255, 255, 0.9);
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(92, 168, 246, 0.2);
  border-color: var(--primary);
}

.checks {
  display: flex;
  align-items: center;
  gap: 1rem;
}

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

.responsive-table {
  min-width: 100%;
}

.history-stack {
  display: grid;
  gap: 0.9rem;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
}

.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.history-stamp {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-actions {
  display: grid;
  align-content: start;
  gap: 0.5rem;
}

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

th,
td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.82rem;
  color: var(--muted);
}

.auth-wrap {
  min-height: 78vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 96vw);
}

.alert.error {
  background: rgba(239, 127, 154, 0.2);
  border: 1px solid rgba(239, 127, 154, 0.4);
  padding: 0.6rem;
  border-radius: 10px;
}

.hint {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid,
  .stats-grid,
  .history-grid,
  .meta-grid,
  .form-grid.two-col {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .topbar-brand {
    width: 100%;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .menu {
    display: none;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    width: 100%;
    padding: 0.35rem 0 0;
  }

  body.nav-open .menu {
    display: grid;
  }

  .menu a {
    display: block;
    width: 100%;
    padding: 0.85rem 1rem;
  }

  .userbox {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .container {
    width: min(100%, calc(100vw - 1.5rem));
    margin: 1rem auto 2rem;
  }

  .kpi-grid,
  .detail-grid,
  .meta-grid,
  .stats-grid,
  .history-grid,
  .form-grid.two-col {
    grid-template-columns: 1fr;
  }

  .supply-head,
  .section-head,
  .history-title-row,
  .page-head,
  .page-head.with-action {
    align-items: start;
    flex-direction: column;
  }

  .table-wrap {
    overflow: visible;
    padding: 0.9rem;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody {
    display: grid;
    gap: 0.85rem;
  }

  .responsive-table tr {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 8px 18px rgba(62, 101, 137, 0.08);
  }

  .responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
    padding: 0.3rem 0;
    border-bottom: 0;
    text-align: right;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: left;
  }

  .table-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .table-actions .btn,
  .table-actions form,
  .table-actions form .btn {
    width: 100%;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0.9rem;
  }

  .brand {
    font-size: 1rem;
  }

  .card {
    padding: 0.9rem;
  }

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

  .responsive-table td {
    flex-direction: column;
    text-align: left;
    gap: 0.2rem;
  }

  .table-actions {
    justify-content: stretch;
  }
}
