/* ============================================================
   Yet Another Army Builder — Dark Warhammer Theme
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --bg:           #18181b;
  --panel-bg:     #22222a;
  --panel-alt:    #28282f;
  --accent:       #ffffff;
  --accent-hover: #cccccc;
  --accent-dark:  #aaaaaa;
  --accent-rgb:   255, 255, 255;
  --accent-on:    #111111;
  --text:         #e0e0e0;
  --text-muted:   #a8a8a8;
  --border:       #3a3a44;
  --border-light: #4a4a54;
  --success:      #2ecc71;
  --warning:      #f39c12;
  --danger:       #e74c3c;
  --card-bg:      #2c2c34;
  --card-hover:   #34343c;
  --radius:       6px;
  --radius-lg:    10px;
  --shadow:       0 2px 8px rgba(0,0,0,0.5);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.7);
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  --font-mono:    'Consolas', 'Monaco', 'Courier New', monospace;
  --font-display: 'Cinzel', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-body:    var(--font);
  --scale-h1:     24px;
  --scale-h2:     18px;
  --scale-h3:     15px;
  --scale-body:   15px;
  --scale-small:  12px;
}

/* ── Reset / Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: 'tnum';
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

ul { list-style: none; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--panel-bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #666; }

/* ── Page-level loading progress strip (fixed, top of viewport) ─ */
.page-progress-wrap {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 500;
  background: rgba(var(--accent-rgb), 0.2);
}
/* Override [hidden] — CSS display: flex/block has higher specificity than
   the browser's built-in [hidden]{display:none} rule, so we must be explicit */
.page-progress-wrap[hidden],
.load-status[hidden] {
  display: none !important;
}
.page-progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.6);
}

/* ── Load status (in center panel header) ────────────────── */
.load-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
  justify-content: center;
}
.load-status-count {
  color: var(--accent);
  font-weight: 600;
}

/* ── Main Layout ─────────────────────────────────────────── */
:root {
  --col-left:  300px;
  --col-right: 420px;
}

.app-main {
  display: grid;
  grid-template-columns: var(--col-left) 4px 1fr 4px var(--col-right);
  grid-template-rows: 1fr;
  height: 100vh;
  gap: 0;
  overflow: hidden;
}

/* ── Resize Handles ──────────────────────────────────────── */
.resize-handle {
  background: var(--border);
  cursor: col-resize;
  transition: background 0.15s;
  z-index: 10;
  flex-shrink: 0;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

/* ── Panels ──────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 180px;
}

.panel-left   { background: var(--panel-bg); border-right: none; }
.panel-center { background: var(--bg); }
.panel-right  { background: var(--panel-bg); border-left: none; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

.panel-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
  flex-shrink: 0;
}

/* ── Army Selection (faction + detachment) ───────────────── */
.army-selection-section {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.army-selection-section .form-group { margin-bottom: 8px; }
.army-selection-section .form-group:last-child { margin-bottom: 0; }

/* ── Army Rules Section ──────────────────────────────────── */
.army-rules-section {
  margin-bottom: 14px;
}
.army-rules-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 4px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.army-rules-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.army-rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.army-rule-item:hover {
  border-color: var(--accent);
  background: var(--card-hover);
}
.army-rule-item .rule-arrow {
  color: var(--text-muted);
  font-size: 11px;
}

/* ── Squad Size Select (in detail panel) ─────────────────── */
.detail-squad-select {
  flex: 1;
  font-size: 13px;
}

/* ── Weapons: Ranged / Melee split ───────────────────────── */
.weapons-subsection {
  margin-bottom: 14px;
}
.weapons-subsection-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 6px;
  border-radius: 3px;
  margin-bottom: 6px;
  display: inline-block;
}
.weapons-subsection-title.ranged {
  color: #5ab5e8;
  background: rgba(90,181,232,0.1);
  border: 1px solid rgba(90,181,232,0.25);
}
.weapons-subsection-title.melee {
  color: #e8955a;
  background: rgba(232,149,90,0.1);
  border: 1px solid rgba(232,149,90,0.25);
}

/* ── Load-complete status (green check, then fade) ───────── */
.load-status.load-complete #load-spinner { display: none; }
.load-status.load-complete { color: var(--success); }

/* ── Upload Area ─────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 14px;
  background: rgba(255,255,255,0.02);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb),0.08);
}

.upload-icon { font-size: 28px; margin-bottom: 6px; }
.upload-text { font-size: 13px; color: var(--text); margin-bottom: 4px; }
.upload-subtext { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; }

/* ── Form Elements ───────────────────────────────────────── */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.form-input,
.form-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.2s;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb),0.2);
}

