:root {
  --bg: #f4efe7;
  --panel: rgba(255, 252, 246, 0.92);
  --line: #d9cab8;
  --text: #1f1a17;
  --muted: #65574d;
  --accent: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 18px 40px rgba(58, 41, 25, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(217, 119, 6, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.18), transparent 28%),
    linear-gradient(180deg, #fbf7f0 0%, var(--bg) 100%);
  min-height: 100vh;
}

.login-body {
  display: grid;
  place-items: center;
}

.login-shell,
.layout {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
}

.login-card,
.panel {
  background: var(--panel);
  border: 1px solid rgba(217, 202, 184, 0.85);
  box-shadow: var(--shadow);
  border-radius: 24px;
}

.login-card {
  max-width: 480px;
  margin: 72px auto;
  padding: 32px;
}

.topbar {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto 16px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.topbar-actions,
.quick-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.notice-panel,
.diagnostics-panel,
.toolbar,
.map-panel,
.table-panel,
.collapsible-panel {
  padding: 20px;
  margin-bottom: 16px;
}

.notice-panel.is-error {
  background: rgba(185, 28, 28, 0.92);
  border-color: rgba(185, 28, 28, 0.92);
  color: #fff;
}

.actions-menus {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading,
.map-panel-header,
.table-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

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

.stat-panel {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
}

.stat-label,
.muted {
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stack-form,
.search-inline,
.form-grid {
  display: grid;
  gap: 12px;
}

.search-inline {
  grid-template-columns: 1fr auto;
}

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

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

label span,
.eyebrow {
  display: block;
  margin-bottom: 6px;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

input,
button,
a.secondary-link {
  font: inherit;
}

input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

input[type="date"] {
  min-width: 0;
  max-width: 100%;
  height: 52px;
  line-height: 1.2;
  appearance: none;
  -webkit-appearance: none;
  padding-top: 0;
  padding-bottom: 0;
}

input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0.72;
}

button,
.secondary-link {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  text-decoration: none;
  cursor: pointer;
  background: var(--accent);
  color: white;
  transition: transform 140ms ease, opacity 140ms ease;
}

button:hover,
.secondary-link:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.secondary-button {
  background: #e7ddd0;
  color: var(--text);
}

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

.icon-button {
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.toolbar-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: auto;
}

.form-actions,
.segmented-control {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.segmented-control {
  justify-content: flex-end;
}

.map-mode-button.active {
  background: var(--accent);
  color: #fff;
}

#map {
  width: 100%;
  height: 620px;
  border-radius: 18px;
  overflow: hidden;
  margin-top: 18px;
}

.search-results {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.search-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  padding: 12px;
  border-radius: 16px;
}

.search-card button {
  margin-top: 8px;
}

.table-wrap {
  overflow: auto;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-icon-button,
.popup-edit-button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
}

.table-icon-button svg,
.popup-edit-button svg {
  width: 16px;
  height: 16px;
}

.table-icon-button.danger-button {
  background: #f6d6d6;
  color: #8e1717;
}

.table-icon-button.secondary-button {
  background: #ece2d5;
}

.editable-cell {
  cursor: text;
}

.editable-cell:hover {
  background: rgba(217, 202, 184, 0.14);
}

.editable-inline-input {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #bda78f;
  background: #fffdfa;
}

.actions-column {
  text-align: center;
}

.hidden {
  display: none;
}

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

th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid rgba(217, 202, 184, 0.7);
  vertical-align: top;
}

th:nth-child(1),
td:nth-child(1) {
  width: 15%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 12%;
  white-space: nowrap;
}

th:nth-child(3),
td:nth-child(3) {
  width: 18%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 14%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 29%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 12%;
}

thead th {
  position: sticky;
  top: 0;
  background: #fbf5ec;
  cursor: pointer;
  user-select: none;
}

thead th:hover {
  background: #f2e8db;
}

thead th:not([data-sort]) {
  cursor: default;
}

thead th[data-direction="asc"]::after {
  content: " ^";
}

thead th[data-direction="desc"]::after {
  content: " v";
}

.heatmap-legend {
  background: rgba(255, 252, 246, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 180px;
}

#heatmap-legend-scale {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

#heatmap-legend-scale span {
  display: flex;
  gap: 8px;
  align-items: center;
}

#heatmap-legend-scale i {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.error-banner {
  color: white;
  background: var(--danger);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 16px;
}

@media (max-width: 1100px) {
  .hero-grid,
  .filters,
  .form-grid.two-columns {
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-heading,
  .map-panel-header,
  .table-header {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions,
  .segmented-control {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .layout,
  .topbar,
  .login-shell {
    width: min(100vw - 20px, 100%);
  }

  .panel,
  .login-card {
    border-radius: 18px;
    padding: 16px;
  }

  .collapsible-panel {
    padding: 16px;
  }

  #map {
    height: 420px;
  }

  th,
  td {
    padding: 10px;
  }
}

@media (max-width: 820px) and (orientation: portrait) {
  .filters {
    grid-template-columns: 1fr;
  }

  label {
    min-width: 0;
  }

  input,
  input[type="date"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  input[type="date"] {
    height: 48px;
    padding: 0 10px;
    font-size: 0.96rem;
  }

  .search-inline {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    justify-content: flex-start;
  }

  .toolbar-actions button,
  .toolbar-actions .checkbox,
  .quick-actions button,
  .search-inline button {
    width: 100%;
  }

  th:nth-child(5),
  td:nth-child(5) {
    display: none;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 24%;
  }

  th:nth-child(2),
  td:nth-child(2) {
    width: 18%;
  }

  th:nth-child(3),
  td:nth-child(3) {
    width: 28%;
  }

  th:nth-child(4),
  td:nth-child(4) {
    width: 18%;
  }

  th:nth-child(6),
  td:nth-child(6) {
    width: 12%;
  }

  table {
    font-size: 0.82rem;
  }

  th,
  td {
    padding: 8px 6px;
  }

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

  .table-icon-button svg {
    width: 14px;
    height: 14px;
  }
}
