/* ============================================================================
   GFS Data Tagger · v10 cobalt design tokens
   Visual data tagger UI — PDF + Markdown + NS field sidebar (3-pane)
   ============================================================================ */

:root {
  --midnight: #051B3A;
  --cobalt: #092F64;
  --navy: #1A5799;
  --tufts: #468BE6;
  --jordy: #93BFEF;
  --alice: #E9F5FF;
  --eerie: #1F1F1F;
  --charcoal: #2D2D2D;
  --graphite: #4B5F7A;
  --slate: #6B7280;
  --steel: #9CA3AF;
  --silver: #D9E1EA;
  --fog: #F3F6FA;
  --white: #FFFFFF;
  --success: #0F766E;
  --warning: #B45309;
  --error: #DC2626;
  --shadow-sm: 0 1px 3px rgba(9,47,100,0.08);
  --shadow-md: 0 4px 16px rgba(9,47,100,0.2);
  --shadow-lg: 0 6px 24px rgba(9,47,100,0.3);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 12px;

  /* 12 distinct tag colors, color-blind friendly palette */
  --tag-1: #2563EB;
  --tag-2: #DC2626;
  --tag-3: #0F766E;
  --tag-4: #B45309;
  --tag-5: #7C3AED;
  --tag-6: #DB2777;
  --tag-7: #0891B2;
  --tag-8: #65A30D;
  --tag-9: #EA580C;
  --tag-10: #4F46E5;
  --tag-11: #BE185D;
  --tag-12: #047857;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--white);
  color: var(--eerie);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  height: 100%;
}
body { display: flex; flex-direction: column; min-height: 100vh; overflow: hidden; }

.mono { font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--slate); }

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

/* ---- Top nav ------------------------------------------------------------ */
.dt-topnav {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px) saturate(1.1);
  -webkit-backdrop-filter: blur(20px) saturate(1.1);
  border-bottom: 1px solid var(--silver);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  flex-shrink: 0;
}
.dt-topnav .tn-logo {
  font-weight: 700;
  color: var(--cobalt);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: 12px;
}
.dt-topnav .tn-crumb { color: var(--slate); }
.dt-topnav .tn-crumb a { color: var(--tufts); }
.dt-topnav .tn-spacer { flex: 1 1 auto; }
.dt-topnav label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--slate);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.dt-topnav select, .dt-topnav input[type="search"] {
  padding: 5px 8px;
  border: 1px solid var(--silver);
  background: var(--white);
  color: var(--eerie);
  font-size: 11px;
  border-radius: var(--radius-md);
  font-family: inherit;
}
.dt-topnav select:focus, .dt-topnav input:focus {
  outline: 2px solid var(--tufts);
  outline-offset: 1px;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--silver);
  background: var(--white);
  color: var(--eerie);
  border-radius: var(--radius-md);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.btn:hover:not(:disabled) { background: var(--alice); border-color: var(--tufts); color: var(--cobalt); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--cobalt); color: var(--white); border-color: var(--cobalt); }
.btn-primary:hover:not(:disabled) { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--fog); }
.btn-danger { color: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: var(--error); color: var(--white); }

/* ---- 3-pane layout ----------------------------------------------------- */
.dt-main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(280px, 320px);
  flex: 1 1 auto;
  overflow: hidden;
  border-bottom: 1px solid var(--silver);
}
.dt-pane { overflow: auto; position: relative; min-width: 0; }
.dt-pane + .dt-pane { border-left: 1px solid var(--silver); }

.pane-head {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--fog);
  border-bottom: 1px solid var(--silver);
  padding: 8px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  color: var(--slate);
  display: flex;
  align-items: center;
  gap: 10px;
}
.pane-head .pane-title { color: var(--cobalt); }
.pane-head .pane-spacer { flex: 1 1 auto; }

/* ---- PDF pane ----------------------------------------------------------- */
.pdf-drop {
  border: 2px dashed var(--silver);
  border-radius: var(--radius-md);
  margin: 24px;
  padding: 40px;
  text-align: center;
  color: var(--slate);
  background: var(--fog);
  transition: all .2s var(--ease);
  cursor: pointer;
}
.pdf-drop.dragover {
  border-color: var(--tufts);
  background: var(--alice);
  color: var(--cobalt);
}
.pdf-drop strong { color: var(--cobalt); display: block; margin-bottom: 6px; font-size: 14px; }
.pdf-drop input[type="file"] { display: none; }

