:root {
  --bg: #2a2a2c;
  --surface: #333333;
  --surface-2: #414042;
  --border: #4f4f52;
  --text: #f9f9f9;
  --text-muted: #a8a9ad;
  --primary: #c5b358;
  --primary-hover: #d4c76a;
  --primary-text: #2a2a2c;
  --danger: #e85d5d;
  --warning: #e6a23c;
  --info: #7eb8da;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --sidebar-w: 260px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.brand-icon { font-size: 1.75rem; }

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary-hover), var(--primary));
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(197, 179, 88, 0.35);
}

.brand-logo {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.brand-logo-wide {
  width: 100%;
  max-width: 220px;
  height: auto;
  aspect-ratio: 1024 / 558;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: none;
  display: block;
}

.sidebar-brand .brand-logo-wide {
  max-width: 100%;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.925rem;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(197, 179, 88, 0.18); color: var(--primary-hover); font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 1rem; }

.main {
  padding: 1.5rem 2rem;
  overflow-x: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.topbar h1 { margin: 0; font-size: 1.75rem; }
.page-subtitle { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.9rem; }

.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.view { display: none; }
.view.active { display: block; }

.setup-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.setup-banner p { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.875rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-card .label { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.stat-card.warning .value { color: var(--warning); }
.stat-card.success .value { color: var(--primary); }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

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

.panel-header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.panel-body { padding: 0; }

.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}

.toolbar input,
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  min-width: 180px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}

tr:hover td { background: rgba(255, 255, 255, 0.02); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: rgba(197, 179, 88, 0.22); color: var(--primary-hover); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.badge-info { background: rgba(59, 130, 246, 0.2); color: var(--info); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.25); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

.actions { display: flex; gap: 0.35rem; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

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

.modal-header h2 { margin: 0; font-size: 1.15rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body { padding: 1.25rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.order-items-list { margin-top: 0.5rem; }

.order-item-row {
  display: grid;
  grid-template-columns: 1fr 80px 36px;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 240px;
  box-shadow: var(--shadow);
  animation: slideIn 0.25s ease;
}

.toast.success { border-color: rgba(197, 179, 88, 0.55); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.stock-low { color: var(--warning); font-weight: 600; }
.stock-out { color: var(--danger); font-weight: 600; }

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }
  .sidebar-footer { width: 100%; }
  .main { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 20% 10%, rgba(197, 179, 88, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(65, 64, 66, 0.5) 0%, transparent 40%),
    var(--bg);
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(320px, 400px);
  width: 100%;
  max-width: 920px;
  min-height: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.login-visual {
  position: relative;
  min-height: 100%;
  background: var(--surface-2);
}

.login-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.login-visual-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 1.75rem;
  background: linear-gradient(to top, rgba(42, 42, 44, 0.92) 0%, rgba(42, 42, 44, 0.15) 55%, transparent 100%);
}

.login-visual-tagline {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  max-width: 18rem;
  line-height: 1.35;
}

.login-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem;
}

.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand .brand-logo-wide {
  max-width: min(100%, 260px);
  margin: 0 auto 0.75rem;
  border-radius: 10px;
}
.login-brand p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* Dashboard hero */
.dashboard-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.25rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, rgba(197, 179, 88, 0.12), rgba(65, 64, 66, 0.35));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
}

.dashboard-hero-copy h2 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.dashboard-hero-copy p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.dashboard-hero-photos {
  display: flex;
  gap: 0.75rem;
}

.dashboard-hero-photos img {
  width: 140px;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
  .login-shell {
    grid-template-columns: 1fr;
    max-width: 400px;
    min-height: auto;
  }

  .login-visual {
    min-height: 180px;
    max-height: 220px;
  }

  .dashboard-hero {
    grid-template-columns: 1fr;
  }

  .dashboard-hero-photos img {
    width: calc(50% - 0.375rem);
    height: 72px;
  }

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

/* Product & category cards */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.item-card:hover {
  transform: translateY(-2px);
  border-color: rgba(197, 179, 88, 0.45);
}

.item-card-image {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}

.item-card-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.item-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.item-card-head h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.item-card-sku {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.item-card-meta,
.item-card-supplier,
.item-card-desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.item-card-desc {
  flex: 1;
}

.item-card-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.item-card-price {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-hover);
}

.item-card-stock {
  font-size: 0.85rem;
  font-weight: 600;
}

.item-card-actions {
  margin-top: auto;
  padding-top: 0.25rem;
}

.category-grid .item-card-image {
  height: 140px;
}

.login-form { margin-top: 1rem; }
.login-hint { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); text-align: center; }
.login-hint code { color: var(--primary); }
.login-error { margin-top: 0.75rem; color: var(--danger); font-size: 0.875rem; text-align: center; }

.server-error {
  width: 100%;
  max-width: 480px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.5rem;
  margin: 1rem;
  color: var(--text);
}

.server-error pre {
  background: var(--surface);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.9rem;
}

.server-error a { color: var(--primary); }
.server-error.hidden { display: none; }

.sidebar-user {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.sidebar-user strong { display: block; }
.sidebar-user small { color: var(--text-muted); }

.modal-wide { max-width: 520px; }

.barcode-video {
  width: 100%;
  max-height: 240px;
  background: #000;
  border-radius: var(--radius);
  object-fit: cover;
}

.barcode-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.75rem 0;
}

.barcode-manual {
  display: flex;
  gap: 0.5rem;
}

.barcode-manual input { flex: 1; }

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

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

.report-card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.report-card p { margin: 0 0 1rem; color: var(--text-muted); font-size: 0.875rem; }

.date-range {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.date-range input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
}