.form-select option { background: var(--panel-bg); }

/* ── Section Label ───────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ── Faction List ────────────────────────────────────────── */
.faction-list { display: flex; flex-direction: column; gap: 6px; }

.faction-list-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 0;
}

.faction-item {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  gap: 8px;
  transition: border-color 0.15s;
}

.faction-item:hover { border-color: var(--border-light); }

.faction-item-info { flex: 1; min-width: 0; }

.faction-item-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.faction-item-count {
  font-size: 11px;
  color: var(--text-muted);
}

.faction-item-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.faction-item-del:hover { color: var(--danger); background: rgba(231,76,60,0.15); }

/* ── Panel controls strip (search + filter) ─────────────── */
.panel-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  flex-shrink: 0;
}

.faction-select { font-size: 12px; padding: 5px 8px; }

/* ── Data footer (upload button) ────────────────────────── */
.data-footer {
  display: flex;
  align-items: center;
}
.btn-upload-file { width: 100%; justify-content: center; }

/* ── Panel header: unit count badge ─────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h2 { flex: 1; }

/* ── Left panel drag-over highlight ─────────────────────── */
.panel-left.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(var(--accent-rgb),0.05);
}

/* ── Roster Controls (legacy, keep for search-input ref) ── */
.roster-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.unit-count-badge {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Unit Grid ───────────────────────────────────────────── */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.roster-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.roster-empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.roster-empty p { margin-bottom: 6px; }
.roster-empty .muted { font-size: 12px; }

/* ── Unit Cards ──────────────────────────────────────────── */
.unit-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.unit-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}

.unit-card:hover {
  border-color: var(--accent);
  background: var(--card-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.unit-card:hover::before { opacity: 1; }
.unit-card:active { transform: translateY(0); box-shadow: none; }

.unit-card.selected {
  border-color: var(--accent);
  background: var(--card-hover);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb),0.3);
}
.unit-card.selected::before { opacity: 1; }

.unit-card-faction {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 6px;
  min-width: 0;
}

.unit-card-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}

.unit-card-pts {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex: 0 0 auto;
}

.unit-card-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 8px;
}

.keyword-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(var(--accent-rgb),0.15);
  border: 1px solid rgba(var(--accent-rgb),0.3);
  color: var(--accent);
  border-radius: 3px;
  padding: 1px 5px;
}

.unit-card-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  text-align: center;
}

.stat-cell {
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
  padding: 3px 2px;
}

.stat-name {
  font-size: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  display: block;
}

.stat-value {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  display: block;
}

/* ── Army List ───────────────────────────────────────────── */
.army-meta {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  margin-bottom: 12px;
}

.points-summary {
  background: rgba(var(--accent-rgb),0.1);
  border: 1px solid rgba(var(--accent-rgb),0.3);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.points-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 8px;
}

.points-current {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.points-separator { font-size: 20px; color: var(--text-muted); }

.points-limit { font-size: 20px; font-weight: 600; color: var(--text); }

.points-label { font-size: 13px; color: var(--text-muted); margin-left: 4px; }

.points-bar-wrap {
  height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.points-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease, background 0.3s;
}

.points-bar.over-limit { background: var(--danger); }
.points-bar.near-limit { background: var(--warning); }

.points-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Army Entries ────────────────────────────────────────── */
.army-entries-header {
  display: grid;
  grid-template-columns: 1fr 44px 50px 44px 28px;
  gap: 4px;
  padding: 4px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.army-entry-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.army-list-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
  padding: 20px 8px;
  text-align: center;
}

.army-entry {
  display: grid;
  grid-template-columns: 1fr 44px 50px 44px 28px;
  align-items: center;
  gap: 4px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 12px;
  transition: border-color 0.15s;
}

.army-entry:hover { border-color: var(--border-light); }

.army-entry-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.army-entry-pts {
  text-align: right;
  color: var(--text-muted);
  font-size: 11px;
}

.army-entry-qty input {
  width: 42px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
  outline: none;
}

.army-entry-qty input:focus { border-color: var(--accent); }

.army-entry-total {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
}

.army-entry-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
  text-align: center;
}

