:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --border: #d9dcd6;
  --text: #1d2420;
  --muted: #5d6761;
  --accent: #1f6f4a;
  --selected: #e4f1ea;
  --danger: #b3261e;
  --warning: #9a5b00;
  --info: #1a5fb4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 16px; font-weight: 650; }
h2 { margin: 0 0 12px; font-size: 13px; font-weight: 650; }

.button {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.button:hover:not(:disabled) { background: var(--bg); }
.button:disabled { opacity: 0.45; cursor: default; }
.button-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button-primary:hover:not(:disabled) { background: #185a3c; }
.button-danger { border-color: var(--danger); color: var(--danger); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Sign-in */
.gate { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.gate-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(360px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.gate-card p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }

/* Layout */
.app {
  display: grid;
  grid-template:
    "top top top" auto
    "list map details" minmax(0, 1fr)
    / 300px minmax(0, 1fr) 300px;
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.nav { display: flex; align-items: center; gap: 8px; }
.position { min-width: 72px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.account { display: flex; align-items: center; gap: 12px; margin-left: auto; min-width: 0; }
.account-email { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* List */
.list-panel {
  grid-area: list;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.list-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.list-controls label { color: var(--muted); font-size: 12px; }
.list-controls select {
  min-width: 0;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
}
.list-message { margin: 0; padding: 12px; color: var(--muted); overflow-wrap: anywhere; }
.list-message.is-error { color: var(--danger); }
.list-message a { color: inherit; }

.doc-list { flex: 1; min-height: 0; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.doc-row {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.doc-row:hover { background: var(--bg); }
.doc-row.is-selected { background: var(--selected); box-shadow: inset 3px 0 0 var(--accent); }
.doc-row-date { font-variant-numeric: tabular-nums; }
.doc-row-outcome { font-size: 12px; font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.doc-row-outcome[data-outcome="MATCHED_SECOND_ATTEMPT"] { color: var(--info); }
.doc-row-outcome[data-outcome="FALLBACK"],
.doc-row-outcome[data-outcome="CANCELLED"] { color: var(--warning); }
.doc-row-outcome[data-outcome="ERROR"],
.doc-row-outcome[data-outcome="NO_INTERNET"] { color: var(--danger); }
.doc-row-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.load-more { margin: 8px; }

/* Map */
.map-panel { grid-area: map; position: relative; min-height: 0; }
.map { position: absolute; inset: 0; }

.layer-toggles {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.15);
}
.layer-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.layer-toggle.is-missing { color: var(--muted); cursor: default; }
.layer-swatch { flex: none; width: 18px; border-top: 3px solid; }
.layer-swatch.is-dashed { border-top-style: dashed; }
.layer-missing { font-size: 11px; }

.map-notice {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgb(29 36 32 / 0.88);
  color: #fff;
}

/* Details */
.details-panel {
  grid-area: details;
  min-height: 0;
  padding: 12px 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.details-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; margin-bottom: 12px; }
.details-header h2 { margin: 0; }
.details-message { margin: 0 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.details-message.is-error { color: var(--danger); }
.details { margin: 0; }
.details dt { margin-top: 10px; color: var(--muted); font-size: 12px; }
.details dt:first-child { margin-top: 0; }
.details dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .app {
    grid-template:
      "top" auto
      "map" 55dvh
      "details" auto
      "list" auto
      / minmax(0, 1fr);
    height: auto;
    min-height: 100dvh;
  }
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .list-panel { border-top: 1px solid var(--border); border-right: 0; }
  .doc-list { max-height: 60dvh; }
  .details-panel { border-left: 0; }
}