.pdf-canvas-wrap {
  position: relative;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.pdf-page {
  position: relative;
  display: inline-block;
  box-shadow: var(--shadow-sm);
  background: var(--white);
}
.pdf-page canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.pdf-page .tag-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  cursor: crosshair;
}
.pdf-page .tag-overlay.disabled { cursor: default; pointer-events: none; }
.pdf-page .tag-rect {
  position: absolute;
  border: 2px solid;
  background: rgba(70,139,230,0.12);
  pointer-events: auto;
  cursor: pointer;
  transition: box-shadow .15s var(--ease);
}
.pdf-page .tag-rect:hover { box-shadow: 0 0 0 3px rgba(70,139,230,0.25); }
.pdf-page .tag-rect .tag-label {
  position: absolute;
  top: -18px;
  left: -2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--white);
  white-space: nowrap;
  pointer-events: none;
}
.pdf-page .tag-rect.drawing {
  border-style: dashed;
  background: rgba(70,139,230,0.20);
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--silver);
  background: var(--white);
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--slate);
  flex-wrap: wrap;
}
.pdf-toolbar .page-info { color: var(--cobalt); font-weight: 600; }

/* ---- Markdown pane ----------------------------------------------------- */
.md-pane-body {
  padding: 20px 24px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--eerie);
  user-select: text;
}
.md-pane-body.empty { color: var(--slate); padding-top: 60px; text-align: center; }
.md-pane-body p { margin-bottom: 10px; }
.md-pane-body h1, .md-pane-body h2, .md-pane-body h3 {
  color: var(--cobalt);
  font-weight: 700;
  margin: 18px 0 8px;
}
.md-pane-body h1 { font-size: 18px; }
.md-pane-body h2 { font-size: 15px; }
.md-pane-body h3 { font-size: 13px; }
.md-pane-body table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
  width: 100%;
}
.md-pane-body th, .md-pane-body td {
  border: 1px solid var(--silver);
  padding: 4px 8px;
  text-align: left;
}
.md-pane-body th { background: var(--fog); font-weight: 600; }
.md-pane-body code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  background: var(--fog);
  padding: 1px 4px;
  border-radius: 2px;
}
.md-pane-body pre {
  background: var(--fog);
  padding: 10px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 10px 0;
}
.md-pane-body ::selection { background: var(--alice); color: var(--cobalt); }

.md-tag-span {
  border-radius: 2px;
  padding: 1px 2px;
  cursor: pointer;
  transition: filter .15s var(--ease);
}
.md-tag-span:hover { filter: brightness(0.92); }

/* ---- Sidebar (NS fields) ----------------------------------------------- */
.sidebar {
  background: var(--fog);
}
.sidebar-search { padding: 10px 14px; border-bottom: 1px solid var(--silver); background: var(--white); }
.sidebar-search input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--silver);
  border-radius: var(--radius-md);
  font-size: 12px;
  font-family: inherit;
}
.sidebar-search input:focus { outline: 2px solid var(--tufts); outline-offset: 1px; border-color: var(--tufts); }

.field-group { padding: 8px 0; border-bottom: 1px solid var(--silver); }
.field-group-heading {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--slate);
  font-weight: 600;
  padding: 4px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--eerie);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .12s var(--ease);
}
.field-item:hover { background: var(--alice); }
.field-item.active {
  background: var(--white);
  border-left-color: var(--tufts);
  color: var(--cobalt);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.field-item.has-tag { color: var(--cobalt); }
.field-item-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--slate);
}
.field-item .tag-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.field-item .check {
  color: var(--success);
  font-weight: 700;
  font-size: 11px;
}

