:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #39d353;
  --accent-hover: #56e86d;
  --open: #3fb950;
  --closed: #ff4d4f;
  --unknown: #f0c040;
  --info: #58a6ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* DEV ribbon */
.dev-ribbon {
  position: fixed;
  top: 18px;
  right: -30px;
  background: #e53935;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 40px;
  transform: rotate(45deg);
  z-index: 9999;
  pointer-events: none;
  text-transform: uppercase;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Nav */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  font-weight: 700;
  font-size: 1.05em;
  color: var(--text);
  margin-right: 16px;
  flex-shrink: 0;
  text-decoration: none;
}
.nav-brand:hover { color: var(--accent); text-decoration: none; }
.nav-links { display: flex; gap: 2px; }
.nav-links a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.85em;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-links a:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nav-username { color: var(--text-muted); font-size: 0.82em; white-space: nowrap; }

/* Page */
.page { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }
.page-header { margin-bottom: 24px; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 1.5em; font-weight: 600; }
.subtitle { color: var(--text-muted); font-size: 0.9em; }
.total-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 12px;
  font-size: 0.85em;
  color: var(--text-muted);
}

/* Alerts */
.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-ok { background: rgba(63,185,80,.15); border: 1px solid var(--open); color: var(--open); }
.alert-err { background: rgba(255,77,79,.15); border: 1px solid var(--closed); color: var(--closed); }
.alert-warn { background: rgba(240,192,64,.15); border: 1px solid var(--unknown); color: var(--unknown); }

/* Stat card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 16px;
  text-align: center;
  transition: border-color .2s, background .2s;
  text-decoration: none;
  display: block;
}
.stat-card:hover { border-color: var(--accent); background: var(--surface2); text-decoration: none; }
.stat-card.open-card { border-color: rgba(63,185,80,.3); }
.stat-card.closed-card { border-color: rgba(255,77,79,.3); }
.stat-icon { font-size: 1.8em; margin-bottom: 6px; }
.stat-num { font-size: 1.8em; font-weight: 700; color: var(--text); }
.stat-label { color: var(--text-muted); font-size: 0.8em; margin-top: 2px; }

/* Two column layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Panel */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h2 { font-size: 0.95em; font-weight: 600; }
.panel > table { margin: 0; }

