/* ==========================================================================
 * iPurple.team Navigator — styles
 * Theme variables are injected at runtime from js/config.js (theme block).
 * Fallback values below are used until config loads.
 * ========================================================================== */
:root {
  --bg: #0a0a0f;
  --bg-elev: #14111c;
  --bg-cell: #1b1726;
  --bg-cell-hover: #2a2138;
  --border: #2d2440;
  --text: #e8e3f2;
  --text-dim: #9a8fb5;
  --purple: #8b5cf6;
  --purple-bright: #a855f7;
  --purple-deep: #6d28d9;
  --accent: #c084fc;
  --danger: #f43f5e;
  --shadow: rgba(139, 92, 246, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

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

/* ---------------- Header ---------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--purple-deep), var(--purple-bright));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 0 16px var(--shadow);
  letter-spacing: -0.5px;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.3px; }
.brand-name .accent { color: var(--accent); }
.brand-tagline { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* ---------------- Search ---------------- */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  min-width: 320px;
  transition: border-color .15s, box-shadow .15s;
}
.search-wrap:focus-within {
  border-color: var(--purple-bright);
  box-shadow: 0 0 0 3px var(--shadow);
}
.search-icon { color: var(--text-dim); flex-shrink: 0; }
#searchInput {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 9px 0;
  width: 100%;
  font-size: 13px;
}
#searchInput::placeholder { color: var(--text-dim); }
.search-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  display: none;
}
.search-clear:hover { color: var(--accent); }
.search-count {
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
  min-width: 0;
}

/* ---------------- Add button ---------------- */
.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--purple-deep), var(--purple-bright));
  border: 1px solid var(--purple-bright);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 0 14px var(--shadow);
}
.add-btn:hover { filter: brightness(1.12); }
.add-btn .plus { font-size: 16px; line-height: 1; }