/* ---- Strategy popover -------------------------------------------------- */
.popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5,27,58,0.40);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.popover-backdrop.open { display: flex; }
.popover {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--silver);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: 100%;
  padding: 20px;
  max-height: 88vh;
  overflow-y: auto;
}
.popover h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--cobalt);
  margin-bottom: 6px;
}
.popover .popover-sub { font-size: 12px; color: var(--slate); margin-bottom: 14px; }
.popover label.field-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--slate);
  font-weight: 600;
  margin: 12px 0 4px;
}
.popover input[type="text"], .popover textarea, .popover select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--silver);
  border-radius: var(--radius-md);
  font-size: 12px;
  font-family: inherit;
  color: var(--eerie);
  background: var(--white);
}
.popover textarea { min-height: 70px; resize: vertical; font-family: 'IBM Plex Mono', monospace; }
.popover input:focus, .popover textarea:focus, .popover select:focus {
  outline: 2px solid var(--tufts);
  outline-offset: 1px;
  border-color: var(--tufts);
}
.popover .strategy-help {
  font-size: 11px;
  color: var(--graphite);
  background: var(--fog);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  margin: 8px 0;
  line-height: 1.5;
}
.popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---- Bottom tag list --------------------------------------------------- */
.tag-list-wrap {
  background: var(--fog);
  border-top: 1px solid var(--silver);
  max-height: 260px;
  overflow-y: auto;
  flex-shrink: 0;
}
.tag-list-head {
  position: sticky;
  top: 0;
  background: var(--fog);
  border-bottom: 1px solid var(--silver);
  padding: 8px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--slate);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tag-list-head .count-pill {
  background: var(--cobalt);
  color: var(--white);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
}
.tag-row {
  display: grid;
  grid-template-columns: 16px minmax(0,1fr) 1fr 1fr 80px;
  gap: 10px;
  align-items: center;
  padding: 6px 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--silver);
  background: var(--white);
}
.tag-row:hover { background: var(--alice); }
.tag-row .tag-swatch { width: 12px; height: 12px; border-radius: 2px; }
.tag-row .tag-field { font-weight: 600; color: var(--cobalt); }
.tag-row .tag-strategy {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--slate);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tag-row .tag-sample {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--graphite);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-row .tag-actions { display: flex; gap: 4px; justify-content: flex-end; }
.tag-row button {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--silver);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--slate);
  font-size: 11px;
}
.tag-row button:hover { background: var(--alice); color: var(--cobalt); border-color: var(--tufts); }
.tag-row button.danger:hover { background: var(--error); color: var(--white); border-color: var(--error); }

.tag-list-empty {
  padding: 20px;
  text-align: center;
  color: var(--slate);
  font-size: 12px;
}

/* ---- Test extraction result panel ------------------------------------- */
.extract-result {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 420px;
  background: var(--white);
  border-left: 1px solid var(--silver);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.extract-result.open { display: flex; }
.extract-result-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--silver);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--fog);
}
.extract-result-head h2 {
  font-size: 14px;
  color: var(--cobalt);
  font-weight: 700;
  flex: 1 1 auto;
}
.extract-result-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 18px; }
.extract-row {
  border-bottom: 1px solid var(--silver);
  padding: 10px 0;
}
.extract-row .field { font-weight: 600; color: var(--cobalt); font-size: 12px; }
.extract-row .value { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--eerie); margin-top: 3px; word-break: break-word; }
.extract-row .conf {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--slate);
  margin-top: 3px;
}
.extract-row.error .value { color: var(--error); }
.extract-row.tbd .value { color: var(--warning); font-style: italic; }

/* ---- Toast ------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--cobalt);
  color: var(--white);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  box-shadow: var(--shadow-md);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}
.toast.show { opacity: 1; }
.toast.error { background: var(--error); }
.toast.success { background: var(--success); }

/* ---- Loading / status -------------------------------------------------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.status-pill.ready { background: var(--alice); color: var(--cobalt); }
.status-pill.loading { background: var(--fog); color: var(--slate); }
.status-pill.error { background: rgba(220,38,38,0.10); color: var(--error); }
.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---- Mobile responsive (stack vertically) ------------------------------ */
@media (max-width: 1024px) {
  .dt-main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 40vh) minmax(200px, 30vh) minmax(200px, 30vh);
    overflow: auto;
  }
  .dt-pane + .dt-pane { border-left: 0; border-top: 1px solid var(--silver); }
  .tag-list-wrap { max-height: 200px; }
  .extract-result { width: 100%; }
  body { overflow: auto; }
}

/* ---- A11y -------------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--tufts); outline-offset: 2px; border-radius: 2px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ---- Print ------------------------------------------------------------- */
@media print {
  .dt-topnav, .tag-list-wrap, .extract-result { display: none; }
}
