:root {
  --bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f6f7f9;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --up: #15803d;
  --down: #dc2626;
  --radius: 10px;
  color-scheme: light;
}

/* The [hidden] attribute must always win over any display rule
   (a previous project's login screen stayed visible because of this). */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  border: 0; background: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
  display: inline-grid; place-items: center;
  color: var(--muted); font-size: 20px; line-height: 1;
}
.icon-btn:hover { background: var(--soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 320px; display: grid; gap: 10px; }
.login-card h1 { margin: 0 0 12px; font-size: 24px; }
.login-card label { font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--down); min-height: 1.2em; margin: 0; font-size: 14px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; font-size: 17px; }
.topbar .search { flex: 1; max-width: 480px; margin: 0 auto; }

/* Search (autocomplete) */
.search { position: relative; }
.search-results {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}
.search-results li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.search-results li[aria-selected=true], .search-results li:hover { background: var(--soft); }
.search-results .sym { font-weight: 600; min-width: 56px; }
.search-results .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results .info { color: var(--muted); cursor: default; }
.search-results .info:hover { background: none; }

/* Menus */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 160px; padding: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  display: grid;
}
.menu button {
  border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu button:hover { background: var(--soft); }
.menu .danger { color: var(--down); }

/* Notice */
.notice {
  margin: 12px 24px 0; padding: 8px 12px;
  background: var(--soft); border-radius: 8px; font-size: 14px;
}

/* Layout: watchlist beside chart on desktop, stacked on mobile */
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 24px;
  padding: 20px 24px 32px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}
.panel { min-width: 0; }

/* Watchlist */
.watchlist-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.watchlist-head select { font-weight: 600; }
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: 1fr auto 24px;
  gap: 8px; align-items: center;
  padding: 10px 6px 10px 10px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.row:hover { background: var(--soft); }
.row.selected { background: #eff4ff; }
.row-id { min-width: 0; }
.row-sym { font-weight: 600; }
.row-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-quote { text-align: right; }
.row-price { font-weight: 500; }
.row-change { font-size: 13px; }
.row-remove {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  width: 24px; height: 24px; border-radius: 6px; font-size: 16px; line-height: 1;
  opacity: 0;
}
.row:hover .row-remove, .row-remove:focus-visible { opacity: 1; }
.row-remove:hover { background: var(--line); color: var(--text); }
@media (hover: none) { .row-remove { opacity: .6; } }
.empty { padding: 24px 4px; }
.watchlist-foot { display: grid; gap: 2px; margin-top: 10px; font-size: 12px; }

/* Detail / chart panel */
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.detail-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.detail-price { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.big-price { font-size: 32px; font-weight: 600; font-variant-numeric: tabular-nums; }
.change { font-variant-numeric: tabular-nums; }
.chart-area {
  height: 360px; border: 1px dashed var(--line); border-radius: var(--radius);
  display: grid; place-items: center;
}

/* Dialog */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(360px, calc(100vw - 32px));
  box-shadow: 0 16px 40px rgba(0,0,0,.12);
}
dialog::backdrop { background: rgba(17,24,39,.25); }
dialog h3 { margin: 0 0 12px; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand { display: none; }
  .notice { margin: 12px 16px 0; }
  .layout { grid-template-columns: 1fr; padding: 16px 16px 32px; gap: 28px; }
  .chart-area { height: 260px; }
  .big-price { font-size: 28px; }
}