/* ---------------- Menus ---------------- */
.menus { display: flex; gap: 4px; }
.menu { position: relative; }
.menu-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}
.menu-btn:hover, .menu.open .menu-btn {
  background: var(--bg-cell);
  border-color: var(--border);
}
.menu-btn .caret { font-size: 9px; color: var(--text-dim); }
.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  min-width: 220px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.55), 0 0 0 1px var(--shadow);
  display: none;
  z-index: 60;
}
.menu.open .menu-dropdown { display: block; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}
.menu-item:hover { background: var(--purple-deep); color: #fff; }
.menu-item .ext { font-size: 10px; color: var(--text-dim); }
.menu-item:hover .ext { color: #fff; }

/* ---------------- Status bar ---------------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 18px;
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}
.legend { display: flex; align-items: center; gap: 8px; }
.palette-select {
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}
.palette-select:focus { outline: none; border-color: var(--purple-bright); }
.legend-bar {
  width: 160px;
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
}
.legend-label { font-size: 10px; }

/* ---------------- Matrix ---------------- */
.matrix {
  display: flex;
  gap: 8px;
  padding: 16px 18px 40px;
  overflow-x: auto;
  align-items: flex-start;
}
.loading { color: var(--text-dim); padding: 40px; font-style: italic; }

.tactic-col {
  flex: 0 0 auto;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tactic-header {
  background: linear-gradient(180deg, var(--purple-deep), var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: 8px 8px 4px 4px;
  padding: 9px 10px;
  position: sticky;
  top: 0;
}
.tactic-name { font-weight: 700; font-size: 13px; color: #fff; }
.tactic-count { font-size: 10px; color: var(--accent); margin-top: 2px; }

.tech {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-cell);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
}
.tech:hover { border-color: var(--purple-bright); }
.tech:active { transform: scale(.995); }
.tech.deselected { opacity: 0.28; }
.tech.search-hit { outline: 2px solid var(--accent); outline-offset: -2px; }
.tech.search-dim { opacity: 0.12; }

.tech-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
}
.tech-id {
  font-size: 10px;
  font-family: "Cascadia Code", Consolas, monospace;
  color: var(--text-dim);
  flex-shrink: 0;
}
.tech-name {
  font-size: 12px;
  line-height: 1.25;
  flex: 1;
  min-width: 0;
}
.tech .score-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0,0,0,.35);
  color: #fff;
  flex-shrink: 0;
}
.tech .note-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.tech .link-badge {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  padding: 1px 4px 1px 3px;
  border-radius: 4px;
  background: var(--purple-deep);
  color: #fff;
  flex-shrink: 0;
}
.tech.light-cell .link-badge { background: rgba(0,0,0,.45); }
.tech .link-badge svg { display: block; }
.tech .score-badge.done-badge { background: rgba(0,0,0,.35); color: #fff; }
.tech.light-cell .score-badge { background: rgba(0,0,0,.45); color: #fff; }

/* progress bars (cells, tactic headers, status, popover) */
.progress {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--purple-bright);
  transition: width .25s ease, background .25s ease;
}
.tech.complete { border-color: var(--purple-bright); }
.tactic-progress { margin-top: 6px; height: 6px; }
.tactic-pct { color: var(--accent); font-weight: 700; }
.status-prog { display: inline-block; width: 120px; height: 7px; vertical-align: middle; }
.status-progress { display: inline-flex; align-items: center; gap: 8px; }

/* sub-technique expander */
.subtech-toggle {
  width: 16px; height: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0,0,0,.25);
  color: var(--accent);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.subtech-toggle:hover { background: var(--purple-deep); color: #fff; }
.subtech-list { display: none; flex-direction: column; gap: 3px; padding: 0 0 4px 14px; }
.tech-wrap.expanded > .subtech-list { display: flex; }
.subtech { font-size: 11px; }
.subtech .tech-row { padding: 5px 7px; }
.subtech .tech-name { font-size: 11px; }

.tech-wrap { display: flex; flex-direction: column; gap: 3px; }

/* custom (user-added) techniques */
.tech.custom-tech { border-left: 3px solid var(--accent); }
.tech .custom-star {
  color: var(--accent);
  font-size: 11px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 3px var(--shadow));
}
.tech.light-cell .custom-star { color: var(--purple-deep); }

/* contrast helpers for heatmap-colored cells */
/* colored cells: brighten the dim ID so it stays legible */
.tech.colored .tech-id { color: rgba(255, 255, 255, 0.92); }
/* light heatmap cells: switch ID + name to dark text */
.tech.light-cell .tech-name,
.tech.light-cell .tech-id { color: #1a1024; }
.tech.light-cell .tech-id { opacity: .85; }

/* ---------------- Popover (technique editor) ---------------- */
.popover-backdrop, .modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(3,2,8,.6);
  backdrop-filter: blur(2px);
  z-index: 80;
}
.popover {
  position: fixed;
  z-index: 90;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--purple);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,.6), 0 0 0 1px var(--shadow);
  padding: 16px;
}
.popover h3 { margin: 0 0 2px; font-size: 15px; color: #fff; }
.popover .pop-id { font-family: Consolas, monospace; font-size: 11px; color: var(--accent); }
.popover .pop-desc {
  font-size: 12px; color: var(--text-dim); margin: 10px 0;
  max-height: 110px; overflow-y: auto; line-height: 1.45;
}
.popover .pop-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); margin: 12px 0 6px; }
.popover .pop-desc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.popover .pop-desc-edit { text-transform: none; letter-spacing: 0; font-size: 12px; }
.edited-tag {
  display: inline-block;
  margin-left: 7px;
  /* note: an explicit display would otherwise defeat the [hidden] attribute */
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--purple-deep);
  color: #fff;
  font-size: 9px;
  letter-spacing: .5px;
  vertical-align: middle;
}
.edited-tag[hidden] { display: none; }
.pop-desc-input { min-height: 130px; font-family: inherit; line-height: 1.45; }
.pop-desc-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.pop-desc-tools .hint { font-size: 11px; color: var(--text-dim); }
.pop-desc-tools .pop-link { text-transform: none; letter-spacing: 0; }
/* completion controls in the popover */
/* 3-state segmented control: Not started / Partial / Completed */
.status-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  flex-shrink: 0;
}
.status-seg button {
  border: none;
  background: var(--bg-cell);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}