/* Bar charts */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.bar-row:last-child { border-bottom: none; }
.bar-label { width: 140px; flex-shrink: 0; font-size: 0.85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width .3s; }
.bar-count { width: 50px; text-align: right; font-size: 0.85em; color: var(--text-muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--surface2);
  padding: 10px 12px;
  text-align: left;
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable::after { content: ' ↕'; color: var(--border); font-size: 0.85em; }
.data-table th.sort-asc::after  { content: ' ↑'; color: var(--accent); }
.data-table th.sort-desc::after { content: ' ↓'; color: var(--accent); }
.data-table th.sortable:hover { color: var(--text); background: #2a313a; }
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.date-cell { color: var(--text-muted); font-size: 0.85em; white-space: nowrap; }
.empty-state { text-align: center; color: var(--text-muted); padding: 32px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-open   { background: rgba(63,185,80,.2);  color: var(--open);    border: 1px solid rgba(63,185,80,.4); }
.badge-closed { background: rgba(255,77,79,.2);  color: var(--closed);  border: 1px solid rgba(255,77,79,.4); }
.badge-unknown { background: rgba(240,192,64,.2); color: var(--unknown); border: 1px solid rgba(240,192,64,.4); }
.badge-info   { background: rgba(88,166,255,.15); color: var(--info);   border: 1px solid rgba(88,166,255,.3); }
.badge-bridge { background: rgba(88,166,255,.15); color: var(--info);   border: 1px solid rgba(88,166,255,.3); }
.badge-lock   { background: rgba(240,192,64,.2);  color: var(--unknown); border: 1px solid rgba(240,192,64,.4); }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border: none;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88em;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82em;
  text-decoration: none;
  transition: border-color .15s, color .15s;
  display: inline-block;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-danger {
  background: rgba(255,77,79,.15);
  color: var(--closed);
  border: 1px solid rgba(255,77,79,.4);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82em;
  transition: background .15s;
}
.btn-danger:hover { background: rgba(255,77,79,.3); }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-input, .filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.9em;
}
.filter-input { flex: 1; min-width: 180px; }
.filter-input:focus, .filter-select:focus {
  outline: none;
  border-color: var(--accent);
}
.filter-select option { background: var(--surface2); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.88em; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9em;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-hint { font-size: 0.8em; color: var(--text-muted); margin-top: 4px; }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
}
.login-title {
  font-size: 1.4em;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.login-subtitle { color: var(--text-muted); font-size: 0.9em; margin-bottom: 28px; }

/* Section divider */
.section-title {
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin: 24px 0 12px;
}

/* ISRS code monospace */
.isrs-code { font-family: 'Courier New', monospace; font-size: 0.82em; color: var(--text-muted); }
a.isrs-code { color: var(--primary); text-decoration: none; }
a.isrs-code:hover { text-decoration: underline; }

/* Status dot */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.open { background: var(--open); }
.status-dot.closed { background: var(--closed); }
.status-dot.unknown { background: var(--unknown); }

/* Detail info grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.info-item label { font-size: 0.78em; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); display: block; margin-bottom: 4px; }
.info-item span { font-size: 0.95em; }

/* Panel footer */
.panel-footer { padding: 8px 16px; border-top: 1px solid var(--border); font-size: 0.82em; }

/* Utility text classes */
.text-muted { color: var(--text-muted); }
.mono { font-family: 'Courier New', monospace; font-size: 0.82em; }

/* Tooltip icon on column headers */
.col-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9px;
  font-style: normal;
  cursor: help;
  margin-left: 4px;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
}
.col-tip:hover { border-color: var(--info); color: var(--info); }

/* CSS tooltip via data-tooltip attribute */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c2128;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: normal;
  width: 220px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
[data-tooltip]:hover::after { opacity: 1; }

/* LOCODE page specifics */
.locode-country-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: .08em;
  vertical-align: middle;
  color: var(--info);
}

.locode-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.locode-fetch-form, .locode-snapshot-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-label { font-size: 0.85em; color: var(--text-muted); white-space: nowrap; }
.locode-search { min-width: 280px; }

/* Diff card */
.locode-diff-card { margin-bottom: 20px; border-color: rgba(88,166,255,.3); }
.locode-diff-card .panel-header { background: rgba(88,166,255,.05); }
.locode-diff-summary { display: flex; gap: 8px; }

.badge-added   { background: rgba(63,185,80,.2);  color: var(--open);    border: 1px solid rgba(63,185,80,.4); }
.badge-removed { background: rgba(255,77,79,.2);  color: var(--closed);  border: 1px solid rgba(255,77,79,.4); }
.badge-changed { background: rgba(88,166,255,.15); color: var(--info);   border: 1px solid rgba(88,166,255,.3); }

tr.diff-added td  { background: rgba(63,185,80,.06); }
tr.diff-removed td { background: rgba(255,77,79,.06); }
tr.diff-changed td { background: rgba(88,166,255,.06); }

.diff-changed-fields { display: flex; flex-direction: column; gap: 2px; }
.diff-field-chip { font-size: 0.8em; }
.diff-old { color: var(--closed); text-decoration: line-through; }
.diff-new { color: var(--open); }

/* LOCODE table specifics */
.subdiv-badge {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 0.78em;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-muted);
}
.ch-indicator {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 1em;
  cursor: help;
  text-decoration: none;
  border-bottom: 1px dashed var(--border);
}
.status-code {
  font-family: 'Courier New', monospace;
  font-size: 0.82em;
  cursor: help;
  text-decoration: none;
  border-bottom: 1px dashed var(--border);
}
.coords-cell { font-size: 0.8em; white-space: nowrap; }
.remarks-cell { font-size: 0.82em; max-width: 200px; }
abbr { text-decoration: none; border-bottom: 1px dashed var(--border); cursor: help; }
