:root {
  --bg: #141414;
  --surface: #1e1e1e;
  --surface-2: #282828;
  --border: #333;
  --text: #ececec;
  --muted: #9a9a9a;
  --accent: #ff671f;
  --accent-dim: rgba(255, 103, 31, 0.15);
  --ok: #5cb85c;
  --warn: #e6a817;
  --error: #e05555;
  --radius: 10px;
  --nav-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
}

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: var(--nav-h);
  height: var(--nav-h);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-start {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
  min-width: 0;
}

.nav-center {
  justify-self: center;
}

.nav-end {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  flex-shrink: 0;
}

/* FIR dropdown */
.fir-select {
  position: relative;
  flex-shrink: 0;
}

.fir-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  min-height: 36px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.fir-trigger:hover,
.fir-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.fir-chevron {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.fir-trigger[aria-expanded="true"] .fir-chevron {
  transform: rotate(180deg);
  border-top-color: var(--accent);
}

.fir-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 200;
  min-width: 160px;
  max-width: min(280px, 90vw);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateX(-50%) translateY(-6px) scale(0.98);
  transform-origin: top center;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.fir-menu.open {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}

.fir-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.fir-option-label {
  flex: 1;
  min-width: 0;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}

.btn-icon-svg {
  display: block;
  opacity: 0.72;
}

.btn-icon:hover .btn-icon-svg {
  opacity: 1;
}

.fir-option:hover {
  background: var(--surface-2);
  color: var(--text);
}

.fir-option.selected {
  color: var(--accent);
  background: var(--accent-dim);
}

.fir-option-check {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}

.fir-option.selected .fir-option-check {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 2px var(--surface);
}

.refresh-hint {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  min-height: 36px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #1a0a00;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled { opacity: 0.55; cursor: wait; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-with-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.btn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.25s, box-shadow 0.25s;
}

.btn-dot.ok {
  background: var(--ok);
  box-shadow: 0 0 6px rgba(92, 184, 92, 0.5);
}

.btn-dot.bad {
  background: var(--error);
  box-shadow: 0 0 6px rgba(224, 85, 85, 0.5);
}

.main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--border);
}

.map-panel {
  position: relative;
  min-height: 0;
  background: var(--surface);
}

#map {
  width: 100%;
  height: 100%;
}

