/* ─────────────────────────────────────────────────────────────
   ADVISORY BOARD — style.css
   
   Advisor colors are NOT hardcoded here.
   Each advisor element receives --advisor-color as an inline
   CSS custom property set by ui.js at render time.
   Generic rules read var(--advisor-color) for borders, dots,
   avatars etc. Adding a new advisor requires zero CSS changes.
───────────────────────────────────────────────────────────── */

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

:root {
  --bg:          #0c0b14;
  --surface:     #161524;
  --surface2:    #1e1c30;
  --surface3:    #252340;
  --border:      #2a2844;
  --border2:     #363460;
  --accent:      #c8a97e;
  --accent-dim:  rgba(200,169,126,0.12);
  --accent2:     #7c72b0;
  --text:        #e6e3f0;
  --text-muted:  #7a7898;
  --text-dim:    #4a4868;
  --danger:      #e07878;
  --success:     #6ec9a0;
  --sidebar-w:   300px;
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

/* ── APP SHELL ───────────────────────────────────────────────
   position:fixed + explicit inset locks to exact visible area
   in any context: browser window, iframe, mobile chrome.
   Children share space via flexbox — no height units needed.
──────────────────────────────────────────────────────────── */
html, body { height: 100%; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* ── SIDEBAR (desktop only) ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* ── MAIN — fills remaining width, stacks header/feed/input ── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── DESKTOP OVERRIDES (≥ 700px) ── */
@media (min-width: 700px) {
  .mobile-header,
  .mobile-drawer-overlay,
  .mobile-drawer { display: none; }
}

/* ── MOBILE OVERRIDES (< 700px) ── */
@media (max-width: 699px) {
  body { flex-direction: column; }
  .sidebar { display: none; }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 0 16px;
    padding-top: var(--safe-top);
    height: calc(var(--header-h) + var(--safe-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 10;
  }
  .mobile-header-title { font-size: 1.15rem; font-weight: 600; color: var(--accent); }
  .mobile-header-right { display: flex; align-items: center; gap: 10px; }
  .mobile-menu-btn {
    width: 38px; height: 38px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted); font-size: 1.1rem; flex-shrink: 0;
  }

  .mobile-drawer-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 40; opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
  }
  .mobile-drawer-overlay.open { opacity: 1; pointer-events: all; }

  .mobile-drawer {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    border-top: 1px solid var(--border);
    z-index: 50;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: var(--safe-bottom);
  }
  .mobile-drawer.open { transform: translateY(0); }

  .drawer-handle {
    width: 36px; height: 4px;
    background: var(--border2); border-radius: 2px;
    margin: 12px auto 8px;
  }
  .drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 20px 16px; border-bottom: 1px solid var(--border);
  }
  .drawer-header h2 { font-size: 1.1rem; font-weight: 600; color: var(--accent); }
  .drawer-close-btn {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text-muted); font-size: 1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .drawer-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }

  .main-header { display: none; }
  .conv-feed { padding: 16px !important; gap: 16px !important; }
  .input-bar { padding: 12px 14px calc(12px + var(--safe-bottom)) !important; }
  .ask-btn { padding: 14px 20px !important; font-size: 0.9rem !important; min-width: 90px; }
  .question-input { font-size: 16px !important; }
  .q-bubble { max-width: 80% !important; }
  .resp-card { padding: 14px !important; }
  .resp-body { font-size: 0.85rem !important; }
  .input-hint { display: none; }
  .hint-desktop { display: none; }
  .hint-mobile { display: block; }
}

/* ── SIDEBAR / DRAWER SHARED ── */
.sidebar-logo {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo h1 { font-size: 1.4rem; font-weight: 600; color: var(--accent); line-height: 1.2; }
.sidebar-logo p { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; font-weight: 300; }

.sidebar-section { padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-section-title {
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 12px;
}

/* ── ADVISOR TOGGLES ──
   Color comes from --advisor-color set inline by ui.js.
   No advisor-specific classes needed here.
──────────────────────────────────────────────────────────── */
.advisor-list { display: flex; flex-direction: column; gap: 6px; }
.advisor-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s; border: 1px solid transparent;
  user-select: none;
}
.advisor-toggle:hover  { background: var(--surface2); }
.advisor-toggle.active { background: var(--surface2); border-color: var(--border); }
.advisor-toggle.inactive { opacity: 0.4; }

/* Dot reads advisor color from parent's custom property */
.advisor-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--advisor-color, var(--text-muted));
}

.advisor-info { flex: 1; min-width: 0; }
.advisor-info strong { font-size: 0.82rem; font-weight: 500; display: block; }
.advisor-info span {
  font-size: 0.7rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}

.toggle-switch {
  width: 34px; height: 20px; background: var(--border2);
  border-radius: 10px; position: relative; flex-shrink: 0; transition: background 0.2s;
}
.toggle-switch::after {
  content: ''; position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-muted); top: 2px; left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.advisor-toggle.active  .toggle-switch { background: var(--accent2); }
.advisor-toggle.active  .toggle-switch::after { transform: translateX(14px); background: white; }

/* ── MEMORY / HISTORY ── */
.memory-area {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.memory-area label {
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim); display: block; margin-bottom: 6px;
}
.memory-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem; padding: 10px; resize: none; outline: none;
  line-height: 1.5; transition: border-color 0.2s;
}
.memory-textarea:focus { border-color: var(--accent2); }
.memory-textarea::placeholder { color: var(--text-dim); }

