*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, a, [role="button"] { touch-action: manipulation; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273549;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --green: #4ade80;
  --red: #f87171;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --header-h: calc(60px + env(safe-area-inset-top, 0px));
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 0 16px calc(12px) calc(16px + var(--safe-left));
  padding-top: env(safe-area-inset-top, 0px);
  gap: 12px;
  padding-right: calc(16px + var(--safe-right));
}
header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; flex: 1; }
header h1 span { color: var(--accent); }

/* Hamburger button */
#menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  -webkit-tap-highlight-color: transparent;
}
#menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
#menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#menu-btn.open span:nth-child(2) { opacity: 0; }
#menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Drawer */
#drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}
#drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity 0.25s;
}
#drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  padding-top: calc(32px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: env(safe-area-inset-left, 0px);
}
#drawer.open { pointer-events: auto; }
#drawer.open #drawer-backdrop { opacity: 1; }
#drawer.open #drawer-panel { transform: translateX(0); }

.drawer-logo {
  padding: 0 20px 24px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-radius: var(--radius);
  margin: 2px 8px;
}
nav a:hover, nav a.active {
  background: var(--surface2);
  color: var(--text);
}
nav a svg { flex-shrink: 0; opacity: 0.7; }
nav a.active svg { opacity: 1; color: var(--accent); }

.drawer-footer {
  margin-top: 24px;
  padding: 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.drawer-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
.drawer-logout:hover { background: var(--surface2); color: var(--red); }
.drawer-logout svg { flex-shrink: 0; opacity: 0.7; }

/* ── User Management ── */
.user-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
}
.user-form-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 14px;
}
.user-form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.user-form-row input {
  flex: 1;
  min-width: 120px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
.user-form-row input:focus { border-color: var(--accent); }
.btn-primary-sm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--accent);
  color: #0f172a;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s;
}
.btn-primary-sm:disabled { opacity: .5; cursor: default; }
.form-error {
  margin-top: 10px;
  font-size: .82rem;
  color: var(--red);
  min-height: 18px;
}
.user-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: border-color .15s;
}
.user-row:hover { border-color: var(--accent); }
.user-row-left { display: flex; align-items: center; gap: 12px; }
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.user-name { font-size: .95rem; font-weight: 600; }
.user-meta { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.user-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background .15s, color .15s;
  display: flex;
}
.user-delete-btn:hover { background: var(--surface2); color: var(--red); }

/* ── Main content ── */
main {
  padding: 20px 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  max-width: 600px;
  margin: 0 auto;
}

/* ── Section title ── */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h2 { font-size: 1rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.badge {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
}

/* ── Stock cards ── */
.stock-list { display: flex; flex-direction: column; gap: 10px; }

.stock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.stock-card:hover  { background: var(--surface2); }
.stock-card:active { filter: brightness(0.9); }

.stock-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--accent);
  flex-shrink: 0;
  border: 1px solid var(--border);
  letter-spacing: -0.02em;
}

.stock-info { flex: 1; min-width: 0; }
.stock-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-ticker {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.stock-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.tag {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.delete-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.delete-btn:hover { background: rgba(248,113,113,0.1); color: var(--red); border-color: rgba(248,113,113,0.3); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state svg { opacity: 0.3; margin-bottom: 16px; }
.empty-state p { font-size: 0.95rem; margin-bottom: 20px; }
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #0f172a;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 20px;
  border-radius: 99px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-dim); }

/* ── Add Stock page ── */
.page-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }

.search-box {
  position: relative;
  margin-bottom: 24px;
}
.search-box input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 14px 48px 14px 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus { border-color: var(--accent); }
.search-box button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #0f172a;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.search-box button:hover { background: var(--accent-dim); }

/* Search result cards */
#search-results { display: flex; flex-direction: column; gap: 10px; }

.search-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s;
}
.search-result-card:hover { border-color: var(--accent); }

.result-card-info { flex: 1; min-width: 0; }
.result-card-name {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-card-ticker { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.result-card-meta   { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.result-add-btn {
  flex-shrink: 0;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #0f172a;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.result-add-btn:hover    { background: var(--accent-dim); }
.result-add-btn:disabled { opacity: 0.4; cursor: default; }
.result-add-btn.added    { background: var(--green); color: #0f172a; font-size: 1rem; }

/* Error / success toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 999;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { color: var(--green); border-color: rgba(74,222,128,0.3); }
.toast.error { color: var(--red); border-color: rgba(248,113,113,0.3); }

/* Loading spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
  height: 72px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Safe area bottom padding */
main { padding-bottom: calc(var(--safe-bottom) + 20px); }

.toast {
  bottom: calc(var(--safe-bottom) + 20px);
}

/* ── Back button (stock detail) ── */
#back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  text-decoration: none;
  padding: 4px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── Stock detail hero ── */
.detail-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.stock-logo.large {
  width: 52px;
  height: 52px;
  font-size: 1rem;
  border-radius: 14px;
  flex-shrink: 0;
}
.detail-name  { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.detail-ticker { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; letter-spacing: 0.04em; }
.detail-price-block { margin-left: auto; text-align: right; }
.detail-price { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.03em; color: var(--accent); }
.detail-price-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.stat-val   { font-size: 0.85rem; font-weight: 700; }
.stat-val.green { color: var(--green); }
.stat-val.red   { color: var(--red); }

/* ── Chart card ── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}
.chart-title { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* Day selector */
.day-scroller {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.day-scroller::-webkit-scrollbar { display: none; }
.day-btn {
  flex-shrink: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.day-btn.active,
.day-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f172a;
}

/* Chart canvas */
.chart-wrap {
  position: relative;
  height: 220px;
}
#price-chart { width: 100% !important; height: 100% !important; }
.chart-empty {
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  /* shown/hidden via inline style in stock.js */
}

