/* ============================================
   Apollo's Table — Dashboard Styles
   Dark + Gold trading terminal aesthetic
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #16161f;
  --bg-card-hover: #1c1c28;
  --bg-input: #1a1a25;
  --border: #2a2a3a;
  --border-subtle: #1e1e2e;
  --gold: #d4a44c;
  --gold-dim: #b8913f;
  --gold-glow: rgba(212, 164, 76, 0.15);
  --gold-bright: #e8bc5e;
  --green: #3ecf6e;
  --green-dim: #2a9e50;
  --green-glow: rgba(62, 207, 110, 0.15);
  --red: #e05252;
  --red-dim: #b33a3a;
  --amber: #d4a44c;
  --text-primary: #e8e6e1;
  --text-secondary: #8a8894;
  --text-muted: #5a5868;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--gold-bright);
}

img {
  max-width: 100%;
  display: block;
}

/* ---------- Password Gate Overlay ---------- */
.password-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2rem;
  opacity: 1;
  transition: opacity 400ms ease;
}

.password-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.password-overlay.hidden {
  display: none;
}

.gate-brand {
  text-align: center;
}

.gate-brand h1 {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

.gate-brand p {
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.gate-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.gate-form input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-sans);
  width: 220px;
  outline: none;
  transition: border-color var(--transition);
}

.gate-form input:focus {
  border-color: var(--gold);
}

.gate-form input::placeholder {
  color: var(--text-muted);
}

.gate-form button {
  background: var(--gold);
  color: var(--bg-primary);
  border: none;
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.gate-form button:hover {
  background: var(--gold-bright);
}

.gate-error {
  color: var(--red);
  font-size: 0.85rem;
  height: 1.2em;
  text-align: center;
}

/* ---------- App Shell ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Navigation ---------- */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  display: block;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
}

.nav-links a:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-links a.active {
  color: var(--gold);
  background: var(--gold-glow);
}

.nav-settings {
  display: flex;
  align-items: center;
}

.nav-settings button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  font-size: 1.1rem;
  line-height: 1;
}

.nav-settings button:hover {
  color: var(--text-secondary);
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  padding: 1.25rem 1.5rem 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Stats Bar ---------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.stat-card .stat-value.gold {
  color: var(--gold);
}

.stat-card .stat-value.green {
  color: var(--green);
}

/* ---------- Filter Bar ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.filter-group select,
.filter-group input[type="range"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  outline: none;
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--gold);
}

.filter-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--border);
  border: none;
  border-radius: 2px;
  padding: 0;
  cursor: pointer;
}

.filter-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
}

.filter-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  border: none;
  cursor: pointer;
}

.filter-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--gold);
  min-width: 50px;
}

.filter-spacer {
  flex: 1;
}

.filter-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Deals Grid ---------- */
.deals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
}

.deal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
  cursor: default;
}

.deal-card:hover {
  border-color: var(--border);
  transform: translateY(-1px);
}

.deal-card.grade-a {
  border-left: 3px solid var(--green);
}

.deal-card.grade-b {
  border-left: 3px solid var(--gold);
}

.deal-card.grade-c {
  border-left: 3px solid var(--text-muted);
}

.deal-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--bg-secondary);
}

.deal-image-placeholder {
  width: 100%;
  height: 180px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.deal-body {
  padding: 0.85rem 1rem;
}

.deal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.deal-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.deal-grade {
  flex-shrink: 0;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.deal-grade.grade-a {
  background: var(--green-glow);
  color: var(--green);
  box-shadow: 0 0 8px rgba(62, 207, 110, 0.1);
}

.deal-grade.grade-b {
  background: var(--gold-glow);
  color: var(--gold);
  box-shadow: 0 0 8px rgba(212, 164, 76, 0.1);
}

.deal-grade.grade-c {
  background: rgba(90, 88, 104, 0.15);
  color: var(--text-muted);
}

.deal-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 1rem;
  margin-bottom: 0.6rem;
}

.deal-metric {
  display: flex;
  flex-direction: column;
}

.deal-metric .metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.deal-metric .metric-value {
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.deal-metric .metric-value.profit {
  color: var(--green);
}

.deal-metric .metric-value.price {
  color: var(--text-primary);
}

.deal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.deal-location {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.deal-time {
  font-style: italic;
}

.deal-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--gold-dim);
  transition: color var(--transition);
}

.deal-link:hover {
  color: var(--gold-bright);
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 400px;
  margin: 0 auto;
}

.empty-state code {
  display: inline-block;
  margin-top: 0.75rem;
  background: var(--bg-input);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--gold);
  border: 1px solid var(--border);
}

