:root {
  --bg: #f8f6f1;
  --panel: #fffdfa;
  --ink: #231f20;
  --muted: #6f6a64;
  --line: #d8d1c7;
  --accent: #8c1515;
  --accent-dark: #5f0f0f;
  --sand: #f2eee6;
  --sand-deep: #e9dfcf;
  --cardinal-soft: #fbefed;
  --amber: #b26b18;
  --red: #8c1515;
  --blue: #2f5d7c;
  --blue-soft: #edf4f7;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Source Sans 3", "Source Sans Pro", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}

.classification-banner {
  background: #2f7654;
  color: #fff;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: .22em;
  font-weight: 700;
  padding: 4px 10px;
  text-transform: uppercase;
}
.classification-banner.bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  border-top: 1px solid rgba(0,0,0,.15);
}
body { padding-bottom: 22px; }

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 1.15fr);
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
  background: #fffdfa;
  color: var(--ink);
  border-top: 5px solid var(--accent);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(35,31,32,.04);
}
.topbar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent);
}
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 15px; }
.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: 0;
  width: auto;
  max-width: 100%;
  justify-self: end;
}
.auth-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  width: auto;
  max-width: 100%;
  white-space: nowrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.auth-bar.hidden {
  display: none;
}
.case-picker {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  width: auto;
  max-width: 100%;
}
.case-picker label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.case-picker select {
  width: 11rem;
  min-width: 9rem;
  max-width: 14rem;
  flex: 0 0 auto;
}
.case-picker button {
  flex: 0 0 auto;
  padding: 0 11px;
  font-size: 13px;
  white-space: nowrap;
}

