/* =========================================================================
   Flour Trace Pro — Design System & Styles
   ========================================================================= */

/* ---- CSS Variables / Tokens ---- */

:root {
  /* Base palette — deep navy + warm amber accent */
  --bg-body: #0b0f1a;
  --bg-sidebar: #0f1423;
  --bg-card: #141929;
  --bg-card-hover: #1a2035;
  --bg-input: #1a2035;
  --bg-table-row: #161c2e;
  --bg-table-hover: #1e2640;
  --border: #252d45;
  --border-light: #313a57;

  /* Text */
  --text-primary: #e8ecf4;
  --text-secondary: #8892a8;
  --text-tertiary: #5e6783;
  --text-inverse: #0b0f1a;

  /* Accent */
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent-soft: rgba(245, 158, 11, 0.12);
  --accent-glow: rgba(245, 158, 11, 0.25);

  /* Status colors */
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.12);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.12);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.12);
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.12);

  /* Silo colors */
  --silo1: #3b82f6;
  --silo2: #22c55e;
  --silo3: #a78bfa;
  --silo4: #f59e0b;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition: 0.2s var(--ease-out);

  /* Layout */
  --sidebar-width: 240px;
}

/* ---- Light Theme Override ---- */

[data-theme='light'] {
  --bg-body: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fb;
  --bg-input: #f4f5f7;
  --bg-table-row: #f8f9fb;
  --bg-table-hover: #eef0f4;
  --border: #dde1e8;
  --border-light: #c8cdd6;

  --text-primary: #1a1d26;
  --text-secondary: #5a6277;
  --text-tertiary: #8892a8;
  --text-inverse: #ffffff;

  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-soft: rgba(217, 119, 6, 0.1);
  --accent-glow: rgba(217, 119, 6, 0.18);

  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.1);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, 0.1);
  --purple: #7c3aed;
  --purple-soft: rgba(124, 58, 237, 0.1);
  --cyan: #0891b2;
  --cyan-soft: rgba(8, 145, 178, 0.1);

  --silo1: #2563eb;
  --silo2: #16a34a;
  --silo3: #7c3aed;
  --silo4: #d97706;
}

[data-theme='light'] .silo-info-type.type-white {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

[data-theme='light'] .silo-info-type.type-wholemeal {
  background: rgba(180, 130, 70, 0.12);
  color: #92650a;
}

[data-theme='light'] .silo-info-type.type-unknown {
  background: rgba(90, 98, 119, 0.1);
  color: #5a6277;
}

/* ---- Reset ---- */

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

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

body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 {
  font-size: var(--text-2xl);
}

h2 {
  font-size: var(--text-lg);
}

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

/* ---- Scrollbar ---- */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* =========================================================================
   Sidebar
   ========================================================================= */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: var(--space-lg) var(--space-lg) var(--space-md);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent) 0%, #d97706 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.logo-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-primary);
}

.logo-subtitle {
  font-size: var(--text-xs);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.15em;
}

/* Sidebar Nav */

.sidebar-nav {
  flex: 1;
  padding: var(--space-sm) var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  width: 100%;
  text-align: left;
}

.nav-btn svg {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity var(--transition);
}

.nav-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-btn:hover svg {
  opacity: 1;
}

.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-btn.active svg {
  opacity: 1;
  color: var(--accent);
}

.sidebar-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
}

.sidebar-footer-text {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* =========================================================================
   Main Content
   ========================================================================= */

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-xl) var(--space-2xl);
}

/* Page sections */

.page {
  display: none;
  animation: fadeIn 0.35s var(--ease-out);
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-top: var(--space-xs);
}

/* =========================================================================
   Cards
   ========================================================================= */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: border-color var(--transition);
}

.card:hover {
  border-color: var(--border-light);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

/* =========================================================================
   Silo Vessel Grid (Dashboard)
   ========================================================================= */

.silo-grid {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--space-2xl);
  padding: var(--space-xl) var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 380px;
}

/* Each silo column: vessel + info below */
.silo-vessel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  transition: transform 0.3s var(--ease-out);
}

.silo-vessel:hover {
  transform: translateY(-4px);
}

/* The SVG silo drawing */
.silo-vessel svg {
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
  transition: filter 0.3s var(--ease-out);
}

.silo-vessel:hover svg {
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.5));
}

/* Fill animation */
.silo-fill-rect {
  transition: y 0.8s var(--ease-out), height 0.8s var(--ease-out);
}

/* Info block below each silo */
.silo-info {
  text-align: center;
  min-width: 120px;
}