/* ---------- Inventory / Kanban ---------- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.kanban-column {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  min-height: 300px;
}

.kanban-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.kanban-count {
  background: var(--bg-input);
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.kanban-items {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kanban-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
}

.kanban-item .item-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.kanban-item .item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.kanban-item .item-price {
  font-family: var(--font-mono);
  color: var(--green);
  font-weight: 600;
}

.kanban-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ---------- Profit Page ---------- */
.metric-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.metric-card .mc-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
}

.metric-card .mc-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.metric-card .mc-value.positive {
  color: var(--green);
}

.metric-card .mc-value.gold {
  color: var(--gold);
}

.metric-card .mc-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Time toggle */
.time-toggle {
  display: inline-flex;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.time-toggle button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.time-toggle button:hover {
  color: var(--text-secondary);
}

.time-toggle button.active {
  background: var(--gold-glow);
  color: var(--gold);
}

/* Profit Table */
.profit-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.profit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.profit-table th {
  background: var(--bg-card);
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.profit-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

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

.profit-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.profit-table .mono {
  font-family: var(--font-mono);
}

.profit-table .positive {
  color: var(--green);
}

.profit-table .negative {
  color: var(--red);
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.sold {
  background: var(--green-glow);
  color: var(--green);
}

.status-badge.listed {
  background: var(--gold-glow);
  color: var(--gold);
}

.status-badge.targeted {
  background: rgba(90, 88, 104, 0.15);
  color: var(--text-muted);
}

.status-badge.picked-up {
  background: rgba(100, 149, 237, 0.15);
  color: #6495ed;
}

.status-badge.photographed {
  background: rgba(186, 130, 237, 0.15);
  color: #ba82ed;
}

/* ---------- Page Header ---------- */
.page-header {
  margin-bottom: 1.25rem;
}

.page-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.page-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ---------- Settings Panel ---------- */
.settings-panel {
  position: fixed;
  top: 56px;
  right: 0;
  width: 320px;
  height: calc(100vh - 56px);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  padding: 1.5rem;
  transform: translateX(100%);
  transition: transform 250ms ease;
  z-index: 99;
  overflow-y: auto;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-panel h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.settings-group {
  margin-bottom: 1.25rem;
}

.settings-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.settings-group input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
}

.settings-group input:focus {
  border-color: var(--gold);
}

.settings-group .btn-save {
  margin-top: 0.5rem;
  background: var(--gold);
  color: var(--bg-primary);
  border: none;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.settings-group .btn-save:hover {
  background: var(--gold-bright);
}

.btn-logout {
  background: none;
  border: 1px solid var(--red-dim);
  color: var(--red);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition);
  width: 100%;
}

.btn-logout:hover {
  background: rgba(224, 82, 82, 0.1);
}

/* ---------- Refresh info ---------- */
.refresh-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 0.75rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  .top-nav {
    padding: 0 1rem;
  }

  .nav-brand {
    font-size: 1rem;
  }

  .nav-links a {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
  }

  .main-content {
    padding: 1rem;
  }

  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .deals-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    justify-content: space-between;
  }

  .filter-spacer {
    display: none;
  }

  .kanban-board {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    width: 100%;
  }

  .deal-image,
  .deal-image-placeholder {
    height: 140px;
  }

  .metric-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .stats-bar {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .stat-card .stat-value {
    font-size: 1.2rem;
  }

  .gate-brand h1 {
    font-size: 1.8rem;
  }

  .gate-form {
    flex-direction: column;
    width: 100%;
    padding: 0 2rem;
  }

  .gate-form input {
    width: 100%;
  }

  .gate-form button {
    width: 100%;
  }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------- Utility ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.text-gold { color: var(--gold); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