button, select, input, textarea {
  font: inherit;
}
button {
  border: 1px solid #c7bfb3;
  background: #fffdfa;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); background: #fff7f2; }
.button-link {
  display: inline-block;
  border: 1px solid #c7bfb3;
  background: #fffdfa;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 12px;
  text-decoration: none;
}
.button-link:hover { border-color: var(--accent); color: var(--accent); background: #fff7f2; }
button.danger {
  border-color: #cdb7b0;
  color: var(--red);
  white-space: nowrap;
}
button.danger:hover {
  border-color: var(--red);
  background: #fff6f6;
}
select, input, textarea {
  width: 100%;
  border: 1px solid #cfc7bb;
  border-radius: 7px;
  padding: 9px;
  background: #fffdfa;
  color: var(--ink);
}
textarea { resize: vertical; line-height: 1.35; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 650; }

.layout {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  min-height: calc(100vh - 82px);
}
.sidebar {
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow: auto;
  background: linear-gradient(180deg, #f2eee6 0%, #eee6d9 100%);
}
.workspace {
  padding: 14px;
  min-width: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(35,31,32,.04);
}
.panel h2 {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  color: var(--accent-dark);
}
.strategic-metric {
  border-left: 6px solid var(--blue);
  background: linear-gradient(180deg, #fffdfa 0%, #f1f6f8 100%);
}
.strategic-metric.increasing { border-left-color: #b26b18; }
.strategic-metric.same { border-left-color: var(--blue); }
.strategic-metric.decreasing { border-left-color: #2f7654; }
.strategic-metric.indeterminate { border-left-color: var(--muted); }
.metric-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.metric-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.metric-context {
  color: var(--muted);
  font-weight: 700;
}
form, .button-stack {
  display: grid;
  gap: 10px;
}
.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.grid2 > label {
  min-width: 0;
}
.sidebar .grid2 input[type="date"] {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding-left: 6px;
  padding-right: 6px;
  font-size: 13px;
}
#osintControlsPanel > label {
  margin-top: 10px;
}
.hidden { display: none; }
.field-group {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  background: var(--sand);
}
.nested-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: linear-gradient(180deg, var(--cardinal-soft), #fff9f7);
  display: grid;
  gap: 10px;
}
.nested-panel.hidden { display: none; }
.nested-panel h3 {
  margin: 0;
  font-size: 15px;
  color: var(--accent-dark);
}
.upload-progress {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  background: var(--blue-soft);
  display: grid;
  gap: 8px;
}
.upload-progress.hidden {
  display: none;
}
.upload-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--blue);
}
.upload-progress progress {
  width: 100%;
}
.imagery-progress {
  margin-top: 10px;
  background: var(--cardinal-soft);
}
.imagery-progress .upload-progress-head {
  color: var(--accent-dark);
}
.field-group h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}
.inline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.inline-head h3 { margin: 0; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 6px;
  background: var(--sand);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.tabpage { display: none; }
.tabpage.active { display: block; }

.editor-panel textarea {
  height: calc(100vh - 170px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.editor-panel pre {
  max-height: calc(100vh - 210px);
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.dossier-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.dossier-head > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.source-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}
.source-card {
  border: 2px solid #bfb5a8;
  border-top: 7px solid var(--accent);
  border-radius: 10px;
  background: #fffdfa;
  padding: 14px;
  display: grid;
  gap: 12px;
  box-shadow: 0 3px 8px rgba(35,31,32,.08);
}
.marker-card {
  border-top-color: var(--amber);
}
.source-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.source-card header > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.source-card header strong {
  font-size: 16px;
  color: var(--accent-dark);
}
.source-index {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.source-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-weight: 700;
}
.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.source-meta span {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  background: var(--sand);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.source-card .card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.source-card .wide { grid-column: 1 / -1; }
.source-card textarea { min-height: 70px; }
.source-card .use-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.source-card .use-row.compact {
  white-space: nowrap;
  font-weight: 800;
}
.source-card .use-row input { width: auto; }
.source-more {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.source-more summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}
.source-actions {
  display: flex;
  justify-content: flex-end;
}

#statusBox {
  min-height: 90px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--ink);
  font-size: 13px;
}
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.image-registry { display: grid; gap: 8px; }
.image-table { display: grid; gap: 8px; }
.image-row {
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}
.image-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(140, 21, 21, .14);
}
.image-row-main {
  display: grid;
  grid-template-columns: minmax(110px, .8fr) minmax(120px, 1fr) minmax(160px, 1.4fr);
  gap: 10px;
  width: 100%;
  text-align: left;
  align-items: center;
  background: transparent;
  color: var(--ink);
  border: 0;
  padding: 4px;
}
.image-edit-row {
  display: grid;
  grid-template-columns: minmax(130px, .7fr) minmax(160px, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-top: 8px;
}
.subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.subtab {
  background: #fffdfa;
  color: var(--ink);
  border: 1px solid var(--line);
}
.subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.subtab.disabled {
  opacity: .55;
  cursor: not-allowed;
}
.fact {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(180deg, #fffdfa 0%, var(--blue-soft) 100%);
}
.fact strong { display: block; font-size: 13px; color: var(--blue); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .03em; }
.editable-context {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}
.editable-context textarea {
  min-height: 150px;
  background: #fffdfa;
}
.editable-context button {
  justify-self: start;
}

.image-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  align-items: start;
}
#imageStage {
  position: relative;
  width: 100%;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#fullImage {
  display: block;
  width: 100%;
  height: auto;
}
#tileOverlay {
  position: absolute;
  inset: 0;
}
.tile {
  position: absolute;
  border: 1px solid rgba(255,255,255,.55);
  background: rgba(32, 106, 93, .10);
}
.tile:hover { outline: 2px solid white; z-index: 3; }
.tile.flagged { background: rgba(199, 125, 28, .35); border-color: rgba(199,125,28,.95); }
.tile.error { background: rgba(178, 59, 59, .25); border-color: rgba(178,59,59,.9); }
.tile.selected {
  outline: 3px solid var(--blue);
  background: rgba(47, 93, 124, .34);
  border-color: rgba(47, 93, 124, .98);
  z-index: 4;
}
.tile.search-match {
  outline: 4px solid #ffd966;
  background: rgba(255, 217, 102, .38);
  border-color: rgba(255, 217, 102, .98);
  box-shadow: 0 0 16px rgba(255, 217, 102, .75);
  z-index: 4;
}
.tile.active-tile {
  outline: 4px solid #fff;
  box-shadow: 0 0 0 2px rgba(47, 93, 124, .95), 0 0 18px rgba(255,255,255,.65);
  z-index: 5;
}
.tile-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  max-height: calc(100vh - 130px);
  overflow: auto;
}
.tile-panel h2 { margin-top: 0; color: var(--accent-dark); }
.tile-preview-summary {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: #fffdfa;
}
.tile-preview-summary p:first-child { margin-top: 0; }
.tile-preview-summary button { margin-top: 8px; }
.tile-search {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: var(--sand);
}
.tile-search label { margin-bottom: 8px; }
.search-results {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}
.search-results p { margin: 0; color: var(--muted); }
.search-hit-list {
  display: grid;
  gap: 5px;
  max-height: 160px;
  overflow: auto;
}
.search-hit {
  text-align: left;
  background: #fffdfa;
  color: var(--ink);
}
.chip-preview { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #111; }
.hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: -4px;
}
.bucket-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 12px;
}
.bucket-card {
  border: 2px solid #bfb5a8;
  border-radius: 10px;
  padding: 12px;
  background: #fffdfa;
  display: grid;
  gap: 10px;
  box-shadow: 0 3px 8px rgba(35,31,32,.08);
  border-top: 7px solid var(--muted);
  border-left: 2px solid #bfb5a8;
  margin-bottom: 0;
}
.bucket-card.user {
  border-top-color: var(--accent);
}
.bucket-card.source-site_type_default {
  border-top-color: var(--blue);
}
.bucket-card.source-osint_watch_marker {
  border-top-color: var(--amber);
}
.bucket-card.source-user {
  border-top-color: var(--accent);
}
.bucket-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
}
.bucket-card header > div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.bucket-index {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.bucket-card input,
.bucket-card textarea {
  background: #fff;
  border-color: #bfb5a8;
}
.bucket-card label {
  color: var(--accent-dark);
  font-weight: 750;
}
.bucket-card textarea {
  min-height: 58px;
}
.bucket-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}
.bucket-toggle input {
  width: auto;
}
.bucket-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 22px;
}
.bucket-source-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(255,255,255,.72);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-weight: 700;
}
.bucket-card p {
  margin: 0;
}
.bucket-keywords {
  color: var(--blue);
  font-size: 13px;
}
.activity-buckets-main {
  margin-top: 12px;
}
.activity-buckets-main .bucket-cards {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.bucket-add {
  margin: 10px 0;
}
.bucket-add summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 700;
  margin-bottom: 8px;
}
.bucket-matrix-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 14px;
}
.bucket-matrix {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fffdfa;
}
.bucket-matrix th,
.bucket-matrix td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  vertical-align: top;
  text-align: left;
}
.bucket-matrix th {
  background: var(--sand);
  color: var(--accent-dark);
  font-size: 13px;
}
.bucket-matrix td span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.trend-pill {
  display: inline-block !important;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--sand);
  color: var(--ink) !important;
  font-weight: 700;
}
.trend-pill.increasing { background: #fff2dd; color: #87520e !important; }
.trend-pill.same { background: var(--blue-soft); color: var(--blue) !important; }
.trend-pill.decreasing { background: #eaf5ef; color: #2f7654 !important; }
.trend-pill.indeterminate { background: #eeeae2; color: var(--muted) !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: var(--blue-soft);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.selected-chip-name {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.remove-chip {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 999px;
  line-height: 1;
  color: var(--red);
  background: #fffdfa;
}
.mini-list { padding-left: 18px; }
.mini-list li { margin-bottom: 6px; }
.empty { color: var(--muted); }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(18, 25, 32, .55);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(1100px, 96vw);
  height: min(820px, 92vh);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
}
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.modal-card h2 { margin: 0; }
.modal-card p { margin: 0; color: var(--muted); }
.modal-card textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  overflow: auto;
  resize: vertical;
}
#osintBriefModal .modal-card {
  height: auto;
  max-height: 92vh;
  grid-template-rows: auto minmax(0, 1fr);
}
#osintBriefText {
  min-height: 360px;
  max-height: 72vh;
  font-family: "Source Sans 3", "Source Sans Pro", ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.modal-card pre {
  height: 100%;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
}
.modal-card-small {
  width: min(720px, 94vw);
  height: min(560px, 88vh);
  grid-template-rows: auto auto 1fr auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
}
@media (max-width: 1050px) {
  .topbar { grid-template-columns: 1fr; }
  .topbar-actions { min-width: 0; width: 100%; align-items: stretch; }
  .auth-bar { justify-content: flex-start; }
  .case-picker { flex-wrap: wrap; justify-content: flex-end; }
  .case-picker select { width: min(14rem, 100%); max-width: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .image-shell { grid-template-columns: 1fr; }
}

/* =========================================================
   Chrome polish pass (palette unchanged, layout only)
   ========================================================= */

/* Sticky topbar with hairline shadow */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 14px 24px;
  box-shadow: 0 1px 0 var(--line), 0 6px 14px -10px rgba(35,31,32,.18);
}
.topbar h1 { font-size: 24px; letter-spacing: .005em; }
.topbar p {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 700;
  color: var(--muted);
  margin-top: 6px;
}

