:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #65746b;
  --line: #dfe6dd;
  --brand: #185a48;
  --brand-2: #d48b2a;
  --danger: #b33b35;
  --ok: #227447;
  --warn: #9f6b14;
  --soft: #edf3ef;
  --shadow: 0 14px 38px rgba(22, 34, 27, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

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

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #16241d;
}

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

.hidden {
  display: none !important;
}

.auth-card {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.auth-brand {
  color: var(--ink);
  margin-bottom: 26px;
}

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

.auth-panel {
  display: none;
}

.auth-panel.active {
  display: block;
}

.auth-panel h2 {
  margin: 2px 0 18px;
  font-size: 28px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form .button {
  margin-top: 4px;
}

.auth-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.link-button,
.logout-button {
  border: 0;
  background: transparent;
  color: var(--brand);
  padding: 0;
  margin-top: 14px;
  cursor: pointer;
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(22, 36, 29, 0.66);
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  padding: 24px;
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.modal-heading h2 {
  margin: 2px 0 0;
  font-size: 26px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 800;
}

.report-form {
  display: grid;
  gap: 14px;
}

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

.report-preview {
  margin-top: 16px;
}

.report-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.report-summary strong {
  flex-basis: 100%;
}

.report-summary span {
  background: var(--soft);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.app-shell.locked {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

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

.sidebar {
  background: #16241d;
  color: #f6f8f5;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

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

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.route-card h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.eyebrow {
  color: #b8c6bd;
  font-size: 13px;
}

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

.nav-tab {
  border: 0;
  border-radius: 8px;
  color: #dce6df;
  background: transparent;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}

.nav-tab:hover,
.nav-tab.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.user-box {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.user-box span {
  font-weight: 800;
}

.user-box small {
  color: #b8c6bd;
}

.logout-button {
  color: #fff;
  text-align: left;
  margin-top: 6px;
}

.sidebar-footer label {
  color: #c6d1ca;
  font-size: 13px;
}

.sidebar-footer select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #22382d;
  color: #fff;
  padding: 10px 12px;
  border-radius: 8px;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.topbar .eyebrow {
  color: var(--muted);
  margin-bottom: 4px;
}

.topbar h2 {
  font-size: 30px;
  letter-spacing: 0;
}

.actions,
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}

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

.button.secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.file-button input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

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

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

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

.metric strong {
  display: block;
  font-size: 30px;
}

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

.panel,
.form-panel,
.table-wrap,
.route-card,
.map-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

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

.panel-heading h3,
.route-card h3 {
  font-size: 18px;
}

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

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
}

.compact .bar-fill {
  background: var(--brand-2);
}

.attention-list,
.top-units {
  display: grid;
  gap: 8px;
}

.attention-item,
.top-unit-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  align-items: center;
}

.top-unit-row {
  grid-template-columns: 38px 1fr auto;
}

.rank {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--soft);
}

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

.badge.ok {
  color: #fff;
  background: var(--ok);
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea,
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
}

input[readonly] {
  background: var(--soft);
}

textarea {
  resize: vertical;
}

.span-2 {
  grid-column: span 2;
}

.route-card {
  margin-top: 14px;
  padding: 16px;
  background: #fbfcf8;
}

.route-card p {
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.5;
}

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

.search {
  max-width: 360px;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  background: #eef4ef;
  color: #35433a;
  position: sticky;
  top: 0;
}

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

.delete-button {
  border: 1px solid #efcbc8;
  color: var(--danger);
  background: #fff7f6;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 10px;
  cursor: pointer;
}

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

.map-card {
  padding: 18px;
}

.map-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.map-card dl {
  margin: 0;
  display: grid;
  gap: 6px;
}

.map-card div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
}

.map-card dt {
  color: var(--muted);
  font-weight: 700;
}

.map-card dd {
  margin: 0;
}

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #16241d;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

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

.empty {
  color: var(--muted);
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcf8;
}

@media (max-width: 1100px) {
  .metric-grid,
  .form-grid,
  .map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .sidebar {
    position: static;
    padding: 18px;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .attention-item {
    grid-template-columns: 1fr;
    display: grid;
  }

  .dashboard-grid,
  .metric-grid,
  .form-grid,
  .form-grid.two,
  .map-grid {
    grid-template-columns: 1fr;
  }

  .span-2,
  .panel.wide {
    grid-column: auto;
  }
}
