/* ── Layout ── */
:root {
  --footer-height: 48px;
  --brand-gold: #f0a500;
  --brand-blue: #4a90d9;
  --brand-green: #3dba6f;
  --bg-dark: #1a1a1a;
  --bg-card: #272727;
  --bg-surface: #333333;
  --text-muted-custom: #8892a4;
}

body {
  background-color: var(--bg-dark);
  color: #e0e6f0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, color 0.2s;
}

main {
  flex: 1;
  padding-bottom: calc(var(--footer-height) + 2rem);
}

/* ── Navbar ── */
.navbar {
  background-color: var(--bg-card) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--brand-gold) !important;
  letter-spacing: 0.03em;
}

.nav-link {
  color: #c8d0e0 !important;
  transition: color 0.15s;
}

.nav-link:hover,
.nav-link.active {
  color: var(--brand-gold) !important;
}

/* ── Footer ── */
footer {
  height: var(--footer-height);
  background-color: var(--bg-card);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  color: var(--text-muted-custom);
  font-size: 0.85rem;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}

.footer-content {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.footer-right {
  position: absolute;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.footer-link {
  color: var(--text-muted-custom);
  text-decoration: none;
  font-size: 0.85rem;
}

.footer-link:hover {
  color: var(--brand-gold);
  text-decoration: none;
}

.squiblydoo-icon {
  height: 24px;
  width: auto;
  opacity: 0.75;
  transition: opacity 0.15s;
}

.squiblydoo-icon:hover {
  opacity: 1;
}

/* ── Cards ── */
.card {
  background-color: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
}

.card-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 600;
}

/* ── Hero section ── */
.hero {
  padding: 4rem 0 3rem;
  text-align: center;
}

.hero h1 {
  font-size: 2.8rem;
  font-weight: 800;
  color: #ffffff;
}

.hero .tagline {
  font-size: 1.15rem;
  color: var(--text-muted-custom);
  max-width: 620px;
  margin: 0.75rem auto 0;
}

.feature-card {
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color: inherit;
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

/* ── Badge colors ── */
.badge-root { background-color: var(--brand-gold); color: #000; }
.badge-intermediate { background-color: var(--brand-blue); color: #fff; }
.badge-leaf { background-color: var(--brand-green); color: #fff; }
.badge-phantom_root { background-color: transparent; color: #8892a4; border: 1px dashed #8892a4; }
.badge-revoked { background-color: #e74c3c; color: #fff; }
.badge-expired { background-color: #7f8c8d; color: #fff; }

/* ── Certificate chain visualization ── */
#chain-viz {
  width: 100%;
  min-height: 300px;
  background: var(--bg-surface);
  border-radius: 0.75rem;
  overflow: hidden;
}

#chain-viz .node circle {
  stroke-width: 2.5px;
}

#chain-viz .node.root circle { fill: var(--brand-gold); stroke: #c8860a; }
#chain-viz .node.intermediate circle { fill: var(--brand-blue); stroke: #2a6aad; }
#chain-viz .node.leaf circle { fill: var(--brand-green); stroke: #2a8a50; }

/* Phantom root — grayed out, dashed border, not filled */
#chain-viz .node.phantom_root circle {
  fill: rgba(136, 146, 164, 0.12);
  stroke: rgba(136, 146, 164, 0.5);
  stroke-dasharray: 6, 4;
}
#chain-viz .node.phantom_root text { fill: rgba(200, 208, 224, 0.45); }
#chain-viz .node.phantom_root { cursor: default; }

#chain-viz .node text {
  font-size: 12px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* node-icon fill is set inline (white on coloured circle) */
#chain-viz .node-label { fill: #c8d0e0; }
#chain-viz .node-type  { fill: #8892a4; }

#chain-viz .link {
  fill: none;
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 2px;
}

/* ── Custom cert section collapsible (replaces Bootstrap accordion for dynamic content) ── */
.cert-section-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #e0e6f0;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.cert-section-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.cert-section-btn .cert-chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.cert-section-btn.open .cert-chevron {
  transform: rotate(180deg);
}

.cert-section-body {
  display: none;
}

.cert-section-body.open {
  display: block;
}

/* ── Cert field table ── */
.cert-field-table th {
  color: var(--text-muted-custom);
  font-weight: 500;
  width: 35%;
  vertical-align: top;
}

.cert-field-table td {
  font-size: 0.875rem;
  word-break: break-all;
  color: #e0e6f0;
}

/* Override Bootstrap dark-mode <code> color and size inside the table.
   Bootstrap sets code to ~pinkish-red at 0.875em, which compounds to unreadably
   small and low-contrast against our dark background. */
.cert-field-table td code {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: inherit;
  color: #a8d8f0;
  background: transparent;
  padding: 0;
}

/* ── DN attribute rows (Subject / Issuer breakdown) ── */
.dn-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 3px;
}

.dn-attr {
  color: var(--text-muted-custom);
  font-size: 0.78rem;
  min-width: 140px;
  flex-shrink: 0;
}

.dn-value {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: inherit;
  color: #a8d8f0;
  background: transparent;
  padding: 0;
  word-break: break-all;
}

.gloss-icon {
  cursor: pointer;
  color: var(--brand-blue);
  margin-left: 4px;
  font-size: 0.8rem;
  user-select: none;
}

.gloss-icon:hover {
  color: #7ab8f5;
}

/* Give popovers a readable max-width and allow text selection */
.popover {
  max-width: 320px;
}

.popover-body {
  user-select: text;
  font-size: 0.85rem;
}

/* ── Forms ── */
.form-control,
.form-select {
  background-color: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.15);
  color: #e0e6f0;
}

.form-control:focus,
.form-select:focus {
  background-color: var(--bg-surface);
  border-color: var(--brand-blue);
  color: #e0e6f0;
  box-shadow: 0 0 0 0.2rem rgba(74, 144, 217, 0.25);
}

.form-control::placeholder {
  color: var(--text-muted-custom);
}

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 0.75rem;
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--brand-blue);
  background: rgba(74, 144, 217, 0.08);
}

