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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Nav */
nav#nav {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}
nav#nav a {
  display: block;
  padding: 1rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
nav#nav a:hover { color: var(--text); }
nav#nav a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; }
h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer;
  font-size: 0.875rem; font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); }

/* Products grid */
.products-grid { display: flex; flex-direction: column; gap: 1rem; }
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.product-card.inactive { opacity: 0.6; }
.product-img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.product-img-placeholder { width: 64px; height: 64px; background: var(--border); border-radius: 6px; flex-shrink: 0; }
.product-info { flex: 1; min-width: 0; }
.product-name { font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; }
.product-meta { font-size: 0.8rem; color: var(--text-muted); }
.product-price { font-size: 0.9rem; color: var(--success); margin-top: 0.2rem; }
.product-stats { display: flex; gap: 1rem; margin-top: 0.4rem; font-size: 0.8rem; color: var(--text-muted); }
.product-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Schedule */
.mode-toggle { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.autopilot-status { padding: 0.75rem 1rem; border-radius: var(--radius); background: rgba(99,102,241,0.1); border: 1px solid rgba(99,102,241,0.2); margin-top: 1rem; }
.status-ok { color: var(--success); }
.status-warn { color: var(--warning); }
.add-time-row { display: flex; gap: 0.75rem; margin-bottom: 1rem; align-items: center; }
.time-input {
  padding: 0.5rem 0.75rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem;
}
.schedules-list { display: flex; flex-direction: column; gap: 0.5rem; }
.schedule-row { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; background: var(--bg); border-radius: 6px; }
.schedule-time { font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.computed-hours { margin-top: 1rem; color: var(--text-muted); font-size: 0.9rem; }

/* Range bar */
.tab-bar {
  display: flex; gap: 0.5rem; margin-bottom: 1.5rem;
}
.range-bar {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.custom-range { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.chart-card canvas { cursor: pointer; }

/* Analytics */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 700px) { .charts-row { grid-template-columns: 1fr; } }
.best-tag { font-size: 0.75rem; font-weight: 500; color: var(--success); margin-left: 0.75rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; padding: 0.5rem 0.75rem; color: var(--text-muted); border-bottom: 1px solid var(--border); font-size: 0.8rem; text-transform: uppercase; }
.data-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 0.5rem 0.75rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 2rem; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-box h2 { margin-bottom: 1.5rem; font-size: 1.25rem; color: var(--text); }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 200;
  padding: 0.75rem 1.25rem; border-radius: var(--radius);
  font-size: 0.9rem; animation: slide-in 0.2s ease;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Empty state */
.empty-state { color: var(--text-muted); text-align: center; padding: 2rem; }
.hidden { display: none !important; }

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Nav: scrollable row */
  nav#nav {
    padding: 0 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav#nav::-webkit-scrollbar { display: none; }
  nav#nav a { padding: 0.85rem 0.85rem; font-size: 0.82rem; white-space: nowrap; }

  /* Container */
  .container { padding: 1rem 0.75rem; }

  /* Page header: stack on very small */
  .page-header { flex-wrap: wrap; gap: 0.5rem; }

  /* Cards */
  .card { padding: 1rem; }

  /* Product cards: wrap actions below */
  .product-card { flex-wrap: wrap; }
  .product-actions { width: 100%; justify-content: flex-end; margin-top: 0.5rem; flex-wrap: wrap; }

  /* Form rows: single column */
  .form-row { grid-template-columns: 1fr; }

  /* Modal: full width */
  .modal-box { margin: 0.75rem; max-width: calc(100% - 1.5rem); padding: 1.25rem; }

  /* Stats grid: 2 columns on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Mode toggle: wrap */
  .mode-toggle { flex-wrap: wrap; }

  /* Add time row: stack */
  .add-time-row { flex-wrap: wrap; }
  .add-time-row .time-input { flex: 1; }

  /* Analytics table: scrollable */
  .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Toast: full width bottom */
  .toast { left: 0.75rem; right: 0.75rem; bottom: 0.75rem; text-align: center; }
}

/* Actions nav badge */
.nav-badge { display: inline-block; min-width: 1.2rem; padding: 0 0.35rem; margin-left: 0.4rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 1.2rem; text-align: center; }

/* ── Nav user / logout ─────────────────────────────────────── */
nav#nav .nav-user { margin-left: auto; align-self: center; font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
nav#nav .nav-user a { margin-left: 8px; padding: 0; border: none; }

/* ── Forms (login / users) ─────────────────────────────────── */
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-muted); }
.form-row input, .form-row select, td select {
  padding: 0.5rem 0.75rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--primary); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
table.data th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-off { color: var(--danger); }
