/* ==========================================================================
   Encounter Layout A — Three-column combat encounter shell
   Left: PC reference cards | Center: Initiative tracker | Right: NPC cards
   ========================================================================== */

/* ---------- Grid shell ---------- */

.enc-layout-a {
  display: grid;
  grid-template-columns: 1fr 285px 1fr;
  gap: 0.75rem;
  height: calc(100vh - 200px);
  min-height: 400px;
}

/* ---------- Side columns ---------- */

.enc-col-pcs,
.enc-col-npcs {
  overflow-y: auto;
  padding: 0.5rem;
}

/* ---------- Center column ---------- */

.enc-col-initiative {
  overflow-y: auto;
  border-left: 1px solid var(--border-primary);
  border-right: 1px solid var(--border-primary);
  padding: 0.5rem;
}

/* ---------- Column headers ---------- */

.enc-col-header {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0 0 0.5rem 0;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-primary);
}

/* ==========================================================================
   Initiative list — compact display in center column
   ========================================================================== */

.enc-initiative-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 0.75rem;
}

.enc-init-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.enc-init-row.enc-init-current {
  background: rgba(230, 57, 70, 0.15);
  border-color: var(--accent-red);
}

.enc-init-row.enc-init-npc {
  color: var(--error);
}

.enc-init-row.enc-init-pc {
  color: var(--success);
}

.enc-init-number {
  font-weight: 700;
  min-width: 2rem;
  text-align: center;
}

.enc-init-name {
  flex: 1;
}

.enc-init-hp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Mausritter DEX save — pass/fail coloring in initiative list */
.enc-init-row.enc-init-pass {
  border-left: 3px solid var(--success);
}

.enc-init-row.enc-init-fail {
  border-left: 3px solid var(--error);
}

.enc-init-row.enc-init-pass .enc-init-number {
  color: var(--success);
  font-size: 0.7rem;
  min-width: 5rem;
}

.enc-init-row.enc-init-fail .enc-init-number {
  color: var(--error);
  font-size: 0.7rem;
  min-width: 5rem;
}

/* ==========================================================================
   NPC stat block card — right column
   ========================================================================== */

.npc-card {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-primary);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.2s;
}

.npc-card.npc-current-turn {
  border-color: var(--accent-red);
  box-shadow: 0 0 8px rgba(230, 57, 70, 0.3);
}

.npc-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.npc-card-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.npc-card-type {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-muted);
}

/* HP tracker — consolidated in encounters.css */

/* ---------- Stat badges row ---------- */

.npc-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.npc-stat-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
}

.npc-stat-label {
  color: var(--text-muted);
  margin-right: 4px;
}

.npc-stat-value {
  font-weight: 600;
}

/* ---------- Expandable section ---------- */

