:root {
  --primary: #0e4f63;
  --primary-700: #0a3d4d;
  --accent: #18c29c;
  --warn: #d98a00;
  --err: #d23b3b;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #1c2733;
  --muted: #7b8794;
  --line: #e3e8ee;
  --sidebar: #0c1722;
  --sidebar-ink: #aebccb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,32,48,.06), 0 6px 18px rgba(16,32,48,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* Layout shell */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  padding: 20px 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand-mark {
  background: var(--accent); color: #06231d; font-weight: 800;
  padding: 4px 8px; border-radius: 8px; letter-spacing: .5px; font-size: 13px;
}
.brand-text { color: #fff; font-weight: 600; }
/* SCDB wordmark: white logo on the brand background colour from the upload. */
.brand-logo {
  display: block; height: 40px; width: auto;
  background: #2c96de; padding: 7px 12px; border-radius: 8px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--sidebar-ink); padding: 10px 12px; border-radius: 8px;
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 16px; }
.partner-name { color: #fff; font-weight: 600; }
.role-chip {
  display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  background: rgba(255,255,255,.08); padding: 3px 8px; border-radius: 20px; width: fit-content;
}
.lang-switch { display: flex; gap: 4px; margin-top: 8px; }
.lang-switch a {
  font-size: 11px; font-weight: 600; letter-spacing: .4px; color: rgba(255,255,255,.55);
  padding: 2px 8px; border-radius: 6px; background: rgba(255,255,255,.06); text-decoration: none;
}
.lang-switch a.active { color: #fff; background: rgba(255,255,255,.18); }

/* i18n / translation editor */
.i18n-progress {
  display: block; width: 160px; height: 8px; border-radius: 6px;
  background: var(--line); overflow: hidden;
}
.i18n-progress > span { display: block; height: 100%; background: var(--accent, #3b82f6); }
.i18n-progress-inline { display: inline-block; vertical-align: middle; width: 120px; margin: 0 4px; }
.i18n-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline-flex; align-items: center; margin: 0; }
.inline-form .chk { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.i18n-grid td { vertical-align: top; }
.i18n-grid .i18n-source { white-space: pre-wrap; color: var(--muted, #6b7280); max-width: 320px; }
.i18n-input { width: 100%; min-width: 220px; font: inherit; resize: vertical; }
.i18n-status { white-space: nowrap; }
.i18n-actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0; }
.i18n-aibar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 16px; }

/* Modal overlay (AI translation progress) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); color: inherit; border-radius: 12px; padding: 24px;
  width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal h2 { margin-top: 0; }
.modal .i18n-progress { width: 100%; height: 12px; margin: 12px 0; }
.ai-counts { font-size: 14px; }
.ai-errors { max-height: 200px; overflow: auto; font-size: 13px; color: var(--danger, #b91c1c); margin: 8px 0; }
.ai-errors ul { margin: 4px 0 0; padding-left: 18px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.page-title { font-size: 18px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user { color: var(--muted); }
.content { padding: 28px; max-width: 1180px; width: 100%; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card-head h2 { font-size: 15px; margin: 0; }
/* Sub-navigation tabs (e.g. Integration: App-Start vs. Blitzer melden) */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.subtabs a {
  padding: 8px 14px; font-size: 14px; font-weight: 500; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtabs a:hover { color: var(--ink); }
.subtabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 880px){ .grid-2 { grid-template-columns: 1fr; } .shell { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat.accent { background: linear-gradient(135deg, var(--primary), var(--primary-700)); color: #fff; border: none; }
.stat.accent .stat-label { color: rgba(255,255,255,.8); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 600; }
.table.compact th, .table.compact td { padding: 7px 10px; font-size: 13px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.empty { color: var(--muted); text-align: center; padding: 22px; }
.small { font-size: 12px; }
td.small { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Database browser */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-scroll .table th, .table-scroll .table td { border-bottom: 1px solid var(--line); }
.db-subhead { font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); margin: 16px 0 8px; }
.db-table-meta { display: inline-flex; gap: 8px; }
a.db-card { display: block; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
a.db-card:hover { border-color: var(--accent, #2563eb); box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.db-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.db-card-foot { display: inline-block; margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--accent, #2563eb); }

/* Bar charts (CSS only) */
.barchart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 8px; overflow-x: auto; }
.bar-col { flex: 1 1 0; min-width: 14px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar-fill { width: 70%; max-width: 26px; min-height: 0; background: var(--primary); border-radius: 3px 3px 0 0; transition: opacity .15s; }
.bar-col:hover .bar-fill { background: var(--accent); }
.bar-label { margin-top: 6px; font-size: 10.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: #eef1f4; color: #56636f;
}
.badge-ok { background: #def5ee; color: #0a7a5d; }
.badge-warn { background: #fdf0d8; color: #a96b00; }
.badge-err { background: #fbe2e2; color: #b62525; }
.badge-neutral { background: #eef1f4; color: #56636f; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; text-decoration: none;
}
.btn:hover { background: #f7f9fb; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-700); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-warn:hover { background: #b87600; border-color: #b87600; color: #fff; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: #b62525; border-color: #b62525; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.job-actions, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions { justify-content: flex-end; margin-top: 8px; }

/* Forms */
.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
.form input, .form select, .form-inline input, .form-inline select, .tier-table input {
  width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
.form input:focus, .form select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.form-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.form-inline input, .form-inline select { width: auto; flex: 1; min-width: 140px; margin-top: 0; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0c1722, #0e4f63); padding: 20px; }
.auth-card { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.auth-brand .brand-text { color: var(--ink); font-weight: 700; }
.auth-sub { color: var(--muted); margin-top: -4px; margin-bottom: 18px; }

/* Flash */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.flash-ok { background: #def5ee; color: #0a7a5d; }
.flash-warn { background: #fdf0d8; color: #91631a; }
.flash-err { background: #fbe2e2; color: #b62525; }
.form-error { color: var(--err); font-size: 13px; margin-top: 8px; font-weight: 600; }

/* App detail */
.app-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.app-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); flex-wrap: wrap; }
.app-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.app-actions form { margin: 0; display: inline-flex; align-items: center; }
.token-cell code { background: #f3f5f7; padding: 3px 7px; border-radius: 6px; }
.copy { cursor: pointer; }
.copy:hover { outline: 1px dashed var(--accent); }

/* Key-value + lists */
.kv { display: grid; gap: 10px; margin: 14px 0; }
.kv-key { display: inline-block; width: 90px; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.kv code { background: #f3f5f7; padding: 4px 8px; border-radius: 6px; }
.lst { margin: 6px 0 14px; padding-left: 18px; }
.lst li { margin-bottom: 4px; }

/* Code cards */
.code-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 16px; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: #f7f9fb; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 12px; }
.code-card pre { margin: 0; padding: 14px; background: #0c1722; color: #d6e2ee; overflow-x: auto; font-size: 12.5px; line-height: 1.55; }
pre.mini { background: #0c1722; color: #d6e2ee; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; overflow-x: auto; }

/* Map */
.map-wrap { margin-bottom: 16px; }
.map { height: 280px; border-radius: 10px; border: 1px solid var(--line); }
/* Clickable report rows: focus the matching map marker. */
.report-row { cursor: pointer; }
.report-row:hover { background: rgba(44,150,222,.08); }
.report-row.active { background: rgba(44,150,222,.16); }

/* Geocoder details popup (hover/focus over the coordinates cell) */
/* Override td.small's overflow:hidden so the absolutely-positioned popup is
   not clipped by the cell. */
td.geo-cell { overflow: visible; max-width: none; }
.geo-tip { position: relative; cursor: help; border-bottom: 1px dotted var(--muted); outline: none; }
.geo-pop {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  /* Above Leaflet's panes/controls (which reach ~z-index 1000) so the map
     never covers the popup. */
  z-index: 2000;
  display: none;
  min-width: 220px;
  padding: 10px 12px;
  text-align: left;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(28,39,51,.18);
  white-space: normal;
}
.geo-tip:hover .geo-pop,
.geo-tip:focus-visible .geo-pop,
.geo-tip:focus-within .geo-pop { display: block; }
.geo-pop::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 14px;
  border: 6px solid transparent;
  border-top-color: var(--surface);
}
.geo-pop-head { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.geo-pop-table { border-collapse: collapse; font-size: 12.5px; font-family: inherit; }
.geo-pop-table th { text-align: left; padding: 2px 12px 2px 0; color: var(--muted); font-weight: 600; white-space: nowrap; text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.geo-pop-table td { padding: 2px 0; color: var(--ink); }

/* Tariff tier editor */
.tier-del-cell { width: 1%; white-space: nowrap; text-align: right; }

/* Switch row (settings) */
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; }

/* Content editor */
.content-tokens { background: #f7f9fb; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; font-size: 13px; }
.content-tokens ul { margin: 8px 0 0; padding-left: 18px; }
.content-tokens li { margin-bottom: 4px; }
.content-tokens code { background: #fff; border: 1px solid var(--line); padding: 2px 6px; border-radius: 6px; }
.code-area { width: 100%; margin-top: 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #0c1722; color: #d6e2ee; font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.6; resize: vertical; }
.code-area:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
