/* NiftyEdge Design System — High-Contrast Financial Terminal UI (Light & Dark) */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-elevated: #ffffff;
  --border: #cbd5e1;
  --border-subtle: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --accent: #0f766e;
  --accent-hover: #0d5e58;
  --accent-contrast: #ffffff;
  --accent-soft: #ccfbf1;
  --accent-soft-text: #115e59;

  --bull-bg: #dcfce7;
  --bull-border: #86efac;
  --bull-text: #14532d;
  --bull-bar: #16a34a;

  --buy-bg: #d1fae5;
  --buy-border: #6ee7b7;
  --buy-text: #065f46;

  --hold-bg: #fef3c7;
  --hold-border: #fcd34d;
  --hold-text: #78350f;
  --hold-bar: #d97706;

  --sell-bg: #fee2e2;
  --sell-border: #fca5a5;
  --sell-text: #7f1d1d;
  --sell-bar: #dc2626;

  --strong-sell-bg: #fecaca;
  --strong-sell-border: #f87171;
  --strong-sell-text: #7f1d1d;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #0f172a;
  --surface-elevated: #1e293b;
  --border: #334155;
  --border-subtle: #1e293b;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --text-soft: #94a3b8;
  --accent: #14b8a6;
  --accent-hover: #2dd4bf;
  --accent-contrast: #042f2e;
  --accent-soft: rgba(20, 184, 166, 0.16);
  --accent-soft-text: #5eead4;

  --bull-bg: rgba(22, 163, 74, 0.18);
  --bull-border: rgba(74, 222, 128, 0.45);
  --bull-text: #86efac;
  --bull-bar: #22c55e;

  --buy-bg: rgba(16, 185, 129, 0.16);
  --buy-border: rgba(52, 211, 153, 0.4);
  --buy-text: #6ee7b7;

  --hold-bg: rgba(245, 158, 11, 0.18);
  --hold-border: rgba(251, 191, 36, 0.45);
  --hold-text: #fcd34d;
  --hold-bar: #f59e0b;

  --sell-bg: rgba(239, 68, 68, 0.18);
  --sell-border: rgba(248, 113, 113, 0.45);
  --sell-text: #fca5a5;
  --sell-bar: #ef4444;

  --strong-sell-bg: rgba(220, 38, 38, 0.25);
  --strong-sell-border: rgba(248, 113, 113, 0.55);
  --strong-sell-text: #fecaca;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.num, td.num, th.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 8px 14px;
  font-weight: 700;
  z-index: 999;
}
.skip-link:focus { left: 12px; top: 12px; border-radius: var(--radius-sm); }

/* Header & Navigation */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  height: 64px;
}

.nav-inner {
  max-width: 1380px;
  margin: 0 auto;
  height: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.125rem;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.9rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-menu-btn {
  display: none;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  padding: 0;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mobile-menu-btn [data-icon="close"] { display: none; }
.mobile-menu-btn.is-open [data-icon="open"] { display: none; }
.mobile-menu-btn.is-open [data-icon="close"] { display: block; }

.mobile-drawer {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}
.mobile-drawer.open { display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 860px) {
  .nav-links { display: none; }
  .mobile-menu-btn { display: inline-flex; align-items: center; gap: 6px; }
}

/* Main Container */
.container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.25;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--border-subtle);
  text-decoration: none;
}

.btn-danger {
  background: var(--sell-bg);
  color: var(--sell-text);
  border-color: var(--sell-border);
}

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.input, .select {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.input::placeholder { color: var(--text-soft); }
.label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}
.kpi-value {
  font-size: 1.4rem;
  font-weight: 800;
  margin-top: 4px;
  letter-spacing: -0.02em;
}
.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Badges & Rating Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-strong-buy { background: var(--bull-bg); border-color: var(--bull-border); color: var(--bull-text); }
.badge-buy { background: var(--buy-bg); border-color: var(--buy-border); color: var(--buy-text); }
.badge-hold { background: var(--hold-bg); border-color: var(--hold-border); color: var(--hold-text); }
.badge-sell { background: var(--sell-bg); border-color: var(--sell-border); color: var(--sell-text); }
.badge-strong-sell { background: var(--strong-sell-bg); border-color: var(--strong-sell-border); color: var(--strong-sell-text); }
.badge-neutral { background: var(--surface-alt); border-color: var(--border); color: var(--text-muted); }

.text-pos { color: var(--bull-text); font-weight: 700; }
.text-neg { color: var(--sell-text); font-weight: 700; }

/* Sector strip */
.sector-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 18px;
}
.sector-pill {
  flex: 0 0 auto;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text);
  transition: border-color 0.15s;
}
.sector-pill:hover, .sector-pill.active {
  border-color: var(--accent);
  text-decoration: none;
}

/* Filter bar */
.filter-form {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.1fr 0.9fr 0.9fr 1fr auto;
  gap: 10px;
  align-items: end;
}
@media (max-width: 1080px) {
  .filter-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .filter-form { grid-template-columns: 1fr; }
}

.portfolio-trade-form {
  display: grid;
  grid-template-columns: 2fr 0.9fr 0.9fr 1.2fr 1.1fr auto;
  gap: 10px;
  align-items: end;
}
@media (max-width: 960px) {
  .portfolio-trade-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .portfolio-trade-form { grid-template-columns: 1fr; }
}

/* Tables & Responsive Mobile Cards */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  text-align: left;
  padding: 11px 12px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.num, tbody td.num { text-align: right; }
tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
tbody tr:hover { background: var(--surface-alt); }
tbody tr:last-child td { border-bottom: none; }

.mobile-cards { display: none; }
.clickable-row { cursor: pointer; }
.stock-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.stock-card-link:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
@media (max-width: 768px) {
  .desktop-table { display: none; }
  .mobile-cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
}

/* Signal Meter (-10 to +10) */
.meter-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #dc2626 0%, #f59e0b 50%, #16a34a 100%);
  margin: 10px 0 6px;
}
.meter-marker {
  position: absolute;
  top: -4px;
  width: 8px;
  height: 22px;
  border-radius: 4px;
  background: var(--text);
  border: 2px solid var(--surface);
  transform: translateX(-50%);
}
.meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-soft);
  font-weight: 700;
}

.metric-bar-bg {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--border-subtle);
  overflow: hidden;
  margin-top: 6px;
}
.metric-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* Alerts */
.alert {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.alert-danger {
  background: var(--sell-bg);
  border-color: var(--sell-border);
  color: var(--sell-text);
}
.alert-success {
  background: var(--bull-bg);
  border-color: var(--bull-border);
  color: var(--bull-text);
}
.alert-warn {
  background: var(--hold-bg);
  border-color: var(--hold-border);
  color: var(--hold-text);
}

.skeleton {
  height: 16px;
  border-radius: 4px;
  background: var(--border-subtle);
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.site-footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
  padding: 20px 16px;
  color: var(--text-soft);
  font-size: 0.82rem;
}
.footer-inner {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
}
