/* macOS Big Sur / Sonoma inspired theme */
:root {
  --system-blue:   #0a84ff;
  --system-green:  #30d158;
  --system-yellow: #ffd60a;
  --system-orange: #ff9f0a;
  --system-red:    #ff453a;
  --system-pink:   #ff375f;
  --system-purple: #bf5af2;
  --system-gray:   #98989d;

  --bg-window:        rgba(28, 28, 30, 0.72);
  --bg-window-solid:  #1c1c1e;
  --bg-sidebar:       rgba(38, 38, 40, 0.82);
  --bg-content:       #2c2c2e;
  --bg-row:           rgba(255, 255, 255, 0.02);
  --bg-row-hover:     rgba(255, 255, 255, 0.045);
  --bg-elev:          rgba(58, 58, 60, 0.5);
  --bg-input:         rgba(118, 118, 128, 0.24);

  --border:           rgba(255, 255, 255, 0.08);
  --border-strong:    rgba(255, 255, 255, 0.14);
  --separator:        rgba(255, 255, 255, 0.06);

  --text:             rgba(255, 255, 255, 0.92);
  --text-dim:         rgba(235, 235, 245, 0.6);
  --text-tertiary:    rgba(235, 235, 245, 0.3);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --sidebar-w: 220px;
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: -apple-system, "SF Pro Display", "SF Pro Text", BlinkMacSystemFont,
               "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(ellipse at top left,  rgba(10, 132, 255, 0.18), transparent 50%),
    radial-gradient(ellipse at top right, rgba(191, 90, 242, 0.12), transparent 50%),
    linear-gradient(180deg, #1a1a1c 0%, #0f0f10 100%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  letter-spacing: -0.01em;
}

/* ── Layout: sidebar + content (Finder style) ────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

aside.sidebar {
  background: var(--bg-sidebar);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 18px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--system-yellow);
  box-shadow: 0 0 14px var(--system-yellow);
}

.sidebar-section {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 16px 12px 6px;
  font-weight: 600;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s;
}

.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); }
.sidebar nav a.active {
  background: var(--system-blue);
  color: white;
  box-shadow: 0 1px 3px rgba(10, 132, 255, 0.4);
}
.sidebar nav a .icon { width: 18px; text-align: center; opacity: 0.85; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 8px 4px;
  border-top: 1px solid var(--separator);
}

/* ── Main content ─────────────────────────────────────────────────────────── */

main {
  padding: 28px 36px 64px;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 28px 0 12px;
  letter-spacing: -0.015em;
}

.subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 0 24px;
}

.subtitle a {
  color: var(--system-blue);
  text-decoration: none;
  margin: 0 6px;
}
.subtitle a:hover { text-decoration: underline; }

code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  background: var(--system-blue);
  color: white;
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.12s, transform 0.04s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  letter-spacing: -0.01em;
}
.btn:hover  { filter: brightness(1.1); }
.btn:active { transform: translateY(0.5px); filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: var(--bg-input);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ── Status banner ────────────────────────────────────────────────────────── */

.scan-status {
  background: var(--bg-elev);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.scan-status.running { border-color: rgba(10, 132, 255, 0.4); color: var(--system-blue); }
.scan-status.done    { border-color: rgba(48, 209, 88, 0.4);  color: var(--system-green); }
.scan-status.error   { border-color: rgba(255, 69, 58, 0.4);  color: var(--system-red); }
.hidden { display: none; }

/* ── Cards (vibrancy) ─────────────────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.card-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.card-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

thead { background: rgba(255, 255, 255, 0.03); }

th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--text); }
th.sort-asc::after  { content: " ▲"; color: var(--system-blue); font-size: 9px; }
th.sort-desc::after { content: " ▼"; color: var(--system-blue); font-size: 9px; }

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--separator);
  font-size: 13px;
  white-space: nowrap;
}

tbody tr { transition: background 0.08s; }
tbody tr:hover { background: var(--bg-row-hover); }
tbody tr:last-child td { border-bottom: none; }

td.num { text-align: right; font-variant-numeric: tabular-nums; }

.ticker-link {
  color: var(--system-blue);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.ticker-link:hover { text-decoration: underline; }

/* ── Tier badges (traffic-light style) ───────────────────────────────────── */

.tier {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
}
.tier::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.tier-strong { color: var(--system-green);  background: rgba(48, 209, 88, 0.12); }
.tier-medium { color: var(--system-yellow); background: rgba(255, 214, 10, 0.12); }
.tier-weak   { color: var(--system-gray);   background: rgba(152, 152, 157, 0.12); }

/* ── Score bar ────────────────────────────────────────────────────────────── */

.score-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.score-bar {
  display: inline-block;
  width: 64px;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--system-yellow), var(--system-green));
  border-radius: 999px;
}

