/* ============================================================
   Stilly — Craft Distillery Management
   Design System
   ============================================================ */

:root {
  --amber:       #C9A84C;
  --amber-light: #E8C97D;
  --amber-dark:  #A07830;
  --copper:      #B87333;

  --bg-base:     #0E0E1A;
  --bg-surface:  #16162A;
  --bg-raised:   #1E1E36;
  --bg-overlay:  #252540;

  --border:      rgba(255,255,255,0.08);
  --border-med:  rgba(255,255,255,0.14);

  --text-primary:   #F0EDE8;
  --text-secondary: #9B98B0;
  --text-muted:     #6B6880;

  --green:  #2ECC71;
  --red:    #E74C3C;
  --blue:   #3498DB;
  --orange: #E67E22;

  --sidebar-w: 240px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow:    0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);

  --transition: 0.18s ease;
}

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

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

/* ── AUTH ───────────────────────────────────────────────────── */

.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, rgba(201,168,76,0.12) 0%, transparent 60%), var(--bg-base);
}

.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-logo { margin-bottom: 12px; }
.auth-title {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--amber);
  letter-spacing: 0.02em;
}
.auth-subtitle { color: var(--text-secondary); font-size: 0.875rem; margin-top: 4px; }

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.auth-card h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.auth-switch { margin-top: 20px; text-align: center; color: var(--text-secondary); font-size: 0.875rem; }
.auth-switch a { color: var(--amber); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ── LAYOUT ─────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .user-info,
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--amber);
  white-space: nowrap;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-raised); }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section { margin-bottom: 4px; }

.nav-section-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 450;
  border-radius: 0;
  transition: color var(--transition), background var(--transition);
  position: relative;
}
.nav-item:hover { color: var(--text-primary); background: var(--bg-raised); }
.nav-item.active {
  color: var(--amber);
  background: rgba(201,168,76,0.1);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--amber);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.user-pill { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--amber-dark), var(--amber));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--bg-base);
  flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { display: block; font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; }

/* ── MAIN CONTENT ───────────────────────────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-base);
}

/* ── VIEW ───────────────────────────────────────────────────── */