.memory-save-btn {
  padding: 9px 16px; background: var(--accent-dim); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 8px; font-size: 0.78rem;
  font-family: 'DM Sans', sans-serif; cursor: pointer; transition: all 0.2s; font-weight: 500;
}
.memory-save-btn:hover,
.memory-save-btn:active { background: var(--accent); color: var(--bg); }
.memory-saved { color: var(--success); font-size: 0.7rem; }

.history-list { overflow-y: auto; max-height: 180px; }
.history-item {
  padding: 9px 10px; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all 0.15s; border: 1px solid transparent;
}
.history-item:hover,
.history-item:active { background: var(--surface2); color: var(--text); }
.history-item.active-hist { background: var(--surface2); border-color: var(--border); color: var(--text); }
.history-empty { font-size: 0.72rem; color: var(--text-dim); font-style: italic; }

.new-session-btn {
  font-size: 0.7rem; color: var(--accent); background: none;
  border: 1px solid var(--accent); border-radius: 5px;
  cursor: pointer; padding: 3px 8px; font-family: 'DM Sans', sans-serif;
  transition: all 0.2s;
}
.new-session-btn:hover,
.new-session-btn:active { background: var(--accent); color: var(--bg); }

.clear-history-btn {
  font-size: 0.7rem; color: var(--text-dim); background: none; border: none;
  cursor: pointer; padding: 4px 0; font-family: 'DM Sans', sans-serif; transition: color 0.2s;
}
.clear-history-btn:hover,
.clear-history-btn:active { color: var(--danger); }

/* ── MAIN AREA ── */
.main-header {
  flex-shrink: 0;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.main-header h2 { font-size: 1.2rem; color: var(--text-muted); font-weight: 400; font-style: italic; }

.conv-feed {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px 28px;
  display: flex; flex-direction: column; gap: 24px;
}

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 12px; color: var(--text-dim); padding: 40px 24px;
}
.empty-state .big-icon { font-size: 2.5rem; opacity: 0.3; }
.empty-state h3 { font-size: 1.3rem; color: var(--text-muted); font-weight: 400; }
.empty-state p { font-size: 0.78rem; line-height: 1.6; max-width: 300px; }

.hint-mobile { display: none; }
.hint-desktop { display: block; }

.q-bubble {
  align-self: flex-end; max-width: 65%;
  background: var(--accent2); color: white;
  padding: 12px 16px; border-radius: 16px 16px 4px 16px;
  font-size: 0.88rem; line-height: 1.5; word-break: break-word;
}

.resp-group { display: flex; flex-direction: column; gap: 12px; }

.diverge-notice {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--danger);
  background: rgba(224,120,120,0.08);
  border: 1px solid rgba(224,120,120,0.2);
  border-radius: 6px; padding: 6px 12px;
}

/* ── RESPONSE CARD ──
   --advisor-color is set inline by ui.js.
   No card.color class needed.
──────────────────────────────────────────────────────────── */
.resp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
  position: relative; overflow: hidden; animation: fadeUp 0.35s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.resp-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--advisor-color, var(--text-muted));
}

.resp-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.resp-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 600; flex-shrink: 0;
  /* Tinted background derived from advisor color via opacity trick */
  background: color-mix(in srgb, var(--advisor-color, var(--text-muted)) 15%, transparent);
  color: var(--advisor-color, var(--text-muted));
}

.resp-name { font-size: 0.78rem; font-weight: 600; }
.resp-role { font-size: 0.68rem; color: var(--text-muted); }
.resp-body { font-size: 0.83rem; line-height: 1.72; color: var(--text); white-space: pre-wrap; word-break: break-word; }

/* ── SKELETON LOADER ── */
.skeleton-line {
  height: 12px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite; margin-bottom: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── INPUT BAR ── */
.input-bar {
  flex-shrink: 0;
  padding: 14px 28px calc(18px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.input-row { display: flex; gap: 10px; align-items: flex-end; }

.question-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem; padding: 12px 14px; resize: none; outline: none;
  line-height: 1.5; transition: border-color 0.2s;
  min-height: 46px; max-height: 120px;
}
.question-input:focus { border-color: var(--accent2); }
.question-input::placeholder { color: var(--text-dim); }

.ask-btn {
  padding: 12px 22px; background: var(--accent); color: var(--bg);
  border: none; border-radius: 10px; font-family: 'DM Sans', sans-serif;
  font-weight: 600; font-size: 0.82rem; cursor: pointer;
  transition: all 0.2s; flex-shrink: 0; letter-spacing: 0.01em;
  touch-action: manipulation;
}
.ask-btn:hover:not(:disabled)  { background: #d9bc94; transform: translateY(-1px); }
.ask-btn:active:not(:disabled) { background: #d9bc94; transform: translateY(0); }
.ask-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.input-hint { font-size: 0.68rem; color: var(--text-dim); margin-top: 6px; }
.disclaimer { font-size: 0.65rem; color: var(--text-dim); text-align: center; margin-top: 8px; line-height: 1.4; }

/* ── ERROR BAR ──
   Inline validation error shown above the input bar.
   Replaces alert() — non-blocking, dismissable, auto-fades.
──────────────────────────────────────────────────────────── */
.error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(224,120,120,0.12);
  border-top: 1px solid rgba(224,120,120,0.35);
  color: var(--danger);
  font-size: 0.8rem;
  animation: fadeUp 0.2s ease;
  flex-shrink: 0;
}
.error-bar-close {
  background: none; border: none; cursor: pointer;
  color: var(--danger); font-size: 0.9rem; padding: 0;
  flex-shrink: 0; opacity: 0.7; font-family: 'DM Sans', sans-serif;
}
.error-bar-close:hover { opacity: 1; }

/* Scrollbars */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
