/* ---------- Design tokens ---------- */
/* Every color used anywhere in this file must trace back to one of these
   variables. Adding a dark theme later means adding a second block here
   (e.g. under prefers-color-scheme: dark) that redefines the same names —
   no component rules below should need to change. */
:root {
  --surface: #f5f6f8;        /* page background */
  --surface-card: #ffffff;   /* card / bubble background */
  --text-primary: #1a1d23;
  --text-secondary: #6b7280;
  --border: #e2e4e9;         /* hairline border color */
  --accent: #2563eb;
  --accent-contrast: #ffffff; /* text/icon color on top of --accent */
  --accent-soft: #e8f0fe;    /* tonal fill for .secondary-button */
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
}

/* ---------- Reset ---------- */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--surface);
  color: var(--text-primary);
}

input {
  font-family: inherit;
}

/* ---------- App layout ---------- */
/* Full-height column: scrollable content area on top, nav bar pinned to
   the bottom. Content is capped and centered so the layout still reads
   well on wide desktop windows. */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.panels {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}

.panel-inner {
  width: 100%;
  max-width: 640px;
  padding: 24px 16px 96px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel[hidden] {
  display: none;
}

/* Chat is the one panel that scrolls internally instead of scrolling the
   whole page — ID-scoped so Alerts/Briefing keep today's content-driven,
   whole-page-scroll behavior untouched. min-height:0 overrides the
   flex-item default of min-height:auto, which would otherwise let this
   box grow past .panel-inner's height to fit its content instead of
   letting .chat-messages scroll internally. */
#panel-chat {
  flex: 1;
  min-height: 0;
}

/* ---------- Bottom nav ---------- */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface-card);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
}

.tab[aria-selected="true"] {
  color: var(--accent);
}

/* ---------- Cards (shared by chat bubbles, alert rows, etc.) ---------- */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---------- Chat panel ---------- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-history-drawer {
  display: flex;
  flex-direction: column;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

/* Author rules beat the UA [hidden]{display:none} regardless of
   specificity, so the drawer's own display:flex above would otherwise
   always win and the hidden attribute would do nothing — same trap
   .panel[hidden] already guards against below. */
.chat-history-drawer[hidden] {
  display: none;
}

.chat-session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-session-row-wrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-session-row--active {
  border-color: var(--accent);
}

.chat-session-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.chat-session-title {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.chat-session-updated {
  color: var(--text-secondary);
  font-size: 12px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 1.4;
  white-space: pre-wrap;
}

.message--you {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.message--assistant {
  align-self: flex-start;
  background: var(--surface-card);
  color: var(--text-primary);
}

.message--pending {
  color: var(--text-secondary);
  font-style: italic;
}

.message--error {
  border-color: var(--danger);
  color: var(--danger);
}

.chat-ticker-card-wrapper {
  align-self: stretch;
}

.proposal-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: stretch;
}

.proposal-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 3px solid var(--accent);
}

.proposal-card--confirmed {
  color: var(--success);
  border-left-color: var(--success);
  text-align: center;
}

.proposal-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chat-form .search-field {
  flex: 1;
}

/* ---------- Alerts panel ---------- */
.search-field {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-card);
  color: var(--text-primary);
  font-size: 14px;
}

.search-field::placeholder {
  color: var(--text-secondary);
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 16px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 0;
}

.primary-button {
  align-self: flex-start;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}

.secondary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.text-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

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

.text-button:disabled {
  opacity: 0.6;
  cursor: default;
  text-decoration: none;
}

/* Ticker row (collapsed summary, clickable to expand) */
.alert-row-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.alert-row-ticker {
  font-weight: 600;
  color: var(--text-primary);
}

.alert-row-summary {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Expanded ticker alert card */
.ticker-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card-section-heading {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Watchlist toggles */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.toggle-row-label {
  color: var(--text-primary);
  font-size: 14px;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--surface-card);
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}

/* Price alerts */
.price-alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.price-alert-item-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.price-alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
}

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

.show-hidden-link {
  align-self: flex-start;
  margin-bottom: 8px;
}

.price-alert-list--hidden {
  margin-bottom: 16px;
  opacity: 0.75;
}

.price-alert-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.threshold-field {
  position: relative;
}

.threshold-adornment {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 14px;
  pointer-events: none;
}

.threshold-adornment--prefix {
  left: 14px;
}

.threshold-adornment--suffix {
  right: 14px;
}

.threshold-field .has-prefix {
  padding-left: 28px;
}

.threshold-field .has-suffix {
  padding-right: 28px;
}

.field-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.price-alert-enabled-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
}

/* ---------- Briefing panel ---------- */
.centered-message {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  color: var(--text-secondary);
  font-size: 16px;
}

/* ---------- Responsive nav: bottom bar below 768px, contained top bar at
   and above it. Same markup and tab-switching JS at both sizes — only
   .tabbar's position/sizing changes. ---------- */
@media (min-width: 768px) {
  .tabbar {
    order: -1;
    align-self: center;
    width: 100%;
    max-width: 640px;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
  }

  .panel-inner {
    padding-bottom: 24px;
  }
}
