/* ==========================================================================
   Apple Human Interface Design System - Stock & Commodity Monitor
   ========================================================================== */

:root {
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Light Theme (Default) */
  --bg-canvas: #F5F5F7;
  --bg-surface: rgba(255, 255, 255, 0.78);
  --bg-surface-secondary: rgba(255, 255, 255, 0.55);
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-input: rgba(0, 0, 0, 0.04);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(0, 113, 227, 0.45);
  --shadow-card: 0 4px 24px -2px rgba(0, 0, 0, 0.06), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 20px 48px -8px rgba(0, 0, 0, 0.22);

  --text-primary: #1D1D1F;
  --text-secondary: #86868B;
  --text-tertiary: #A1A1A6;

  --accent-blue: #0071E3;
  --accent-blue-hover: #0077ED;
  --accent-green: #34C759;
  --accent-green-bg: rgba(52, 199, 89, 0.12);
  --accent-red: #FF3B30;
  --accent-red-bg: rgba(255, 59, 48, 0.12);
  --accent-orange: #FF9500;
  --accent-gold: #D4AF37;

  --blur-glass: blur(28px) saturate(180%);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
}

[data-theme="dark"] {
  --bg-canvas: #000000;
  --bg-surface: rgba(28, 28, 30, 0.78);
  --bg-surface-secondary: rgba(44, 44, 46, 0.55);
  --bg-card: rgba(28, 28, 30, 0.82);
  --bg-input: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --border-focus: rgba(10, 132, 255, 0.55);
  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
  --shadow-modal: 0 24px 64px 0 rgba(0, 0, 0, 0.7);

  --text-primary: #F5F5F7;
  --text-secondary: #A1A1A6;
  --text-tertiary: #6E6E73;

  --accent-blue: #0A84FF;
  --accent-blue-hover: #409CFF;
  --accent-green: #30D158;
  --accent-green-bg: rgba(48, 209, 88, 0.18);
  --accent-red: #FF453A;
  --accent-red-bg: rgba(255, 69, 58, 0.18);
}

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

body {
  font-family: var(--font-system);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.47059;
  letter-spacing: -0.01em;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  padding-bottom: 60px;
}

/* Glassmorphism surfaces */
.glass {
  background: var(--bg-surface);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-subtle);
}

/* Header & Nav */
.header-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0071E3, #5856D6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

.brand-title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

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

/* Buttons */
.btn {
  font-family: var(--font-system);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s cubic-bezier(0.25, 1, 0.5, 1);
  user-select: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background-color: var(--accent-blue);
  color: white;
}

.btn-primary:hover {
  background-color: var(--accent-blue-hover);
}

.btn-secondary {
  background-color: var(--bg-surface-secondary);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background-color: var(--bg-card);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: var(--bg-surface-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-icon:hover {
  background-color: var(--bg-card);
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-stock {
  background: rgba(0, 113, 227, 0.12);
  color: var(--accent-blue);
}

.badge-metal {
  background: rgba(212, 175, 55, 0.18);
  color: var(--accent-gold);
}

.badge-ocp {
  background: rgba(238, 0, 0, 0.12);
  color: #EE0000;
  border: 1px solid rgba(238, 0, 0, 0.2);
}

/* Container */
.container {
  max-width: 1480px;
  margin: 28px auto;
  padding: 0 20px;
}

/* Summary Grid (Hero Cards) */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.hero-card {
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hero-card.hero-highlight {
  border-left: 4px solid var(--accent-blue);
}

.hero-card:hover {
  transform: translateY(-2px);
}

.hero-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hero-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.hero-sub {
  margin-top: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-positive {
  color: var(--accent-green) !important;
}

.text-negative {
  color: var(--accent-red) !important;
}

.pill-pnl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
}

.pill-positive {
  background: var(--accent-green-bg);
  color: var(--accent-green);
}

.pill-negative {
  background: var(--accent-red-bg);
  color: var(--accent-red);
}

.pill-neutral {
  background: var(--bg-surface-secondary);
  color: var(--text-secondary);
}

.hero-pa {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Segmented Control */
.segmented-control {
  display: inline-flex;
  background: var(--bg-surface-secondary);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 20px;
  gap: 2px;
}

.segment-btn {
  font-family: var(--font-system);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.segment-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Table Card */
.table-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.table-header {
  padding: 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.table-title {
  font-size: 17px;
  font-weight: 600;
}

.asset-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.asset-table th {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.3;
  vertical-align: bottom;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-secondary);
}

.asset-table td {
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

/* Column widths: asset gets the flexible space, numeric columns stay compact */
.asset-table th:nth-child(1) { width: 20%; }
.asset-table th:nth-child(2) { width: 9%; }
.asset-table th:nth-child(3) { width: 15%; }
.asset-table th:nth-child(4) { width: 15%; }
.asset-table th:nth-child(5) { width: 8%; }
.asset-table th:nth-child(6) { width: 12%; }
.asset-table th:nth-child(7) { width: 11%; }
.asset-table th:nth-child(8) { width: 8%; }
.asset-table th:nth-child(9) { width: 4%; }

/* Numbers never break mid-value; original USD price sits on its own line */
.asset-table td:not(:first-child) {
  white-space: nowrap;
}

.asset-table .orig-price {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.asset-table tr:last-child td {
  border-bottom: none;
}

.asset-table tr:hover td {
  background-color: var(--bg-surface-secondary);
}

.symbol-cell {
  display: flex;
  flex-direction: column;
}

.symbol-ticker {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.symbol-name {
  font-size: 12px;
  color: var(--text-secondary);
}

.sparkline-svg {
  width: 72px;
  height: 32px;
  overflow: visible;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  padding: 28px;
  transform: scale(0.94) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-dialog {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-system);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
  transition: all 0.2s ease;
}

.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--border-focus);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Toaster Notifications */
.toaster-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 320px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 500;
}

.toast-icon {
  font-size: 18px;
}

.toast-undo {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-blue);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.toast-undo:hover {
  background: rgba(0, 113, 227, 0.1);
}

/* Command Palette (Cmd + K) */
.cmd-k-palette {
  max-width: 580px;
}

.cmd-search-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 17px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  outline: none;
}

.cmd-results {
  max-height: 280px;
  overflow-y: auto;
  padding: 10px;
}

.cmd-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 14px;
}

.cmd-item:hover, .cmd-item.selected {
  background: var(--bg-surface-secondary);
}

/* Responsive */
@media (max-width: 768px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .header-nav {
    padding: 12px 16px;
  }
  .asset-table th:nth-child(4),
  .asset-table td:nth-child(4),
  .asset-table th:nth-child(5),
  .asset-table td:nth-child(5) {
    display: none;
  }
}
