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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --text: #e2e8f0;
  --text-muted: #718096;
  --accent: #f6c90e;
  --accent-dark: #d4a900;
  --green: #48bb78;
  --red: #fc8181;
  --blue: #63b3ed;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

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

.nav-brand a {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-links a { color: var(--text); font-size: 0.9rem; }
.nav-links a:hover { color: var(--accent); text-decoration: none; }
.nav-user { color: var(--text-muted); font-size: 0.85rem; }

/* Main */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 1.25rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 2rem 0 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.8rem; }

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.card-link { text-decoration: none; display: block; }

.browse-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.15s, transform 0.15s;
}

.browse-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.browse-card h3 { font-size: 1rem; margin-bottom: 0.4rem; color: var(--text); }
.browse-card p { font-size: 0.8rem; color: var(--text-muted); margin: 0.1rem 0; }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  background: var(--surface2);
  padding: 0.6rem 0.75rem;
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.sortable-col:hover { color: var(--text); background: var(--surface); cursor: pointer; }
.sortable-col.sort-active { color: var(--accent); }
.sort-icon { font-size: 0.7rem; opacity: 0.6; }
.data-table td a { color: var(--text); }
.data-table td a:hover { color: var(--accent); }

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 0.75rem; }

.price-cell { font-weight: 600; color: var(--green); }

.card-thumb {
  width: 32px;
  height: 44px;
  object-fit: cover;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 0.5rem;
}

/* Product page */
.product-header {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  align-items: flex-start;
}

.product-image {
  width: 200px;
  border-radius: var(--radius);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

.price-summary {
  display: flex;
  gap: 1.5rem;
  margin: 1rem 0;
}

.price-item { text-align: center; }
.price-label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.price-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--accent); }

/* Chart */
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1rem 0 2rem;
  position: relative;
  height: 320px;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }

/* Search */
.search-form { margin-bottom: 1.5rem; }
.search-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }
.search-select { min-width: 140px; }
.result-count { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1rem; }

.list-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.list-controls .search-input { max-width: 320px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-full { width: 100%; text-align: center; }
.btn-link { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.875rem; padding: 0; }
.btn-link:hover { color: var(--red); }
.btn-danger-sm { background: transparent; border: 1px solid var(--red); color: var(--red); padding: 0.2rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.75rem; }
.btn-danger-sm:hover { background: var(--red); color: #fff; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
input[type=text], input[type=email], input[type=password], select, .search-input, .search-select, .form-input-inline {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.form-input-inline { width: auto; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }

/* Auth */
body.auth-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo { font-size: 2rem; text-align: center; margin-bottom: 0.5rem; }
.auth-card h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.auth-note { text-align: center; color: var(--text-muted); font-size: 0.75rem; margin-top: 1.5rem; }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-error { background: rgba(252,129,129,0.15); border: 1px solid var(--red); color: var(--red); }
.alert-success { background: rgba(72,187,120,0.15); border: 1px solid var(--green); color: var(--green); }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-admin { background: rgba(246,201,14,0.15); color: var(--accent); border-color: var(--accent); }
.badge-user { background: var(--surface2); color: var(--text-muted); }
.badge-success { background: rgba(72,187,120,0.15); color: var(--green); border-color: var(--green); }
.badge-error { background: rgba(252,129,129,0.15); color: var(--red); border-color: var(--red); }
.badge-running { background: rgba(99,179,237,0.15); color: var(--blue); border-color: var(--blue); }

/* Admin */
.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-section h2 { margin-top: 0; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { margin: 0; }

.invite-link { font-size: 0.75rem; color: var(--blue); word-break: break-all; }

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

/* Last updated */
.last-updated { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.5rem; }

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.footer a { color: var(--text-muted); }

/* Error page */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  gap: 1rem;
  padding: 2rem;
}

code { background: var(--surface2); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.8rem; }

@media (max-width: 600px) {
  .product-header { flex-direction: column; }
  .product-image { width: 140px; }
  .price-summary { flex-wrap: wrap; }
  .navbar { padding: 0 1rem; }
  .container { padding: 1rem; }
}

/* Collections */
.group-layout { display: flex; gap: 1rem; align-items: flex-start; }
.group-table-wrap { flex: 1; min-width: 0; }

.collections-sidebar {
  width: 240px;
  flex-shrink: 0;
  order: -1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.sidebar-hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; }

.collection-drop-zone {
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}
.collection-drop-zone.drag-over {
  border-color: var(--green);
  background: rgba(72,187,120,0.1);
  color: var(--green);
}

.collection-badge {
  display: inline-block;
  background: var(--accent);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  cursor: pointer;
}
.collection-badge:hover { opacity: 0.8; }

.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  font-size: 1rem;
  padding: 0 0.25rem;
  user-select: none;
}
tr.dragging { opacity: 0.5; }

/* Quantity popover */
.qty-popover {
  position: absolute;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-width: 240px;
  box-shadow: var(--shadow);
}
.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.popover-title { font-weight: 600; font-size: 0.85rem; }
.popover-qty-row, .popover-add-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}
.popover-qty-row:last-child, .popover-add-row:last-child { border-bottom: none; }
.popover-col-name { font-size: 0.85rem; flex: 1; }

/* Inline qty editor (popover + product page) */
.qty-editor-inline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.qty-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.qty-btn:hover { border-color: var(--accent); color: var(--accent); }
.qty-display { min-width: 24px; text-align: center; font-size: 0.875rem; font-weight: 600; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.page-info { color: var(--text-muted); font-size: 0.85rem; }