.map-legend {
  position: absolute;
  top: 10px;
  left: 10px;
  bottom: auto;
  z-index: 2;
  display: flex;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(20, 20, 20, 0.82);
  border: 1px solid var(--border);
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot.current {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.legend-dot.stale {
  background: var(--warn);
  box-shadow: 0 0 0 1px rgba(230, 168, 23, 0.4);
}

.detail-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.detail-empty {
  flex: 1;
  min-height: 0;
}

.detail-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 16px 16px 14px;
}

.detail-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.fix-region {
  margin: 0 0 4px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-content h2 {
  margin: 0 0 6px;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  color: var(--text);
}

.fix-meta {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.fix-meta.is-stale {
  color: var(--warn);
}

.time-block {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
}

.time-date {
  font-weight: 600;
  color: var(--text);
}

.time-z,
.time-ist {
  font-variant-numeric: tabular-nums;
}

.time-z {
  color: var(--text);
}

.time-ist {
  color: var(--muted);
}

.time-ist::before {
  content: "·";
  margin-right: 8px;
  color: var(--border);
}

.time-missing {
  color: var(--muted);
}

.fl-table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
}

.fl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.fl-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.fl-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fl-table td:first-child {
  font-weight: 600;
  color: var(--accent);
}

.fl-table tbody tr:hover {
  background: var(--accent-dim);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-backdrop.closing {
  animation: fadeOut 0.18s ease forwards;
}

.modal {
  width: min(400px, 100%);
  max-height: min(80vh, 560px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-logs {
  width: min(520px, 100%);
  max-height: min(85vh, 640px);
}

.modal-shortcuts {
  width: min(96vw, 720px);
  max-height: none;
}

.modal-shortcuts .modal-body {
  overflow: visible;
}

.modal-head-compact {
  padding: 10px 14px;
}

.modal-head-compact h2 {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.shortcuts-body {
  padding: 4px 14px 12px;
  overflow: visible;
}

.shortcuts-line {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.shortcut-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.shortcut-chip-label {
  font-size: 0.7rem;
  color: var(--muted);
}

.shortcut-divider {
  color: var(--border);
  font-size: 0.65rem;
  flex-shrink: 0;
  user-select: none;
}

.key-cap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55rem;
  height: 1.45rem;
  padding: 0 6px;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  background: linear-gradient(180deg, #333 0%, #2a2a2a 100%);
  border: 1px solid #444;
  border-bottom-color: #222;
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  font-variant-numeric: tabular-nums;
}

.key-cap-wide {
  min-width: 2.1rem;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
}

.modal-backdrop.closing .modal {
  animation: slideDown 0.18s ease forwards;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 10px 16px 14px;
  overflow-y: auto;
  min-height: 0;
}

.logs-body {
  max-height: min(70vh, 520px);
}

.logs-meta {
  margin: 0 0 10px;
  font-size: 0.74rem;
  color: var(--muted);
}

.status-hero {
  padding: 0 0 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.status-next-line,
.status-last-line {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
}

.status-last-line {
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
}

.status-hero-fir {
  font-weight: 700;
  color: var(--accent);
}

.status-hero-at {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status-regions {
  padding-top: 2px;
}

.status-row {
  display: grid;
  grid-template-columns: 8px 52px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(51, 51, 51, 0.55);
}

.status-row:last-child {
  border-bottom: none;
}

.status-row.is-next {
  background: var(--accent-dim);
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  border-radius: 6px;
  border-bottom-color: transparent;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ok { background: var(--ok); }
.status-dot.warning { background: var(--warn); }
.status-dot.error { background: var(--error); }

.status-fir {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-time {
  font-size: 0.72rem;
  color: var(--muted);
  justify-self: end;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status-file-link {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  line-height: 1;
  padding: 2px;
}

.status-file-link:hover {
  color: var(--accent);
}

.log-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
  line-height: 1.45;
}

.log-item strong {
  font-weight: 600;
  color: var(--text);
}

.log-item:last-child { border-bottom: none; }

.log-item.ok { color: var(--text); }
.log-item.warn { color: var(--warn); }
.log-item.fail { color: var(--error); }
.log-item.deploy { color: var(--accent); }

.log-time {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 3px;
}

.log-detail {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-word;
}

.log-region {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  animation: fadeIn 0.2s ease;
}

.toast.error { border-color: var(--error); }

.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slideDown {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(10px); }
}

.mapboxgl-ctrl-bottom-right,
.mapboxgl-ctrl-bottom-left,
.mapboxgl-ctrl-top-right,
.mapboxgl-ctrl-top-left {
  display: none !important;
}

@media (max-width: 900px) {
  html, body { overflow: auto; }
  .shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
  }
  .nav {
    position: sticky;
    top: 0;
    z-index: 50;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 0;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    gap: 8px;
  }
  .nav-start {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    justify-content: flex-start;
    align-items: center;
  }
  .nav-center {
    grid-column: 1;
    grid-row: 2;
    justify-self: stretch;
    display: flex;
    justify-content: center;
    width: 100%;
  }
  .fir-select {
    width: 100%;
    max-width: 360px;
  }
  .fir-trigger {
    width: 100%;
    justify-content: center;
  }
  .fir-menu {
    left: 50%;
    right: auto;
    width: min(360px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }
  .nav-end {
    grid-column: 1;
    grid-row: 3;
    justify-self: stretch;
    width: 100%;
    justify-content: center;
    gap: 10px;
  }
  .nav-end .btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: 180px;
    justify-content: center;
  }
  .nav-end .btn-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
  }
  .refresh-hint {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: min(50vh, 420px) auto;
  }
  .detail-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    min-height: 280px;
  }
  .map-legend {
    top: 8px;
    left: 8px;
  }
}

@media (max-width: 480px) {
  .btn {
    padding: 8px 12px;
    min-height: 40px;
    font-size: 0.8rem;
  }
  .fir-trigger {
    padding: 8px 12px;
    min-height: 40px;
    font-size: 0.84rem;
  }
  .btn-icon {
    min-height: 40px;
    min-width: 40px;
  }
  .nav-end .btn {
    max-width: none;
  }
  .refresh-hint {
    font-size: 0.72rem;
  }
  .map-legend {
    top: 8px;
    left: 8px;
    flex-direction: row;
    gap: 6px;
  }
}
