:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #f1f3f8;
  --border: #e4e7ee;
  --text: #101828;
  --text-muted: #64748b;
  --text-faint: #98a2b3;

  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-light: #eef3ff;
  --brand-text-on: #ffffff;

  --up: #16a34a;
  --up-bg: #ecfdf3;
  --down: #dc2626;
  --down-bg: #fef2f2;
  --neutral-bg: #f1f3f8;

  --amber: #b45309;
  --amber-bg: #fffbeb;
  --violet: #6d28d9;
  --violet-bg: #f5f3ff;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0a0d14;
  --surface: #121623;
  --surface-alt: #1a1f2e;
  --border: #262c3d;
  --text: #e7e9ee;
  --text-muted: #9aa3b5;
  --text-faint: #6b7488;

  --brand: #4f8cff;
  --brand-hover: #6da0ff;
  --brand-light: rgba(79, 140, 255, 0.14);
  --brand-text-on: #05070c;

  --up: #34d399;
  --up-bg: rgba(52, 211, 153, 0.12);
  --down: #f87171;
  --down-bg: rgba(248, 113, 113, 0.12);
  --neutral-bg: #1a1f2e;

  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.12);
  --violet: #a78bfa;
  --violet-bg: rgba(167, 139, 250, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}
html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover {
  text-decoration: none;
}
.brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--brand), #7aa8ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin-left: 28px;
}
.topnav a {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.topnav a:hover {
  color: var(--text);
  background: var(--surface-alt);
  text-decoration: none;
}
.topnav a.active {
  color: var(--brand);
  background: var(--brand-light);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover {
  background: var(--surface-alt);
  color: var(--text);
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
}

/* mobile nav */
.nav-toggle {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.nav-toggle:hover {
  background: var(--surface-alt);
  color: var(--text);
}
.nav-toggle svg {
  flex-shrink: 0;
}

/* ---------- Layout ---------- */

main#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.view {
  display: none;
}
.view.active {
  display: block;
}

.page-header {
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0 0 4px;
}
.page-header p {
  margin: 0;
}
.page-header.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.date-filter {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.date-filter label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}
.date-filter input[type="date"] {
  width: auto;
}
.date-filter .button {
  padding: 9px 14px;
}

h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
h2 {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 28px 0 12px;
}
.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}
.faint {
  color: var(--text-faint);
}
.error {
  color: var(--down);
  font-size: 0.88rem;
}

/* ---------- Cards / surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ---------- Screener tabs ---------- */

.screener-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.screener-tabs button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.12s ease;
}
.screener-tabs button:hover {
  border-color: var(--brand);
  color: var(--text);
}
.screener-tabs button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-text-on);
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.as-of {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: var(--radius-pill);
}
.as-of .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--up);
  flex-shrink: 0;
}

/* ---------- Form controls ---------- */

select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="url"],
input[type="number"],
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: var(--font);
  width: 100%;
}
select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
}
th,
td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-alt);
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr {
  transition: background 0.1s ease;
}
tbody tr:hover {
  background: var(--surface-alt);
}

.symbol-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.symbol-cell .sym {
  font-weight: 700;
  color: var(--text);
}
.symbol-cell .company {
  font-size: 0.78rem;
  color: var(--text-faint);
  font-weight: 400;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
th.num-head {
  text-align: right;
}

.up {
  color: var(--up);
}
.down {
  color: var(--down);
}

.chg-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chg-pill.up {
  color: var(--up);
  background: var(--up-bg);
}
.chg-pill.down {
  color: var(--down);
  background: var(--down-bg);
}
.chg-pill.flat {
  color: var(--text-muted);
  background: var(--neutral-bg);
}

/* ---------- Pagination ---------- */

.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}
.pager button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.pager button:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}
.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- Sector cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.sector-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: block;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
  overflow: hidden;
}
.sector-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--brand);
}
.sector-card.theme::before {
  background: var(--violet);
}
.sector-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.sector-card .kind {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.sector-card .name {
  color: var(--text);
  font-weight: 700;
  font-size: 0.98rem;
  margin-bottom: 8px;
}
.sector-card .count {
  color: var(--text-muted);
  font-size: 0.8rem;
  display: inline-block;
  background: var(--surface-alt);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 14px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-muted);
}
.back-link:hover {
  color: var(--brand);
}