.army-entry-remove:hover {
  color: var(--danger);
  background: rgba(231,76,60,0.15);
}

.army-entry-squad {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

.detail-pts-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  padding: 0 4px;
  align-self: center;
}

/* ── Army Toolbar ────────────────────────────────────────── */
.army-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  border: 1px solid transparent;
  white-space: nowrap;
  outline: none;
}

.btn:active { transform: scale(0.97); }

.btn-accent {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-light);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  flex: 1;
  min-width: 0;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover { background: #c0392b; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 360px;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modal-in 0.15s ease;
}

.modal-unit-detail { max-width: 640px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  border-radius: 3px;
  transition: color 0.15s;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ── Saved Army List ─────────────────────────────────────── */
.saved-army-list { display: flex; flex-direction: column; gap: 8px; }

.saved-army-empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

.saved-army-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.saved-army-info { flex: 1; min-width: 0; }

.saved-army-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-army-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.saved-army-actions { display: flex; gap: 6px; }

/* ── Unit Detail Panel (right panel) ────────────────────── */
.unit-detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
  gap: 8px;
}
.unit-detail-empty-icon { font-size: 48px; opacity: 0.3; margin-bottom: 8px; }
.unit-detail-empty p { font-size: 14px; }
.unit-detail-empty .muted { font-size: 12px; max-width: 220px; }

.unit-detail-content { display: flex; flex-direction: column; gap: 0; }

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.detail-header-main { flex: 1; min-width: 0; }
.btn-google-search {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s, border-color 0.15s;
  margin-top: 2px;
}
.btn-google-search:hover { opacity: 1; border-color: var(--border-light); }
.detail-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 6px;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}
.detail-faction {
  background: rgba(var(--accent-rgb),0.12);
  border: 1px solid rgba(var(--accent-rgb),0.25);
  color: var(--accent);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-type {
  color: var(--text-muted);
  font-style: italic;
}
.detail-pts {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-left: auto;
}

.detail-add-section {
  background: rgba(var(--accent-rgb),0.07);
  border: 1px solid rgba(var(--accent-rgb),0.2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
}
.detail-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.detail-qty-input { width: 70px; flex-shrink: 0; }
.detail-add-btn { flex: 1; }

.detail-section {
  margin-bottom: 16px;
}
.detail-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.detail-stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  text-align: center;
}
.detail-stat-cell {
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  padding: 8px 4px;
}
.detail-stat-cell .stat-name  { font-size: 10px; }
.detail-stat-cell .stat-value { font-size: 16px; }

.detail-table-wrap { overflow-x: auto; }

.detail-ability {
  font-size: 12px;
  margin-bottom: 6px;
  line-height: 1.5;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
}
.detail-ability-name { font-weight: 700; margin-right: 4px; }
.detail-ability-desc { color: var(--text-muted); }

/* Core abilities — system-wide rules displayed as name plaques */
.core-abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.core-ability-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 3px 8px;
  border-radius: 3px;
  color: #a8d8a8;
  background: rgba(168,216,168,0.08);
  border: 1px solid rgba(168,216,168,0.25);
  display: inline-block;
}

/* Weapon keyword tags in weapons table */
.weapon-keywords-cell { white-space: normal; }
.weapon-kw-tag {
  display: inline-block;
  font-size: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  margin: 1px 2px;
  white-space: nowrap;
}
.weapon-kw-tag.has-tooltip {
  cursor: help;
  border-color: rgba(90,181,232,0.4);
}

/* Global tooltip (JS-positioned, position: fixed — never clipped) */
.global-tooltip {
  position: fixed;
  z-index: 9999;
  background: #1e1e1e;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  max-width: 300px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  white-space: normal;
}

