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

:root {
  --bg:          #0f1117;
  --bg-2:        #161b27;
  --bg-3:        #1e2535;
  --border:      #2a3347;
  --border-l:    #364058;
  --text:        #e8edf5;
  --text-2:      #8b95a8;
  --text-3:      #5a6478;
  --accent:      #4f7fff;
  --accent-glow: rgba(79,127,255,.18);
  --green:       #22c55e;
  --green-bg:    rgba(34,197,94,.12);
  --red:         #ef4444;
  --red-bg:      rgba(239,68,68,.12);
  --orange:      #f97316;
  --orange-bg:   rgba(249,115,22,.12);
  --purple:      #a855f7;
  --purple-bg:   rgba(168,85,247,.12);
  --radius:      10px;
  --radius-lg:   14px;
  --shadow:      0 4px 24px rgba(0,0,0,.35);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.25);
  --sidebar-w:   240px;
  --transition:  .18s ease;
}

html { font-size: 15px; }

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

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

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), #7c4fff);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 18px rgba(79,127,255,.35);
}
.logo svg { width: 18px; height: 18px; color: #fff; }

.logo-title { display: block; font-size: .95rem; font-weight: 700; color: var(--text); }
.logo-sub   { display: block; font-size: .7rem; color: var(--text-2); }

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-2);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,127,255,.25);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.version-badge {
  font-size: .7rem;
  color: var(--text-3);
  background: var(--bg-3);
  padding: 3px 8px;
  border-radius: 20px;
  display: inline-block;
}

/* ─── Main ─────────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

/* ─── Views ────────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

/* ─── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.page-sub   { font-size: .8rem; color: var(--text-2); margin-top: 2px; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(79,127,255,.3);
}
.btn-primary:hover { background: #3d6ef5; box-shadow: 0 0 20px rgba(79,127,255,.45); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-l);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-danger:hover { background: #dc2626; }

.btn-icon {
  padding: 6px;
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-2);
  transition: background var(--transition), color var(--transition);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover { background: var(--bg-3); color: var(--text); }
.btn-icon.delete:hover { background: var(--red-bg); color: var(--red); }
.btn-icon.edit:hover   { background: var(--accent-glow); color: var(--accent); }

/* ─── Stats ────────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }

.stat-blue   .stat-icon { background: var(--accent-glow);  color: var(--accent); }
.stat-green  .stat-icon { background: var(--green-bg);     color: var(--green);  }
.stat-orange .stat-icon { background: var(--orange-bg);    color: var(--orange); }
.stat-purple .stat-icon { background: var(--purple-bg);    color: var(--purple); }

.stat-value {
  display: block;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-label {
  display: block;
  font-size: .72rem;
  color: var(--text-2);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ─── Low Stock List ───────────────────────────────────────────────────────── */
.low-stock-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

.low-stock-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,.2);
  border-radius: var(--radius);
  padding: 11px 16px;
  animation: fadeIn .25s ease;
}
.ls-name     { font-weight: 600; font-size: .875rem; color: var(--text); }
.ls-category { font-size: .75rem; color: var(--text-2); margin-top: 1px; }
.ls-qty {
  font-size: .8rem;
  color: var(--red);
  background: rgba(239,68,68,.15);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
}

/* ─── Filters ──────────────────────────────────────────────────────────────── */
.filters-row {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input { padding-left: 34px !important; }

.input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 13px;
  font-size: .85rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.input::placeholder { color: var(--text-3); }
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input.error { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }

.select-input { min-width: 160px; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a6478' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  padding-right: 30px;
}
.select-input option { background: var(--bg-3); color: var(--text); }

/* ─── Table ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

.table thead tr {
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}
.table th {
  padding: 12px 16px;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  user-select: none;
}
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text); }
.sort-icon { font-size: .9em; opacity: .5; }
.table th.sort-asc  .sort-icon,
.table th.sort-desc .sort-icon { opacity: 1; color: var(--accent); }

.table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-3); }

/* ── Low stock row highlight ── */
.table tbody tr.row-low { background: rgba(239,68,68,.06); }
.table tbody tr.row-low:hover { background: rgba(239,68,68,.1); }

.table td { padding: 12px 16px; vertical-align: middle; }

.product-name  { font-weight: 600; color: var(--text); }
.product-desc  { font-size: .72rem; color: var(--text-2); margin-top: 2px; }

.category-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,127,255,.2);
}

.qty-cell { font-weight: 700; font-size: .9rem; }
.qty-low  { color: var(--red); }
.qty-ok   { color: var(--green); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-ok  { background: var(--green-bg);  color: var(--green);  border: 1px solid rgba(34,197,94,.2); }
.status-ok::before  { background: var(--green); }
.status-low { background: var(--red-bg);    color: var(--red);    border: 1px solid rgba(239,68,68,.2);  }
.status-low::before { background: var(--red); }

.actions-cell { display: flex; gap: 4px; }

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-3);
  font-size: .85rem;
}
.empty-state svg { width: 44px; height: 44px; opacity: .4; }
.hidden { display: none !important; }

/* ─── Form ─────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 30px;
  max-width: 760px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-2); }
.required { color: var(--red); }
.form-error { font-size: .73rem; color: var(--red); min-height: 16px; }

.preview-box {
  background: var(--bg-3);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  gap: 32px;
  margin-bottom: 22px;
}
.preview-item { display: flex; flex-direction: column; gap: 2px; }
.preview-label { font-size: .72rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.preview-value { font-size: .95rem; font-weight: 700; color: var(--text); }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-l);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
  text-align: center;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(18px); opacity:0; } to { transform: none; opacity:1; } }

.modal-icon {
  width: 52px; height: 52px;
  background: var(--red-bg);
  border-radius: 50%;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--red);
}
.modal-icon svg { width: 24px; height: 24px; }
.modal-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 8px; }
.modal-text  { font-size: .84rem; color: var(--text-2); line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; }

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

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .84rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn .22s ease;
  min-width: 240px;
  max-width: 320px;
}
@keyframes toastIn { from { transform: translateX(30px); opacity:0; } to { transform: none; opacity:1; } }
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastOut { to { transform: translateX(30px); opacity:0; } }

.toast-icon { width: 16px; height: 16px; flex-shrink: 0; }
.toast.success { border-left: 3px solid var(--green); }
.toast.success .toast-icon { color: var(--green); }
.toast.error   { border-left: 3px solid var(--red);   }
.toast.error   .toast-icon { color: var(--red);   }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.info    .toast-icon { color: var(--accent); }

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-l); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .logo-text, .nav-item span, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .main { margin-left: 60px; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .filters-row { flex-direction: column; }
  .select-input { min-width: auto; }
}