.status-seg button:first-child { border-left: none; }
.status-seg button:hover { color: var(--text); }
.status-seg .seg-partial.active { background: var(--partial, #7c3aed); color: #fff; }
.status-seg .seg-done.active    { background: #43a047; color: #fff; }
.status-seg .seg-none.active    { background: var(--border); color: var(--text); }
.status-seg-lg { display: flex; width: 100%; }
.status-seg-lg button { flex: 1; padding: 9px 6px; font-size: 12px; font-weight: 600; }
.status-seg-sm button { padding: 4px 7px; font-size: 11px; }

.comp-summary { display: flex; align-items: center; gap: 10px; }
.comp-bar { flex: 1; height: 8px; }
.comp-text { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.comp-actions { display: flex; gap: 8px; margin-top: 10px; }
.subcheck-list { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; max-height: 200px; overflow-y: auto; }
.subrow { display: flex; align-items: center; gap: 9px; font-size: 12px; }
.subrow-label { min-width: 0; line-height: 1.25; }
.subcheck-id { font-family: Consolas, monospace; font-size: 10px; color: var(--text-dim); margin-right: 3px; }
.pop-note {
  width: 100%;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px;
  font-size: 12px;
  resize: vertical;
  min-height: 56px;
  font-family: inherit;
}
/* iPurple articles editor */
.popover .pop-section-label svg { vertical-align: -1px; margin-right: 3px; }
.links-empty { font-size: 12px; color: var(--text-dim); font-style: italic; padding: 2px 0 4px; }
.link-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-cell);
}
.link-row input {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 8px;
  font-size: 12px;
  font-family: inherit;
  width: 100%;
}
.link-row input:focus { outline: none; border-color: var(--purple-bright); }
.link-url-row { display: flex; align-items: center; gap: 6px; }
.link-url-row .link-url { flex: 1; }
.link-open, .link-del, .link-edit, .link-done {
  flex-shrink: 0;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.link-open:hover, .link-del:hover, .link-edit:hover, .link-done:hover { border-color: var(--purple-bright); }
.link-open.disabled { opacity: .35; pointer-events: none; }
.link-del { color: var(--danger); font-size: 17px; }
.link-done { color: var(--purple-bright); }

/* read-only popover (visitors) */
.ro-status { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.ro-dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); flex-shrink: 0; }
.ro-desc { max-height: 160px; }
.ro-links { display: flex; flex-direction: column; gap: 7px; }
.ro-links .link-anchor { padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg-cell); }
.ro-links .link-anchor:hover { border-color: var(--purple-bright); text-decoration: none; }

/* saved article shown as a clickable hyperlink */
.link-row.link-view { flex-direction: row; align-items: center; gap: 6px; padding: 7px 8px; }
.link-anchor {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
}
.link-anchor:hover { text-decoration: underline; }
.link-anchor svg { flex-shrink: 0; }
.link-anchor span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-sm { padding: 6px 11px; font-size: 12px; }

.pop-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }
.btn {
  border: 1px solid var(--border);
  background: var(--bg-cell);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { border-color: var(--purple-bright); }
.btn-primary { background: linear-gradient(135deg, var(--purple-deep), var(--purple-bright)); border-color: var(--purple-bright); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.pop-toggle-select { display:flex; align-items:center; gap:6px; font-size:12px; color: var(--text-dim); cursor:pointer; }

a.pop-link { font-size: 12px; }

/* ---------------- Modal (help) ---------------- */
.modal {
  position: fixed;
  z-index: 90;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--purple);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.65);
  padding: 24px;
}
.modal h2 { margin-top: 0; color: #fff; }
.modal h3 { color: var(--accent); margin-bottom: 6px; }
.modal code { background: var(--bg-cell); padding: 1px 5px; border-radius: 4px; font-size: 12px; color: var(--accent); }
.modal ul { line-height: 1.7; }
.modal .modal-close { position: absolute; }

/* ---------------- Form (add/edit technique) ---------------- */
.form-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }
.field input[type=text],
.field textarea,
.field select {
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
.field input[type=text]:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--purple-bright);
  box-shadow: 0 0 0 3px var(--shadow);
}
.field textarea { resize: vertical; min-height: 64px; }
.field .hint { font-size: 11px; color: var(--text-dim); }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

.type-toggle { display: flex; gap: 8px; }
.type-toggle label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-cell);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.type-toggle input { accent-color: var(--purple-bright); }
.type-toggle label.sel { border-color: var(--purple-bright); background: var(--purple-deep); color: #fff; }

.tactic-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px;
  max-height: 168px;
  overflow-y: auto;
}
.tactic-checks label { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: pointer; }
.tactic-checks input { accent-color: var(--purple-bright); }
.form-error { color: var(--danger); font-size: 12px; min-height: 16px; }

/* ---------------- Footer ---------------- */
.app-footer {
  padding: 16px 18px 28px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ---------------- Scrollbars ---------------- */
::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple-deep); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  border: 1px solid var(--purple-bright);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 9px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  .search-wrap { min-width: 200px; }
  .brand-tagline { display: none; }
}