/* Wargear options bullet list */
.wargear-option-list {
  list-style: disc;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.6;
}
.wargear-option-item {
  margin-bottom: 6px;
  color: var(--text);
}
.wargear-choice-list {
  list-style: circle;
  padding-left: 20px;
  margin-top: 3px;
  color: var(--text-muted);
}
.wargear-model-ctx {
  list-style: none;
  margin-bottom: 8px;
}
.wargear-model-name {
  font-weight: 600;
  color: var(--accent);
}
.wargear-suboption-list {
  list-style: none;
  padding-left: 14px;
  margin-top: 4px;
}
.wargear-suboption-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 4px;
  margin-bottom: 2px;
}
.wargear-choice-item {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}
.wargear-choice-item::before {
  content: '• ';
  color: var(--accent);
  opacity: 0.6;
}

/* Redesigned Loadout section */
.wl-composition {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
  padding: 4px 8px;
  background: var(--surface2, rgba(255,255,255,0.04));
  border-radius: 4px;
  display: inline-block;
}
.wl-model-block {
  margin-bottom: 12px;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  background: var(--surface2, rgba(255,255,255,0.03));
  border-radius: 0 4px 4px 0;
}
.wl-model-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.wl-model-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.wl-model-count {
  font-size: 11px;
  color: var(--text-muted);
}
.wl-defaults {
  font-size: 12px;
  margin-bottom: 6px;
  line-height: 1.5;
}
.wl-defaults-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-right: 4px;
}
.wl-defaults-weapons {
  color: var(--text);
}
.wl-suboption {
  margin-top: 6px;
}
.wl-suboption-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.wl-choice-list {
  list-style: none;
  padding-left: 10px;
  margin: 2px 0 0 0;
}
.wl-choice-list li {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}
.wl-choice-list li::before {
  content: '• ';
  color: var(--accent);
  opacity: 0.6;
}
.wl-choice-group {
  margin-bottom: 10px;
}
.wl-choice-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}
.wl-max {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}


/* ── Unit Detail Modal (legacy — keep weapons-table styles) ─ */
.unit-detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.unit-stats-table {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}

.unit-stats-table .stat-cell {
  text-align: center;
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  padding: 8px 4px;
}

.unit-stats-table .stat-name { font-size: 10px; }
.unit-stats-table .stat-value { font-size: 16px; }

.weapons-section { margin-top: 14px; }

.weapons-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.weapons-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.weapons-table th {
  text-align: left;
  padding: 4px 6px;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.weapons-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(58,58,58,0.5);
}

.weapons-table tr:last-child td { border-bottom: none; }

.weapons-table tr:hover td { background: rgba(255,255,255,0.03); }

.weapon-type-ranged { color: #5ab5e8; }
.weapon-type-melee  { color: #e8955a; }

/* ── Toast ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  max-width: 300px;
  pointer-events: none;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

.toast.fade-out { animation: toast-out 0.3s ease forwards; }

/* ── Utility ─────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1200px) {
  :root { --col-left: 260px; --col-right: 360px; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; }
  .app-main {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 4px auto 4px auto;
    height: auto;
    overflow: visible;
  }
  .resize-handle { height: 4px; width: 100%; cursor: row-resize; }
  .panel { min-width: 0; height: auto; min-height: 300px; border-right: none; border-bottom: 1px solid var(--border); }
  .panel-body { max-height: 500px; overflow-y: auto; }
}

/* ── Loading Spinner ─────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Points Over Limit ───────────────────────────────────── */
.points-over .points-current { color: var(--danger); }

/* BSData browse modal styles removed — data now auto-loads */

/* ── Army Rules: two sub-sections ───────────────────────── */
.army-rules-subsection { margin-bottom: 10px; }
.army-rules-subsection:last-child { margin-bottom: 0; }

.stratagem-cp-badge {
  font-size: 10px;
  font-weight: 700;
  color: #f5c842;
  background: rgba(245,200,66,0.12);
  border: 1px solid rgba(245,200,66,0.3);
  border-radius: 3px;
  padding: 1px 5px;
  margin-right: 4px;
}

.rule-item-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.stratagem-item { border-left: 2px solid rgba(245,200,66,0.4); }

.enhancement-pts-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(128,128,128,0.12);
  border: 1px solid rgba(128,128,128,0.25);
  border-radius: 3px;
  padding: 1px 5px;
  margin-right: 4px;
}

.enhancement-item { border-left: 2px solid rgba(var(--accent-rgb, 255,255,255), 0.35); }

/* ── Enhancement checkboxes in unit detail panel ──────────── */
.detail-enhancements-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.enhancement-cb-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  padding: 7px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  transition: background 0.15s;
}