/* ---------- Stock detail / ticker header ---------- */

.ticker-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 6px;
}
.ticker-header .id h1 {
  margin: 0;
  font-size: 1.55rem;
}
.ticker-header .id .company {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-top: 2px;
}
.ticker-header .price-block {
  text-align: right;
}
.ticker-header .price {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.stat-grid .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.stat-grid .stat .label {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-grid .stat .value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.badge {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}
.badge.on {
  color: var(--up);
  background: var(--up-bg);
  border-color: transparent;
}
.badge.sector {
  color: var(--brand);
  background: var(--brand-light);
  border-color: transparent;
  font-weight: 600;
}

/* ---------- Call type badges ---------- */

.call-type {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.call-type.buy,
.call-type.sector_positive,
.call-type.accumulate {
  color: var(--up);
  background: var(--up-bg);
}
.call-type.sell,
.call-type.sector_negative {
  color: var(--down);
  background: var(--down-bg);
}
.call-type.neutral,
.call-type.other {
  color: var(--text-muted);
  background: var(--neutral-bg);
}

/* ---------- Analyst call cards ---------- */

.call-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.call-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.call-card.buy,
.call-card.sector_positive,
.call-card.accumulate {
  border-left-color: var(--up);
}
.call-card.sell,
.call-card.sector_negative {
  border-left-color: var(--down);
}
.call-card.neutral,
.call-card.other {
  border-left-color: var(--text-faint);
}
.call-card .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 8px;
}
.call-card .meta .sep {
  color: var(--text-faint);
}
.call-card .summary {
  color: var(--text);
  line-height: 1.6;
}
.call-card .symbols {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.call-card .symbols a {
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  color: var(--text);
}
.call-card .symbols a:hover {
  border-color: var(--brand);
  color: var(--brand);
  text-decoration: none;
}

/* ---------- Forms ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-muted);
}
.form .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.form .checkbox-label input {
  width: auto;
}

button,
.button {
  background: var(--brand);
  border: 1px solid var(--brand);
  color: var(--brand-text-on);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease;
}
button:hover,
.button:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  text-decoration: none;
}
.button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.button.secondary:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.admin-header > div {
  display: flex;
  gap: 8px;
}

.admin-subnav {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.admin-subnav a {
  padding: 8px 4px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.admin-subnav a:hover {
  color: var(--text);
  text-decoration: none;
}
.admin-subnav a.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 28px 0 12px;
}
.section-header h2 {
  margin: 0;
}

.corp-action-type {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--neutral-bg);
}
.corp-action-type.dividend {
  color: var(--up);
  background: var(--up-bg);
}
.corp-action-type.bonus,
.corp-action-type.split {
  color: var(--brand);
  background: var(--brand-light);
}
.corp-action-type.rights,
.corp-action-type.buyback {
  color: var(--amber);
  background: var(--amber-bg);
}
.corp-action-type.agm,
.corp-action-type.board_meeting {
  color: var(--violet);
  background: var(--violet-bg);
}

.upcoming-tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .topnav {
    display: none;
  }
  .nav-toggle {
    display: flex;
  }
  .topbar.menu-open .topnav {
    display: flex;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 8px 16px 14px;
    margin-left: 0;
    box-shadow: var(--shadow-md);
  }
  .topbar.menu-open .topnav a {
    padding: 10px 12px;
  }
}

@media (max-width: 600px) {
  main#app {
    padding: 18px 16px 40px;
  }
  .topbar {
    padding: 0 16px;
  }
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .form {
    max-width: 100%;
    padding: 16px;
  }
  .ticker-header {
    flex-direction: column;
  }
  .ticker-header .price-block {
    text-align: left;
  }
}