.npc-expand-toggle {
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.npc-expand-toggle:hover {
  color: var(--text-primary);
}

.npc-expanded-content {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.npc-expanded-content p {
  margin: 0.25rem 0 0 0;
}

/* ==========================================================================
   Quick-Add Monsters panel
   ========================================================================== */

.quick-add-monsters {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.quick-add-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.quick-add-search {
  flex: 1;
  min-width: 120px;
  padding: 0.3rem 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.8rem;
}

.quick-add-count-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.quick-add-count-row input[type="number"] {
  width: 50px;
  padding: 0.25rem 0.4rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.8rem;
}

.quick-add-monster-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.quick-add-monster-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
}

.quick-add-monster-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

.quick-add-monster-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.quick-add-stat {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ==========================================================================
   PC d20 roller
   ========================================================================== */

.pc-d20-roller {
  margin-top: 0.4rem;
}

.pc-d20-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pc-d20-controls input[type="number"] {
  width: 54px;
  padding: 0.2rem 0.35rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.75rem;
}

.pc-d20-result {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.pc-d20-value {
  font-weight: 700;
  font-size: 0.9rem;
}

.pc-d20-pass {
  color: var(--success);
  font-weight: 600;
  font-size: 0.8rem;
}

.pc-d20-fail {
  color: var(--error);
  font-weight: 600;
  font-size: 0.8rem;
}

.pc-ref-info {
  flex: 1;
}

.pc-ref-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

/* ==========================================================================
   Mobile: stack to single column, initiative first
   ========================================================================== */

@media (max-width: 768px) {
  .enc-layout-a {
    grid-template-columns: 1fr;
    height: auto;
  }

  .enc-col-initiative {
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border-primary);
    border-bottom: 1px solid var(--border-primary);
    order: -1;
  }
}

/* Turn navigation arrow buttons — full width */
.enc-turn-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}
.enc-turn-btn {
  min-width: 2.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 1rem;
  flex-shrink: 0;
}
.enc-current-turn-label {
  flex: 1;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Extra control buttons — full width row */
.enc-runner-extra-controls {
  display: flex;
  gap: 0.35rem;
  width: 100%;
}
.enc-runner-extra-controls .button {
  flex: 1;
}

/* Runner controls container */
.enc-runner-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

/* NPC card remove button — consolidated in encounters.css */

/* ==========================================================================
   Manual Dice Toggle + Input
   ========================================================================== */

/* Toggle button in encounter runner controls */
.enc-manual-dice-toggle {
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  border: 1px solid var(--border-primary);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.enc-manual-dice-toggle.enc-manual-inactive {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.enc-manual-dice-toggle.enc-manual-active {
  background: rgba(251, 191, 36, 0.15);
  border-color: var(--warning);
  color: var(--warning);
}

.enc-manual-dice-toggle:hover {
  border-color: var(--warning);
}

/* Small toggle variant for session view section headers */
.enc-manual-toggle-sm {
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.2;
}

/* Manual dice input field — reused across attack, save, and session views */
.manual-dice-input {
  width: 52px;
  padding: 0.25rem 0.35rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.8rem;
  text-align: center;
}

.manual-dice-input:focus {
  border-color: var(--warning);
  outline: none;
}

/* Manual dice row for attack resolution */
.manual-dice-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.manual-dice-mode-btns {
  display: flex;
  gap: 0.25rem;
}

.manual-dice-mode-btns .button {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
}

.manual-dice-input-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Manual save row (inline input + button in attr pool) */
.manual-save-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Inline manual save in session view save rows */
.manual-save-inline {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

.manual-save-inline .manual-dice-input {
  width: 44px;
  font-size: 0.75rem;
  padding: 0.2rem 0.3rem;
}

.manual-save-inline .button {
  font-size: 0.7rem;
  padding: 0.2rem 0.4rem;
}

/* Session view saves header with toggle */
.cs-saves-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cs-saves-header .cs-section-title {
  margin-bottom: 0;
}

/* Manual mode save row — disable the click cursor */
.cs-save-row.cs-save-manual {
  cursor: default;
}

/* ==========================================================================
   Layout D — Timeline with Expandable Cards
   All combatants in initiative order. Current combatant auto-expands.
   Controls bar pinned at top.
   ========================================================================== */

.enc-layout-d {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 400px;
}

.enc-layout-d-controls {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-primary);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.enc-timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
}

/* Collapsed card — one-line summary */
.enc-timeline-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border-primary);
  border-left: 4px solid var(--border-primary);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.enc-timeline-card:hover {
  background: var(--bg-hover);
}

/* Color-coded left borders by combatant type */
.enc-timeline-card-pc { border-left-color: var(--success); }
.enc-timeline-card-enemy { border-left-color: var(--error); }
.enc-timeline-card-ally { border-left-color: var(--info); }

/* Current combatant highlight */
.enc-timeline-card-current {
  border-color: var(--accent-red);
  border-left-color: var(--accent-red);
  background: rgba(230, 57, 70, 0.08);
  box-shadow: 0 0 8px rgba(230, 57, 70, 0.2);
}

/* Collapsed card inner elements */
.enc-timeline-card-init {
  font-weight: 700;
  min-width: 2rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.enc-timeline-card-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.enc-timeline-card-badges {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.enc-timeline-card-hp {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* HP bar (relative health indicator) */
.enc-hp-bar {
  width: 60px;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.enc-hp-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s, background-color 0.3s;
}

.enc-hp-bar-fill.hp-full { background: var(--success); }
.enc-hp-bar-fill.hp-wounded { background: #fbbf24; }
.enc-hp-bar-fill.hp-hurt { background: var(--error); }
.enc-hp-bar-fill.hp-critical { background: #dc2626; }

/* Expanded card wrapper */
.enc-timeline-card-expanded {
  border-radius: 6px;
  border: 1.5px solid var(--border-primary);
  border-left: 4px solid var(--border-primary);
  background: var(--bg-secondary);
  padding: 0.5rem;
  transition: border-color 0.15s;
}

.enc-timeline-card-expanded.enc-timeline-card-pc { border-left-color: var(--success); }
.enc-timeline-card-expanded.enc-timeline-card-enemy { border-left-color: var(--error); }
.enc-timeline-card-expanded.enc-timeline-card-ally { border-left-color: var(--info); }
.enc-timeline-card-expanded.enc-timeline-card-current {
  border-color: var(--accent-red);
  border-left-color: var(--accent-red);
  background: rgba(230, 57, 70, 0.05);
  box-shadow: 0 0 8px rgba(230, 57, 70, 0.2);
}

.enc-expanded-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.25rem;
  cursor: pointer;
}

.enc-expanded-header-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.enc-expanded-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.5rem;
}

/* Target card (indented below attacker) */
.enc-timeline-target {
  margin-left: 1.5rem;
  border-left: 3px solid var(--warning);
  opacity: 0.9;
}

.enc-timeline-target-label {
  font-size: 0.7rem;
  color: var(--warning);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
}

/* Combat log at bottom of timeline */
.enc-timeline-log {
  border-top: 1px solid var(--border-primary);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Player View P1 — "Your Turn" Focus
   Character status top, action panel center, initiative footer
   ========================================================================== */

.enc-player-p1 {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 400px;
  gap: 0;
}

/* Header: encounter name + round */
.enc-player-p1-header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.enc-player-p1-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.enc-player-p1-round {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Character status card */
.enc-player-p1-status {
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.enc-player-p1-name {
  font-weight: 700;
  font-size: 1rem;
}

.enc-player-p1-stats {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.enc-player-p1-stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.enc-player-p1-stat-value {
  font-weight: 700;
  color: var(--text-primary);
}

/* Main content area — either "your turn" or "waiting" */
.enc-player-p1-main {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* "It's your turn" banner */
.enc-player-p1-your-turn {
  text-align: center;
  padding: 0.75rem;
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid var(--success);
  border-radius: 6px;
  color: var(--success);
  font-weight: 700;
  font-size: 1rem;
}

/* "Waiting" state */
.enc-player-p1-waiting {
  text-align: center;
  padding: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.enc-player-p1-turns-away {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1.1rem;
}

/* Turn progress bar */
.enc-player-p1-progress {
  width: 100%;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.enc-player-p1-progress-fill {
  height: 100%;
  background: var(--accent-red);
  border-radius: 3px;
  transition: width 0.5s;
}

/* Target selection list */
.enc-player-p1-targets {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.enc-player-p1-targets h4 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.enc-player-p1-target {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.enc-player-p1-target:hover {
  background: var(--bg-hover);
}

.enc-player-p1-target.selected {
  border-color: var(--accent-red);
  background: rgba(230, 57, 70, 0.08);
}

.enc-player-p1-target-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.enc-player-p1-target-hp {
  width: 80px;
}

/* Action buttons row */
.enc-player-p1-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.enc-player-p1-actions .button {
  flex: 1;
  min-width: 80px;
}

/* Combat feed */
.enc-player-p1-feed {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.enc-player-p1-feed-entry {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Initiative footer */
.enc-player-p1-initiative {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-primary);
  font-size: 0.8rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  overflow-x: auto;
  flex-shrink: 0;
}

.enc-player-p1-init-item {
  white-space: nowrap;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.enc-player-p1-init-item.is-current {
  background: rgba(230, 57, 70, 0.15);
  color: var(--accent-red);
  font-weight: 700;
}

.enc-player-p1-init-item.is-you {
  color: var(--success);
  font-weight: 600;
}

.enc-player-p1-init-separator {
  color: var(--text-muted);
}

@media (max-width: 480px) {
  .enc-player-p1-status {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .enc-player-p1-actions .button {
    font-size: 0.85rem;
  }
}