.dropzone .drop-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted-custom);
}

/* ── CA tree ── */
.ca-tree-node {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ca-tree-node.root { background: rgba(240, 165, 0, 0.12); border-left: 3px solid var(--brand-gold); }
.ca-tree-node.intermediate { background: rgba(74, 144, 217, 0.12); border-left: 3px solid var(--brand-blue); }
.ca-tree-node.leaf { background: rgba(61, 186, 111, 0.12); border-left: 3px solid var(--brand-green); }
.ca-tree-node.revoked { opacity: 0.5; border-left-color: #e74c3c; }

.ca-tree-children { margin-left: 1.75rem; }

/* ── Buttons ── */
.btn-primary {
  background-color: var(--brand-blue);
  border-color: var(--brand-blue);
}

.btn-primary:hover {
  background-color: #2a6aad;
  border-color: #2a6aad;
}

.btn-warning {
  background-color: var(--brand-gold);
  border-color: var(--brand-gold);
  color: #000;
}

.btn-warning:hover {
  background-color: #c8860a;
  border-color: #c8860a;
  color: #000;
}

/* ── Alerts ── */
.alert {
  border-radius: 0.6rem;
}

/* ── Tooltips ── */
.tooltip-inner {
  max-width: 320px;
  text-align: left;
  font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════════════════════
   LIGHT MODE  —  mid-tone blue-gray palette (not pure white)
   Applied when <html data-theme="light">
   ═══════════════════════════════════════════════════════════════ */

[data-theme="light"] {
  /* Layout colours */
  --bg-dark:           #e6eaf4;   /* body background   */
  --bg-card:           #f1f3fb;   /* cards, navbar, footer */
  --bg-surface:        #d8ddf0;   /* card headers      */
  --text-muted-custom: #6a748e;

  /* Brand colours — slightly darkened for readability on light bg */
  --brand-gold:  #b87800;
  --brand-blue:  #1a5fb0;
  --brand-green: #1e7a44;
}

[data-theme="light"] body {
  color: #1e2438;
}

/* Borders: swap white-alpha for black-alpha */
[data-theme="light"] .card,
[data-theme="light"] .navbar,
[data-theme="light"] footer {
  border-color: rgba(0, 0, 0, 0.1) !important;
}

[data-theme="light"] .card-header {
  border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .cert-section-btn {
  color: #1e2438;
  border-top-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .cert-section-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* Form controls */
[data-theme="light"] .form-control,
[data-theme="light"] .form-select {
  background-color: #f8f9fe;
  border-color: rgba(0, 0, 0, 0.18);
  color: #1e2438;
}

[data-theme="light"] .form-control:focus,
[data-theme="light"] .form-select:focus {
  background-color: #f8f9fe;
  color: #1e2438;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 0.2rem rgba(26, 95, 176, 0.2);
}

[data-theme="light"] .form-control::placeholder {
  color: #9aa0b4;
}

[data-theme="light"] .form-text {
  color: var(--text-muted-custom);
}

/* Code — dark blue on light background */
[data-theme="light"] code,
[data-theme="light"] .cert-field-table td code,
[data-theme="light"] .dn-value {
  color: #1a5fb0;
}

/* Cert field table text */
[data-theme="light"] .cert-field-table td { color: #1e2438; }
[data-theme="light"] .cert-field-table th { color: var(--text-muted-custom); }
[data-theme="light"] .dn-attr             { color: var(--text-muted-custom); }

/* Dropzone */
[data-theme="light"] .dropzone {
  border-color: rgba(0, 0, 0, 0.18);
}
[data-theme="light"] .dropzone:hover,
[data-theme="light"] .dropzone.dragover {
  border-color: var(--brand-blue);
  background: rgba(26, 95, 176, 0.06);
}

/* CA tree nodes — bump opacity so they read on lighter background */
[data-theme="light"] .ca-tree-node.root         { background: rgba(184, 120,  0, 0.1); }
[data-theme="light"] .ca-tree-node.intermediate { background: rgba(26,   95, 176, 0.1); }
[data-theme="light"] .ca-tree-node.leaf         { background: rgba(30,  122,  68, 0.1); }

/* D3 chain viz */
[data-theme="light"] #chain-viz { background: var(--bg-surface); }

[data-theme="light"] #chain-viz .link {
  stroke: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] #chain-viz .node-label { fill: #2c3555; }
[data-theme="light"] #chain-viz .node-type  { fill: #6a748e; }

[data-theme="light"] #chain-viz .node.phantom_root circle {
  fill: rgba(60, 70, 120, 0.06);
  stroke: rgba(60, 70, 120, 0.3);
}
[data-theme="light"] #chain-viz .node.phantom_root text {
  fill: rgba(50, 60, 100, 0.45);
}

/* Gloss icon */
[data-theme="light"] .gloss-icon { color: var(--brand-blue); }

/* Nav link */
[data-theme="light"] .nav-link        { color: #3a4260 !important; }
[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link.active { color: var(--brand-gold) !important; }

/* Navbar brand stays gold */
[data-theme="light"] .navbar-brand { color: var(--brand-gold) !important; }

/* Footer text */
[data-theme="light"] footer { color: var(--text-muted-custom); }
[data-theme="light"] .footer-link { color: var(--text-muted-custom); }

/* Theme toggle button icon */
#themeToggle { transition: opacity 0.15s; }
#themeToggle:hover { opacity: 0.8; }