.silo-info-name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.silo-info-weight {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.silo-info-weight .unit {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}

.silo-info-type {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}

.silo-info-type.type-white {
  background: rgba(74, 143, 226, 0.15);
  color: #6aafff;
}

.silo-info-type.type-wholemeal {
  background: rgba(196, 154, 108, 0.15);
  color: #d4b48a;
}

.silo-info-type.type-unknown {
  background: rgba(136, 146, 168, 0.12);
  color: var(--text-tertiary);
}

.silo-info-type::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.silo-info-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* =========================================================================
   Tables
   ========================================================================= */

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table thead th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background var(--transition);
}

.data-table tbody tr:hover td {
  background: var(--bg-table-hover);
  color: var(--text-primary);
}

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

/* =========================================================================
   Status Badges
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-active {
  background: var(--green-soft);
  color: var(--green);
}

.badge-empty {
  background: var(--red-soft);
  color: var(--red);
}

.badge-white {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge-wholemeal {
  background: var(--purple-soft);
  color: var(--purple);
}

.badge-pending {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: var(--text-inverse);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--accent);
}

/* =========================================================================
   Forms
   ========================================================================= */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-md);
}

.form-row {
  display: flex;
  gap: var(--space-md);
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-group label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input::placeholder {
  color: var(--text-tertiary);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding-top: var(--space-sm);
}

.form-feedback {
  font-size: var(--text-sm);
  font-weight: 500;
}

.form-feedback.success {
  color: var(--green);
}

.form-feedback.error {
  color: var(--red);
}

/* =========================================================================
   Report Tabs
   ========================================================================= */

.report-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: var(--space-lg);
  width: fit-content;
}

.report-tab {
  padding: var(--space-sm) var(--space-lg);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.report-tab:hover {
  color: var(--text-primary);
}

.report-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.report-panel {
  display: none;
  animation: fadeIn 0.25s var(--ease-out);
}

.report-panel.active {
  display: block;
}

/* =========================================================================
   Utilities
   ========================================================================= */

.mt-sm {
  margin-top: var(--space-sm);
}

.mt-md {
  margin-top: var(--space-md);
}

.mt-lg {
  margin-top: var(--space-lg);
}

.mt-xl {
  margin-top: var(--space-xl);
}

.text-mono {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: var(--text-xs);
}

.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-tertiary);
}

.empty-state svg {
  margin-bottom: var(--space-md);
  opacity: 0.3;
}

.empty-state p {
  font-size: var(--text-sm);
}

/* Loading spinner */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================================
   Live Session Panel
   ========================================================================= */

.session-summary {
  padding: var(--space-lg);
}

.session-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.session-meta-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.session-value {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.session-progress {
  height: 10px;
  background: var(--bg-input);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 6px;
}

.session-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.5s var(--ease-out);
}

.session-progress-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-align: right;
}

.session-allocs {
  margin-top: var(--space-lg);
}

.session-alloc-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.session-alloc-row:last-child {
  border-bottom: none;
}

.session-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  flex-wrap: wrap;
}

/* ---- Allocation Breakdown (Deliveries Table) ---- */

.alloc-breakdown {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alloc-chip {
  font-size: var(--text-sm);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  white-space: nowrap;
  line-height: 1.5;
}

.alloc-chip strong {
  color: var(--accent);
}

/* =========================================================================
   Settings Grid
   ========================================================================= */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-lg);
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  transition: border-color var(--transition);
}

.settings-card:hover {
  border-color: var(--border-light);
}

.settings-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.settings-card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.settings-card .form-group {
  margin-bottom: var(--space-md);
}

.settings-card .btn-save {
  width: 100%;
  justify-content: center;
  margin-top: var(--space-sm);
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1100px) {
  .silo-grid {
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: var(--space-lg) var(--space-md);
  }

  .silo-grid {
    flex-wrap: wrap;
    gap: var(--space-lg);
  }

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

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---- Login Overlay ---- */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.login-logo {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-logo .logo-icon {
  margin: 0 auto var(--space-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 var(--space-xs);
}

.login-logo p {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin: 0;
}

.login-card .form-group {
  margin-bottom: var(--space-md);
}

.login-card .form-feedback {
  margin-top: var(--space-md);
  text-align: center;
}

/* ---- Sidebar User Info ---- */

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-xs);
  margin-bottom: var(--space-sm);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sidebar-user-name {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
}

/* ---- Role Badges ---- */

.badge-admin {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.badge-superuser {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
}

.badge-user {
  background: rgba(107, 114, 128, 0.12);
  color: #9ca3af;
}