/* ==========================================================================
   MINIMALIST SETTER CALL MAP — CLEAN DECISION SYSTEM (MOBILE-FIRST TUNED)
   ========================================================================== */

:root {
  --bg-main: #0b0f17;
  --bg-card: #141c2b;
  --bg-card-hover: #1c263a;
  --bg-sidebar: #0f1624;
  --border: #26334d;
  --border-active: #38bdf8;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #38bdf8;
  --accent-green: #34d399;
  --accent-amber: #fbbf24;
  --accent-red: #f87171;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.header {
  min-height: 56px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
}

.header-title h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-title .subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: block;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.role-selector {
  display: none; /* hidden as requested */
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.role-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.role-btn:hover {
  color: var(--text-primary);
}

.role-btn.active {
  background: #0284c7;
  color: #ffffff;
}

.view-toggles {
  display: flex;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.toggle-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* Main Area */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  height: calc(100% - 56px);
}

.view-panel {
  display: none;
  flex: 1;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.view-panel.active {
  display: flex;
}

/* ==========================================================================
   VIEW 1: CLEAN DECISION FLOWCHART (FULLY CONNECTED LINES)
   ========================================================================== */
.chart-layout {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

.tree-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 32px 100px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0; /* ZERO GAP ensures connector touches both nodes perfectly */
}

/* Flowchart Nodes */
.flow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 680px;
  position: relative;
}

/* Solid connected vertical spine with directional arrow */
.flow-connector {
  width: 2px;
  height: 36px;
  background-color: var(--border-active);
  margin: 0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-shrink: 0;
}

.flow-connector::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--border-active);
}

.decision-box {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.decision-box:hover {
  background: var(--bg-card-hover);
  border-color: #3b4e72;
}

.decision-box.selected {
  border-color: var(--accent-blue);
  background: #182338;
  box-shadow: 0 0 0 1px var(--accent-blue), 0 4px 16px rgba(56, 189, 248, 0.2);
}

.decision-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.decision-stage {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent-blue);
}

.decision-name {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Decision Branch Trunk & Chips */
.decision-branches {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  position: relative;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
}

.branch-chip {
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 5px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  width: fit-content;
  position: relative;
}

.branch-chip::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  width: 12px;
  height: 1px;
  background: var(--border);
}

.branch-chip:hover, .branch-chip:active {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.branch-chip.advance { border-left: 3px solid var(--accent-green); }
.branch-chip.objection { border-left: 3px solid var(--accent-amber); }
.branch-chip.exit { border-left: 3px solid var(--accent-red); }

/* Right Inspector Panel (Desktop default) */
.inspector-panel {
  width: 420px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  z-index: 50;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.inspector-header .node-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent-blue);
  display: inline-block;
  margin-bottom: 4px;
}

.inspector-header h3 {
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--text-primary);
}

.inspector-close-btn {
  display: none;
}

.inspector-section label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.script-text {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  font-size: 0.94rem;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-line;
}

.rule-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.branch-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.branch-action-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.branch-action-btn:hover, .branch-action-btn:active {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}

.inspector-backdrop {
  display: none;
}

/* ==========================================================================
   VIEW 2: CLEAN STEP-BY-STEP (FULL SMOOTH SCROLL SUPPORT)
   ========================================================================== */
.step-card-container {
  flex: 1;
  display: block;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 120px 16px; /* Generous bottom padding so phone address bar never covers content */
  width: 100%;
  height: 100%;
}

.step-card {
  width: 100%;
  max-width: 650px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.step-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.step-counter {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent-blue);
}

.tone-tag {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.step-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.step-script-box {
  background: var(--bg-main);
  border-left: 3px solid var(--accent-blue);
  border-radius: 0 6px 6px 0;
  padding: 16px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-line;
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.step-rule-box {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.decisions-container label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.decision-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.decision-btn {
  padding: 12px 14px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.15s ease;
  touch-action: manipulation;
  min-height: 44px;
}

.decision-btn:hover, .decision-btn:active {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}

.decision-btn.advance { border-left: 3px solid var(--accent-green); }
.decision-btn.objection { border-left: 3px solid var(--accent-amber); }
.decision-btn.exit { border-left: 3px solid var(--accent-red); }

.step-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 38px;
}

.btn-secondary:hover:not(:disabled), .btn-secondary:active:not(:disabled) {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   VIEW 3: CLEAN SCRIPT CHEATSHEET
   ========================================================================== */
.cheatsheet-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 18% 100px 18%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.cheat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cheat-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.cheat-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.cheat-tone {
  font-size: 0.76rem;
  color: var(--accent-blue);
  font-weight: 500;
}

.cheat-script {
  background: var(--bg-main);
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 0.92rem;
  line-height: 1.55;
  border-left: 3px solid var(--border-active);
  white-space: pre-line;
}

.cheat-rule {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE OVERRIDES
   ========================================================================== */
@media (max-width: 820px) {
  .header {
    flex-wrap: wrap;
    padding: 10px 14px;
    min-height: auto;
  }

  .header-title h1 {
    font-size: 0.98rem;
  }

  .header-title .subtitle {
    font-size: 0.7rem;
  }

  .view-toggles {
    width: 100%;
    justify-content: space-between;
    margin-top: 4px;
  }

  .toggle-btn {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 0.78rem;
  }

  /* Tree Container */
  .tree-container {
    padding: 16px 12px 120px 12px;
  }

  .decision-box {
    padding: 12px 14px;
  }

  .decision-name {
    font-size: 0.92rem;
  }

  .branch-chip {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  /* Inspector as Mobile Slide-Up Bottom Sheet */
  .inspector-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 82vh;
    max-height: 82dvh;
    background: #111827;
    border-top: 1px solid var(--border);
    border-left: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.75);
    transform: translateY(105%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .inspector-panel.open {
    transform: translateY(0);
  }

  .inspector-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
  }

  .inspector-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .inspector-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  /* Step-by-Step Mobile */
  .step-card-container {
    padding: 12px 10px 140px 10px; /* High clearance for mobile address bars */
  }

  .step-card {
    padding: 18px 14px;
    gap: 14px;
  }

  .step-title {
    font-size: 1.15rem;
  }

  .step-script-box {
    font-size: 0.94rem;
    padding: 14px 12px;
    max-height: 220px;
  }

  .decision-btn {
    padding: 10px 12px;
    font-size: 0.86rem;
  }

  /* Cheatsheet Mobile */
  .cheatsheet-container {
    padding: 16px 12px 120px 12px;
    gap: 14px;
  }

  .cheat-card {
    padding: 14px;
  }
}
