/* ============================================================
   Laverton Stock Watchlist — Dark Theme
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0d0f14;
  --bg-surface:   #141720;
  --bg-elevated:  #1c2030;
  --bg-hover:     #232840;
  --border:       #252a3a;
  --border-light: #2e3450;

  --text-primary:   #e8eaf6;
  --text-secondary: #8892b0;
  --text-muted:     #4a5278;

  --accent:         #4f6ef7;
  --accent-hover:   #6b84ff;
  --accent-dim:     rgba(79, 110, 247, 0.15);

  --green:   #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red:     #ef4444;
  --red-bg:  rgba(239, 68, 68, 0.1);
  --yellow:  #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.1);

  --bull-color:  #22c55e;
  --base-color:  #4f6ef7;
  --bear-color:  #ef4444;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 2px 12px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.12em; color: var(--text-primary); }
.brand-sub  { font-size: 12px; color: var(--text-muted); letter-spacing: 0.05em; }
.topbar-actions { display: flex; gap: 8px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 0.15s;
}
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-light); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost    { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); }
.btn-danger   { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Add form ────────────────────────────────────────────── */
.add-form {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}
.add-form.hidden { display: none; }
.add-form-inner h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row input, .form-row select {
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); padding: 6px 10px; border-radius: var(--radius);
  font-size: 13px; flex: 1; min-width: 100px;
}
.form-row input:focus, .form-row select:focus {
  outline: none; border-color: var(--accent);
}
.form-status { margin-top: 6px; font-size: 12px; color: var(--text-secondary); }

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1; padding: 8px 0;
  background: none; border: none;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s; text-transform: uppercase;
}
.sidebar-tab:hover { color: var(--text-primary); }
.sidebar-tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.sidebar-tab.buy.active  { color: var(--green);        border-bottom-color: var(--green); }
.sidebar-tab.hold.active { color: var(--yellow);       border-bottom-color: var(--yellow); }
.sidebar-tab.sell.active { color: var(--red);          border-bottom-color: var(--red); }
.sidebar-tab.retired.active { color: var(--text-muted); border-bottom-color: var(--text-muted); }

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12px;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
#sidebar-content { overflow-y: auto; flex: 1; padding: 8px 0; }