.view {
  padding: 28px 32px;
  max-width: 1400px;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.view-title { font-size: 1.5rem; font-weight: 700; }
.view-subtitle { color: var(--text-secondary); font-size: 0.875rem; margin-top: 2px; }

.view-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

/* ── KPI GRID ───────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}
.kpi-card:hover { border-color: var(--border-med); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--kpi-color, var(--amber));
}

.kpi-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.kpi-value { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.kpi-sub { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; }

/* ── CARDS / TABLES ─────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 0.9rem; font-weight: 600; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

/* ── GRID LAYOUTS ───────────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ── BADGES ─────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-green   { background: rgba(46,204,113,0.15);  color: #2ECC71; }
.badge-amber   { background: rgba(201,168,76,0.15);  color: var(--amber); }
.badge-red     { background: rgba(231,76,60,0.15);   color: #E74C3C; }
.badge-blue    { background: rgba(52,152,219,0.15);  color: #3498DB; }
.badge-gray    { background: rgba(155,152,176,0.15); color: var(--text-secondary); }
.badge-orange  { background: rgba(230,126,34,0.15);  color: #E67E22; }

/* ── BUTTONS ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--amber);
  color: #0E0E1A;
  border-color: var(--amber);
}
.btn-primary:hover { background: var(--amber-light); border-color: var(--amber-light); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--border-med); background: var(--bg-overlay); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-raised); }

.btn-danger { background: rgba(231,76,60,0.15); color: #E74C3C; border-color: rgba(231,76,60,0.3); }
.btn-danger:hover { background: rgba(231,76,60,0.25); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-raised); }

/* ── FORMS ──────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.label-optional { color: var(--text-muted); font-weight: 400; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=datetime-local],
select, textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 9px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.12);
}
input::placeholder { color: var(--text-muted); }

select option { background: var(--bg-raised); }

textarea { resize: vertical; min-height: 80px; }

/* ── ALERTS ─────────────────────────────────────────────────── */

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.alert-error  { background: rgba(231,76,60,0.12); border: 1px solid rgba(231,76,60,0.3); color: #E74C3C; }
.alert-success{ background: rgba(46,204,113,0.12); border: 1px solid rgba(46,204,113,0.3); color: #2ECC71; }
.alert-info   { background: rgba(52,152,219,0.12); border: 1px solid rgba(52,152,219,0.3); color: #3498DB; }
.alert-warn   { background: rgba(230,126,34,0.12); border: 1px solid rgba(230,126,34,0.3); color: #E67E22; }

/* ── MODAL ──────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ── TOAST ──────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-overlay);
  border: 1px solid var(--border-med);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  min-width: 240px;
  max-width: 360px;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── LOADING ────────────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
  flex-direction: column;
  gap: 12px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state svg { opacity: 0.3; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 0.875rem; }

/* ── PROGRESS BAR ───────────────────────────────────────────── */

.progress-bar {
  height: 6px;
  background: var(--bg-overlay);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--amber);
  border-radius: 99px;
  transition: width 0.6s ease;
}
.progress-fill.green  { background: var(--green); }
.progress-fill.red    { background: var(--red); }

/* ── STATS BLOCK ────────────────────────────────────────────── */

.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-secondary); font-size: 0.85rem; }
.stat-value { font-weight: 600; font-size: 0.95rem; }

/* ── REMISSION GAUGE ────────────────────────────────────────── */

.remission-gauge {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.gauge-header { display: flex; justify-content: space-between; margin-bottom: 12px; }
.gauge-label { font-size: 0.8rem; color: var(--text-secondary); }
.gauge-value { font-weight: 700; color: var(--amber); }

/* ── FILTER BAR ─────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar input, .filter-bar select { max-width: 200px; margin: 0; }
.filter-bar label { display: none; }

/* ── DETAIL PANEL ───────────────────────────────────────────── */

.detail-section { margin-bottom: 24px; }
.detail-section h4 { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 12px; }

/* ── DASHBOARD SPECIFIC ─────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ── BARREL CARD ────────────────────────────────────────────── */

.barrel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.barrel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.barrel-card:hover { border-color: var(--amber); box-shadow: 0 0 0 1px rgba(201,168,76,0.2); }
.barrel-card.status-filled { border-top: 2px solid var(--amber); }
.barrel-card.status-empty  { border-top: 2px solid var(--bg-overlay); }
.barrel-card.status-retired { opacity: 0.5; }

.barrel-number { font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; }
.barrel-spirit { font-size: 0.75rem; color: var(--text-muted); text-transform: capitalize; margin-bottom: 10px; }
.barrel-stats  { display: flex; justify-content: space-between; }
.barrel-stat   { text-align: center; }
.barrel-stat-val { font-size: 1rem; font-weight: 600; display: block; }
.barrel-stat-key { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }

/* ── RESPONSIVE ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { position: fixed; z-index: 100; width: 240px; transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar.mobile-open { transform: translateX(0); }
  .view { padding: 20px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── COLOUR HELPERS ─────────────────────────────────────────── */
.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.fw-600 { font-weight: 600; }
.fs-sm  { font-size: 0.8rem; }

/* ── RICKHOUSE MAP ──────────────────────────────────────────── */

.rickhouse-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.rack-cell {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition);
}
.rack-cell:hover { border-color: var(--amber); }
.rack-cell.full  { background: rgba(201,168,76,0.1); border-color: rgba(201,168,76,0.3); }
.rack-cell .rack-id { font-weight: 700; font-size: 0.85rem; margin-bottom: 4px; }
.rack-cell .rack-count { font-size: 0.7rem; color: var(--text-muted); }

/* ── CHART PLACEHOLDER ──────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 200px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 0 4px;
}
.chart-bar {
  flex: 1;
  background: linear-gradient(to top, var(--amber-dark), var(--amber));
  border-radius: 4px 4px 0 0;
  min-width: 20px;
  transition: height 0.5s ease;
  position: relative;
  cursor: pointer;
}
.chart-bar:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  margin-bottom: 4px;
}
.chart-labels {
  display: flex;
  gap: 6px;
  padding: 0 4px;
  margin-top: 4px;
}
.chart-label { flex: 1; text-align: center; font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── DISTILLATION CUTS ──────────────────────────────────────── */
.cuts-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.cut-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.cut-label { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 6px; }
.cut-value { font-size: 1.1rem; font-weight: 700; }
.cut-abv   { font-size: 0.75rem; color: var(--amber); margin-top: 2px; }

.cut-card.cut-hearts { border-color: rgba(46,204,113,0.4); background: rgba(46,204,113,0.05); }
.cut-card.cut-heads  { border-color: rgba(231,76,60,0.3); }
.cut-card.cut-tails  { border-color: rgba(230,126,34,0.3); }