.enhancement-cb-item:hover { background: var(--hover-bg); }

.enhancement-cb-item input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.enh-cb-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.enh-cb-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.enh-cb-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.enh-cb-pts {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(128,128,128,0.12);
  border: 1px solid rgba(128,128,128,0.25);
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
}

.enh-cb-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
  white-space: pre-wrap;
}

/* Army entry enhancement badges */
.army-enh-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 2px;
}

.army-enh-badge {
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(var(--accent-rgb, 128,128,128), 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(var(--accent-rgb, 128,128,128), 0.2);
  cursor: default;
}

.army-enh-pts {
  font-size: 9px;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ── Stratagem detail view ───────────────────────────────── */
.strat-detail-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  font-size: 13px;
}
.strat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.strat-value { color: var(--text); line-height: 1.5; }
.strat-cp { color: #f5c842; font-size: 14px; font-weight: 700; }
.stratagem-cp-hero {
  color: #f5c842;
  font-size: 16px;
  font-weight: 700;
  margin-left: auto;
}

/* ── Leader section ──────────────────────────────────────── */
.detail-section-title-leader {
  color: #5ab5e8;
  border-bottom-color: rgba(90,181,232,0.3);
}
.detail-section-title-ledbby {
  color: #a8e88a;
  border-bottom-color: rgba(168,232,138,0.3);
}

.detail-leader-units { margin-bottom: 8px; }
.detail-leader-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.leader-unit-tag {
  font-size: 11px;
  background: rgba(90,181,232,0.1);
  border: 1px solid rgba(90,181,232,0.3);
  color: #5ab5e8;
  border-radius: 3px;
  padding: 2px 7px;
}

.detail-ledby-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ledby-tag {
  font-size: 11px;
  background: rgba(168,232,138,0.08);
  border: 1px solid rgba(168,232,138,0.25);
  color: #a8e88a;
  border-radius: 3px;
  padding: 2px 7px;
}

/* ── Wargear options (bullet list) ─────────────────────────── */

/* === Phase-2 UX additions === */

/* Filter chips row (rendered inside #panel-center .panel-controls, after search) */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}
.filter-chip {
  font-size: 11px;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.04);
  color: var(--text-muted, #bbb);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.filter-chip:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text, #eee);
}
.filter-chip.active {
  background: rgba(168,232,138,0.18);
  border-color: rgba(168,232,138,0.55);
  color: #d4f5bb;
}
.filter-chips-clear {
  font-size: 14px;
  line-height: 1;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 2px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted, #aaa);
  cursor: pointer;
  opacity: 0.7;
}
.filter-chips-clear:hover {
  opacity: 1;
  background: rgba(255,255,255,0.08);
  color: var(--text, #eee);
}

/* Unit card: hide the faction line when a specific faction/chapter is selected. */
.unit-card.faction-hidden .unit-card-faction { display: none; }

/* Led-By collapse: hide leaders past the 3rd when collapsed. */
.detail-ledby-list.collapsed > *:nth-child(n+4) { display: none; }
.detail-ledby-list.collapsed > .ledby-more-pill { display: inline-flex; }
.detail-ledby-title { cursor: pointer; user-select: none; }
.ledby-more-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px dashed rgba(168,232,138,0.35);
  background: rgba(168,232,138,0.04);
  color: #a8e88a;
  cursor: pointer;
}
.ledby-more-pill:hover {
  background: rgba(168,232,138,0.12);
  border-style: solid;
}

/* Enhancement ineligibility (unit lacks Character keyword). */
.enhancement-cb-item.enhancement-ineligible {
  opacity: 0.55;
  cursor: not-allowed;
}
.enhancement-cb-item.enhancement-ineligible .enhancement-cb {
  pointer-events: none;
}
.enh-cb-ineligible-note {
  display: inline-block;
  margin-top: 3px;
  font-size: 10px;
  font-style: italic;
  color: #e2a04a;
}

/* Weapon keyword tag color coding. Background tints with readable text. */
.weapon-kw-tag.weapon-kw-red {
  background: rgba(220, 74, 74, 0.18);
  border-color: rgba(220, 74, 74, 0.45);
  color: #f2b2b2;
}
.weapon-kw-tag.weapon-kw-orange {
  background: rgba(230, 150, 50, 0.18);
  border-color: rgba(230, 150, 50, 0.45);
  color: #f3cc93;
}
.weapon-kw-tag.weapon-kw-blue {
  background: rgba(80, 150, 230, 0.18);
  border-color: rgba(80, 150, 230, 0.45);
  color: #b8d6f5;
}
.weapon-kw-tag.weapon-kw-purple {
  background: rgba(170, 110, 220, 0.18);
  border-color: rgba(170, 110, 220, 0.45);
  color: #dcc1f2;
}

/* === Toolbar redesign (two rows + Export dropdown) === */
.army-toolbar {
  flex-direction: column;
  gap: 6px;
}
.army-toolbar .toolbar-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
/* Undo our generic .btn-sm { flex:1 } inside the toolbar — we want buttons
   to size to content so the layout doesn't stretch awkwardly. */
.army-toolbar .btn-sm {
  flex: 0 1 auto;
}
.army-toolbar .toolbar-spacer {
  flex: 1 1 auto;
  min-width: 0;
}
.army-toolbar .toolbar-icons {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.army-toolbar .toolbar-extras {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.army-toolbar .toolbar-extras:empty,
.army-toolbar .toolbar-icons:empty {
  display: none;
}

/* Compact icon button: square-ish, larger glyph, no wide horizontal padding. */
.btn.btn-icon {
  padding: 4px 8px;
  min-width: 30px;
  font-size: 15px;
  line-height: 1;
  font-weight: 500;
}

/* Dropdown menu — used by Export group in army toolbar. */
.dropdown {
  position: relative;
  display: inline-block;
  flex: 0 1 auto;
}
.dropdown-trigger .caret {
  font-size: 10px;
  margin-left: 3px;
  opacity: 0.7;
}
.dropdown-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: var(--surface, #1a1a1a);
  border: 1px solid var(--border-light, rgba(255,255,255,0.12));
  border-radius: var(--radius, 4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 4px;
  z-index: 100;
}
.dropdown.open > .dropdown-menu {
  display: block;
}
.dropdown-menu > button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text, #e8e8e8);
  font: inherit;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: calc(var(--radius, 4px) - 1px);
  cursor: pointer;
  white-space: nowrap;
}
.dropdown-menu > button:hover,
.dropdown-menu > button:focus {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}
.dropdown-menu .export-extras:empty {
  display: none;
}
.dropdown-menu .export-extras > button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text, #e8e8e8);
  font: inherit;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: calc(var(--radius, 4px) - 1px);
  cursor: pointer;
  white-space: nowrap;
}
.dropdown-menu .export-extras > button:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* === Toolbar overflow guards (narrow panel widths) === */
.panel-footer {
  min-width: 0;
  /* NO overflow:hidden — the Export dropdown menu is absolutely
     positioned above the trigger (`bottom: calc(100% + 6px)`) and any
     hidden overflow on an ancestor clips the upper menu items. Button
     text is already clamped by max-width + ellipsis below, which is
     what actually prevents toolbar overflow. */
}
.army-toolbar,
.army-toolbar .toolbar-row {
  min-width: 0;
}
/* Ellipsize overly long labels instead of pushing off the panel. */
.army-toolbar .btn-sm {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Don't let the dropdown menu demand more than the panel width. */
.dropdown-menu {
  max-width: calc(var(--col-left, 300px) - 20px);
  min-width: min(180px, calc(var(--col-left, 300px) - 20px));
}