.pct-pos { color: var(--system-green); }
.pct-neg { color: var(--system-red); }

/* ── Chips ────────────────────────────────────────────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.chip {
  background: rgba(10, 132, 255, 0.14);
  color: var(--system-blue);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.chip.sector {
  background: rgba(191, 90, 242, 0.14);
  color: var(--system-purple);
}

/* ── Filters (macOS form controls) ───────────────────────────────────────── */

.filters {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.filters label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filters input,
.filters select {
  background: var(--bg-input);
  border: 1px solid transparent;
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--system-blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
}

/* Custom select chevron */
.filters select {
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='rgba(235,235,245,0.6)' d='M5 6 0 0h10z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.filters .count {
  margin-left: auto;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* ── Segmented control (macOS-style) ────────────────────────────────────── */

.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.segmented a {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.12s;
}
.segmented a:hover { background: rgba(255, 255, 255, 0.05); }
.segmented a.active {
  background: rgba(120, 120, 128, 0.36);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ── Company overview card ───────────────────────────────────────────────── */

.company-card {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin: 18px 0 24px;
  box-shadow: var(--shadow-sm);
}

.company-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.company-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.company-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.company-meta .dot-sep { color: var(--text-tertiary); }

.company-summary {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.55;
  letter-spacing: -0.005em;
}

/* ── Target column in signal rows ────────────────────────────────────────── */

.signal-row .target {
  color: var(--text-tertiary);
  font-size: 11.5px;
  margin-right: 14px;
  white-space: nowrap;
  letter-spacing: -0.005em;
}

@media (max-width: 700px) {
  .signal-row .target { display: none; }
}

/* ── Detail page ──────────────────────────────────────────────────────────── */

.detail-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 6px;
}
.detail-header h1 { font-size: 38px; letter-spacing: -0.035em; }
.detail-meta { color: var(--text-dim); font-size: 13px; }

.signal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}

.signal-list {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.signal-row {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--separator);
  font-size: 13px;
}
.signal-row:last-child { border-bottom: none; }
.signal-row .check { width: 22px; font-size: 14px; }
.signal-row .label { flex: 1; }
.signal-row .pts   { color: var(--text-tertiary); font-size: 11px; }
.signal-row.passed .check { color: var(--system-green); }
.signal-row.failed .check { color: var(--text-tertiary); }

/* ── Login page ───────────────────────────────────────────────────────────── */

body.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-shell {
  width: 100%;
  max-width: 380px;
}

.login-card {
  background: var(--bg-window);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}
.login-brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--system-yellow);
  box-shadow: 0 0 14px var(--system-yellow);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 6px;
}

.login-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 22px;
}

.login-label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 14px;
}

.login-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-input);
  border: 1px solid transparent;
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.login-label input:focus {
  outline: none;
  border-color: var(--system-blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
}

.login-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}

.login-error {
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.3);
  color: var(--system-red);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

/* Sidebar logout link */
.sidebar-foot .logout-link {
  display: block;
  text-align: center;
  margin-top: 10px;
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: none;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color 0.12s, background 0.12s;
}
.sidebar-foot .logout-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-dim);
}
.empty-state h2 { color: var(--text); font-size: 20px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  aside.sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar nav { flex-direction: row; gap: 4px; }
  .sidebar-section, .sidebar-foot { display: none; }
  main { padding: 20px; }
  .signal-grid { grid-template-columns: 1fr; }
}