/* Tighter, more refined panels */
.panel {
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 0 rgba(35,31,32,.04), 0 1px 3px rgba(35,31,32,.05);
}
.panel h2 {
  font-family: "Source Sans 3", "Source Sans Pro", ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h2::before {
  content: "";
  width: 3px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
  display: inline-block;
}

/* Sidebar refinement */
.sidebar { padding: 12px; }
.sidebar .panel { padding: 12px 14px; margin-bottom: 12px; }

/* Tabs — capsule, underline-active */
.tabs {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 0;
  gap: 2px;
  margin-bottom: 14px;
}
.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  text-transform: uppercase;
}
.tab:hover { color: var(--accent); background: transparent; border-color: transparent; }
.tab.active {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

/* Subtabs — quieter chips */
.subtab {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
}

/* Buttons — flatter, tighter */
button, .button-link {
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  transition: border-color .12s, background .12s, color .12s;
}
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Inputs — consistent height + radius */
select, input, textarea {
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

/* Labels — uppercase micro-caps for clearer hierarchy */
label {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
}

/* Facts strip — denser, mono values */
.facts {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1px;
  overflow: hidden;
}
.fact {
  background: var(--panel);
  border: 0;
  border-radius: 0;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.fact strong {
  font-family: "Source Sans 3", "Source Sans Pro", ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  letter-spacing: .14em;
  font-weight: 800;
  color: var(--blue);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.fact.editable-context {
  grid-column: 1 / -1;
  font-family: "Source Sans 3", "Source Sans Pro", ui-sans-serif, system-ui, sans-serif;
}

/* Status box — quiet terminal look on cream */
#statusBox {
  background: #faf6ee;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #4a463f;
}

/* Cards — flatter, thinner top stripe */
.source-card, .bucket-card {
  border-width: 1px;
  border-top-width: 3px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(35,31,32,.06);
  padding: 12px 14px;
}
.source-card header strong { font-size: 14px; }
.source-meta span,
.source-badge,
.bucket-source-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 3px 7px;
}

/* Image registry rows — tighter */
.image-row {
  border-radius: 6px;
  padding: 6px 8px;
}
.image-row-main { font-size: 13px; }
.image-row-main strong { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; }

/* Tile panel + image stage — sharper edges */
#imageStage, .tile-panel { border-radius: 8px; }
.tile-panel { padding: 12px 14px; }
.tile-panel h2 { font-size: 12px; }
.tile-preview-summary, .tile-search {
  border-radius: 6px;
  padding: 10px 12px;
}

/* Chips — refined */
.chip {
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}

/* Status / state badge utility (drop-in for any JS-rendered pill) */
.badge {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}
.badge.ok      { color: #2f7654; border-color: #c2dccb; background: #f1f8f3; }
.badge.warn    { color: #87520e; border-color: #e8d4ab; background: #fff6e6; }
.badge.error   { color: var(--red); border-color: #d9b7b7; background: #fbeded; }
.badge.running { color: var(--blue); border-color: #b8d2e0; background: var(--blue-soft); }

/* Mono utility for coords / timestamps / IDs */
.mono, time, code, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* Trend pills — slightly stronger borders */
.trend-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1px solid transparent;
}
.trend-pill.increasing { border-color: #e8d4ab; }
.trend-pill.same       { border-color: #b8d2e0; }
.trend-pill.decreasing { border-color: #c2dccb; }
.trend-pill.indeterminate { border-color: var(--line); }

/* Field groups — quieter */
.field-group { border-radius: 6px; padding: 10px 12px; }
.field-group h3 { font-size: 10px; letter-spacing: .14em; }

/* Nested rerun panel — tone down gradient */
.nested-panel {
  background: linear-gradient(180deg, #fbf3ea 0%, #fffdfa 100%);
  border-radius: 8px;
  padding: 12px;
}

/* Modal — sharper corners + softer overlay */
.modal { background: rgba(35,31,32,.42); backdrop-filter: blur(2px); }
.modal-card { border-radius: 10px; }

/* Polished scrollbars (webkit) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #d8d1c7; border-radius: 5px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #b8af9f; }

/* Case picker: align select height with adjacent buttons */
.case-picker select {
  height: auto;
  min-height: 36px;
  line-height: 1.25;
  padding: 7px 28px 7px 10px;
  font-size: 13px;
}
.case-picker button {
  height: 36px;
  line-height: 1;
}
.case-picker .settings-btn { padding: 0 10px; gap: 5px; font-size: 13px; }
.case-picker .keys-pill { line-height: 1; }
.case-picker .danger { padding: 0 11px; }

/* ---------------------------------------------------------------
   Settings button + keys status pill (per-user API keys)
   --------------------------------------------------------------- */
.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 6px 8px;          /* tighter than default button */
  font-size: 13px;
}
.keys-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 0 5px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #f1f8f3;
  color: #2f7654;
  font-weight: 700;
  line-height: 1;
}
.keys-pill.missing {
  background: #fbeded;
  border-color: #d9b7b7;
  color: var(--red);
}

.auth-status {
  font-size: 12px;
  color: var(--muted);
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-logout {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  flex-shrink: 0;
}

.auth-logout:hover {
  color: var(--text);
  text-decoration: underline;
}

.auth-admin-btn {
  font-size: 12px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.users-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 14px;
}

.users-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.users-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.users-row-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.users-row-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.users-row .danger {
  padding: 4px 8px;
  font-size: 12px;
}

@media (max-width: 700px) {
  .users-form {
    grid-template-columns: 1fr;
  }
  .users-row {
    grid-template-columns: 1fr;
  }
}

.case-access-owner-label {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(139, 35, 50, 0.06);
  color: var(--text);
  font-size: 13px;
}

/* Settings modal layout */
.settings-grid {
  display: grid;
  gap: 22px;                  /* more breathing room between fields */
  padding: 8px 2px 4px;
}
.settings-grid > label {
  display: grid;
  gap: 8px;
}
.settings-grid .hint {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  font-size: 11px;
  color: var(--muted);
}
.settings-grid input[type="password"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 10px 12px;
}
/* Match the provider dropdown height/padding to the key inputs and give it a
   consistent custom chevron instead of the native control. */
.settings-grid select {
  padding: 10px 12px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23857b6c' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.settings-grid > label.hidden { display: none; }
.settings-radio-group {
  display: grid;
  gap: 10px;                  /* breathing room between heading + options */
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 4px;
}
.settings-radio-heading {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
}
.settings-radio-options {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.settings-radio {
  display: inline-flex;
  align-items: center;        /* center radio with its label text */
  gap: 8px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  margin: 0;
}
.settings-radio input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: 0 0 auto;             /* prevent flex stretching */
  accent-color: var(--accent);
}
.modal-actions { gap: 8px; padding-top: 4px; }
.modal-actions button + button { margin-left: auto; }

/* Inline indicator/flip tags */
.tag {
  display: inline-block;
  margin: 0 4px 3px 0;
  padding: 1px 8px;
  background: #1c2636;
  border: 1px solid #2b3a52;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
}
.bucket-sources { margin-top: 6px; }
.bucket-sources ul { margin: 4px 0 0; padding-left: 18px; }
.bucket-sources li { margin: 2px 0; }