.sector-group { margin-bottom: 4px; }
.sector-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 8px 14px 4px;
  text-transform: uppercase;
}
.sidebar-ticker {
  display: flex;
  align-items: center;
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  gap: 10px;
}
.sidebar-ticker:hover { background: var(--bg-elevated); }
.sidebar-ticker.active {
  background: var(--accent-dim);
  border-right: 2px solid var(--accent);
}
.st-left { display: flex; flex-direction: column; gap: 3px; min-width: 50px; }
.st-sym {
  font-size: 13px; font-weight: 700; color: var(--text-primary);
}
.st-conviction {
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  padding: 1px 5px; border-radius: 3px; text-transform: uppercase;
  display: inline-block; width: fit-content;
}
.st-conviction.buy          { background: var(--green-bg);  color: var(--green); }
.st-conviction.hold         { background: var(--yellow-bg); color: var(--yellow); }
.st-conviction.sell         { background: var(--red-bg);    color: var(--red); }
.st-conviction.retired-badge { background: var(--bg-elevated); color: var(--text-muted); }
.st-info { flex: 1; min-width: 0; }
.st-company {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.st-price {
  font-size: 12px; font-weight: 600; text-align: right;
  white-space: nowrap;
}
.st-chg { font-size: 11px; text-align: right; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral  { color: var(--text-muted); }

/* ── Main panel ──────────────────────────────────────────── */
.main-panel {
  overflow-y: auto;
  padding: 24px;
  background: var(--bg-base);
}
.welcome-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 12px;
  color: var(--text-muted);
}
.welcome-icon { font-size: 48px; }
.welcome-screen h2 { font-size: 18px; color: var(--text-secondary); }
.welcome-screen p { font-size: 13px; }

/* ── Ticker header ───────────────────────────────────────── */
.ticker-header {
  display: flex; align-items: flex-start; gap: 24px;
  padding-bottom: 20px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px; flex-wrap: wrap;
}
.ticker-header-left { flex: 1; min-width: 200px; }
.ticker-sym { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.ticker-company { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }
.ticker-sector-badge {
  display: inline-block; margin-top: 6px;
  padding: 2px 8px; border-radius: 20px;
  background: var(--accent-dim); color: var(--accent);
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
}
.ticker-header-right {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-end;
}
.price-block { display: flex; align-items: baseline; gap: 8px; }
.price-current { font-size: 26px; font-weight: 700; }
.price-change { font-size: 14px; font-weight: 600; }
.entry-block, .target-block { font-size: 13px; color: var(--text-secondary); }
.entry-pct, .upside-pct { font-weight: 600; margin-left: 4px; }
.rec-badge {
  margin-top: 4px; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em;
}
.rec-strong-buy  { background: rgba(34,197,94,0.15); color: #22c55e; }
.rec-buy         { background: rgba(134,239,172,0.15); color: #86efac; }
.rec-hold        { background: var(--yellow-bg); color: var(--yellow); }
.rec-sell        { background: var(--red-bg); color: var(--red); }
.rec-strong-sell { background: rgba(239,68,68,0.2); color: #f87171; }
.ticker-header-actions { display: flex; gap: 8px; align-items: flex-start; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }

.conviction-btns { display: flex; gap: 4px; }
.conviction-btn {
  padding: 4px 12px; border-radius: var(--radius);
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  cursor: pointer; border: 1px solid var(--border-light);
  background: transparent; color: var(--text-muted);
  transition: all 0.15s;
}
.conviction-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.conviction-btn.buy.active  { background: var(--green-bg);  color: var(--green);  border-color: var(--green); }
.conviction-btn.hold.active { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow); }
.conviction-btn.sell.active { background: var(--red-bg);    color: var(--red);    border-color: var(--red); }

#btn-retire.btn-retired-active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; margin-bottom: 20px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.tab {
  padding: 8px 16px; background: none; border: none;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s; margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Metrics grid ────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.metric-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px;
}
.metric-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.metric-value { font-size: 18px; font-weight: 700; margin-top: 4px; }
.metric-sub   { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ── Analyst summary ─────────────────────────────────────── */
.analyst-summary {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 20px;
}
.analyst-summary h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.rec-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.rec-bar-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rec-bar-count { font-size: 18px; font-weight: 700; }
.rec-bar-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.rec-bar-track {
  flex: 1; height: 8px; border-radius: 4px;
  background: var(--bg-elevated); overflow: hidden; min-width: 120px;
}
.rec-bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s; }

/* ── Chart ───────────────────────────────────────────────── */
.chart-controls {
  display: flex; gap: 20px; margin-bottom: 12px; flex-wrap: wrap;
}
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-line { display: inline-block; width: 24px; height: 3px; border-radius: 2px; }
.price-line  { background: var(--accent); }
.target-line { background: var(--yellow); }
.target-line.dashed {
  background: none;
  border-top: 2px dashed var(--yellow);
  height: 0;
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.chart-wrap { position: relative; height: 360px; }
#price-chart { width: 100% !important; height: 100% !important; }

/* ── Analyst tab ─────────────────────────────────────────── */
.analyst-rec-chart-wrap { margin-bottom: 24px; }
.analyst-rec-chart-wrap h3,
.analyst-changes-wrap h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
#rec-chart { max-width: 100%; }

.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left; padding: 8px 12px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-elevated); }

.rating-upgrade   { color: var(--green); font-weight: 600; }
.rating-downgrade { color: var(--red);   font-weight: 600; }
.rating-init      { color: var(--accent); font-weight: 600; }
.rating-reiterate { color: var(--text-secondary); }

/* ── Scenarios ───────────────────────────────────────────── */
.scenarios-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 800px) { .scenarios-grid { grid-template-columns: 1fr; } }

.scenario-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; position: relative;
  overflow: hidden;
}
.scenario-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
}
.scenario-card.bull::before { background: var(--bull-color); }
.scenario-card.base::before { background: var(--base-color); }
.scenario-card.bear::before { background: var(--bear-color); }
.sc-type-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.scenario-card.bull .sc-type-label { color: var(--bull-color); }
.scenario-card.base .sc-type-label { color: var(--base-color); }
.scenario-card.bear .sc-type-label { color: var(--bear-color); }
.sc-target { font-size: 22px; font-weight: 700; margin-bottom: 2px; }
.sc-return  { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.sc-prob    { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.sc-thesis  { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.sc-empty   { color: var(--text-muted); font-style: italic; font-size: 13px; }

.scenario-form {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; margin-bottom: 24px;
}
.scenario-form h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.scenario-form textarea {
  width: 100%; margin-top: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); padding: 8px 10px; border-radius: var(--radius);
  font-size: 13px; resize: vertical; font-family: inherit;
}
.scenario-form textarea:focus { outline: none; border-color: var(--accent); }

/* ── Analyst notes ───────────────────────────────────────── */
.notes-section h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.note-item {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px;
}
.note-meta { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; flex-wrap: wrap; }
.note-meta strong { color: var(--text-secondary); }
.note-commentary { font-size: 13px; color: var(--text-primary); line-height: 1.6; }

.note-form {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-top: 16px;
}
.note-form textarea {
  width: 100%; margin-top: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); padding: 8px 10px; border-radius: var(--radius);
  font-size: 13px; resize: vertical; font-family: inherit;
}
.note-form textarea:focus { outline: none; border-color: var(--accent); }

/* ── News ────────────────────────────────────────────────── */
.news-list { display: flex; flex-direction: column; gap: 12px; }
.news-item {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 18px;
}
.news-headline {
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  margin-bottom: 4px; line-height: 1.4;
}
.news-headline a { color: inherit; text-decoration: none; }
.news-headline a:hover { color: var(--accent); }
.news-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.news-summary { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }

/* ── Overview analyst summary ────────────────────────────── */
.overview-analyst {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}

/* ── Misc ────────────────────────────────────────────────── */
.loading-msg { color: var(--text-muted); font-size: 13px; padding: 16px; }
.hidden { display: none !important; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); padding: 10px 18px;
  border-radius: var(--radius); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 999;
  animation: fadeIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Hamburger (desktop: hidden) ─────────────────────────── */
.btn-menu { display: none; font-size: 18px; padding: 6px 10px; }

/* ── Sidebar backdrop (mobile only) ─────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 299;
}
.sidebar-backdrop.visible { display: block; }

/* ══════════════════════════════════════════════════════════
   MOBILE  (≤ 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Layout: single full-width column */
  .layout {
    grid-template-columns: 1fr;
    height: calc(100vh - 52px);
  }

  /* Sidebar: hidden drawer, slides in from left */
  .sidebar {
    position: fixed;
    left: 0; top: 52px;
    width: 80vw; max-width: 300px;
    height: calc(100vh - 52px);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 300;
    box-shadow: 6px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }

  /* Show hamburger, hide btn text */
  .btn-menu { display: inline-flex; }
  .btn-text { display: none; }

  /* Topbar: tighter */
  .topbar { padding: 0 10px; gap: 8px; }
  .brand-name { font-size: 13px; }
  .brand-sub  { display: none; }

  /* Main panel: full width, less padding */
  .main-panel { padding: 16px 12px; }

  /* Add form: stack inputs vertically */
  .add-form { padding: 12px; }
  .form-row { flex-direction: column; }
  .form-row input, .form-row select { width: 100%; min-width: 0; }

  /* Ticker header: stack vertically */
  .ticker-header {
    flex-direction: column; gap: 12px;
    padding-bottom: 16px; margin-bottom: 16px;
  }
  .ticker-sym  { font-size: 22px; }
  .ticker-header-right { align-items: flex-start; flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .price-current { font-size: 20px; }
  .ticker-header-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }

  /* Tabs: horizontal scroll, no wrap */
  .tabs {
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; gap: 0;
    margin-bottom: 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 8px 12px; font-size: 12px; }

  /* Sidebar tabs: tighter */
  .sidebar-tab { font-size: 10px; padding: 7px 0; }

  /* Metrics grid: 2 columns on mobile */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px; margin-bottom: 16px;
  }
  .metric-card  { padding: 10px 12px; }
  .metric-label { font-size: 10px; }
  .metric-value { font-size: 15px; }

  /* Analyst table: scroll horizontally */
  .analyst-changes-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { font-size: 12px; min-width: 480px; }

  /* Chart: shorter on mobile */
  .chart-wrap { height: 220px; }

  /* Notes form */
  .note-form .form-row { flex-direction: column; }

  /* Conviction buttons: wrap if needed */
  .conviction-btns { flex-wrap: wrap; }

  /* Welcome screen */
  .welcome-screen h2 { font-size: 16px; }
  .welcome-icon { font-size: 36px; }

  /* Toast: full width at bottom */
  .toast {
    left: 12px; right: 12px; bottom: 16px;
    text-align: center;
  }
}
