:root {
  --brand-1: #7c3aed;
  --brand-2: #4f46e5;
  --brand-ink: #ffffff;
  --bg: #f4f2fb;
  --surface: #ffffff;
  --surface-2: #faf9fe;
  --ink: #1c1830;
  --ink-2: #5d5578;
  --ink-3: #8d86a8;
  --border: #e6e1f3;
  --shadow: 0 1px 2px rgb(28 24 48 / 0.05), 0 8px 24px -12px rgb(76 60 180 / 0.18);
  --shadow-lg: 0 24px 64px -16px rgb(28 24 48 / 0.35);
  --radius: 14px;
  --radius-sm: 9px;
  --good: #15803d;
  --good-bg: #e5f6ec;
  --warning: #b45309;
  --warning-bg: #fdf1de;
  --serious: #c2410c;
  --serious-bg: #fdeadd;
  --critical: #b91c1c;
  --critical-bg: #fbe4e4;
  --info: #1d4ed8;
  --info-bg: #e3edfd;
  --neutral: #5d5578;
  --neutral-bg: #ece9f5;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="dark"] {
  --bg: #14111f;
  --surface: #1d1929;
  --surface-2: #232030;
  --ink: #f1edfb;
  --ink-2: #b7aecf;
  --ink-3: #7f7599;
  --border: #2f2a44;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 32px -12px rgb(0 0 0 / 0.5);
  --good-bg: #12382580;
  --warning-bg: #4a2f0b80;
  --serious-bg: #4f220a80;
  --critical-bg: #4d121280;
  --info-bg: #16294e80;
  --neutral-bg: #2c284080;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

.hidden { display: none !important; }
.muted-text { color: var(--ink-3); font-size: 12px; }
.preserve { white-space: pre-wrap; color: var(--ink-2); margin: 0; }
.loading { padding: 32px; text-align: center; color: var(--ink-3); }

/* ---------- Login ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px 400px at 15% 20%, rgb(124 58 237 / 0.14), transparent 60%),
    radial-gradient(600px 400px at 85% 80%, rgb(79 70 229 / 0.14), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.login-brand h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.login-brand p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }

.login-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 24px;
  color: var(--brand-ink);
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 6px 16px -6px rgb(124 58 237 / 0.6);
  flex-shrink: 0;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
label.inline-label { flex-direction: row; align-items: center; gap: 10px; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgb(124 58 237 / 0.15);
}

textarea { resize: vertical; }

.form-error {
  color: var(--critical);
  background: var(--critical-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin: 0;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  color: var(--brand-ink);
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 6px 16px -8px rgb(124 58 237 / 0.7);
}
.btn-primary:hover { box-shadow: 0 8px 20px -8px rgb(124 58 237 / 0.8); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--critical-bg); color: var(--critical); border-color: transparent; }
.btn-danger:hover { background: var(--critical); color: #fff; }

.btn-good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.btn-good:hover { background: var(--good); color: #fff; }

.btn-sm { font-size: 12.5px; padding: 6px 11px; }
.btn-block { width: 100%; }

/* ---------- Layout ---------- */
#app-view { display: flex; min-height: 100vh; }

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 14px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.sidebar-brand .login-logo { width: 36px; height: 36px; font-size: 19px; border-radius: 10px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: linear-gradient(135deg, rgb(124 58 237 / 0.14), rgb(79 70 229 / 0.14));
  color: var(--brand-1);
}
body[data-theme="dark"] .nav-item.active { color: #c4b5fd; }
.nav-item svg { flex-shrink: 0; }

.sidebar-footer { padding: 12px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); }
.sidebar-footer .btn { text-align: left; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 4px;
}

.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }

.content {
  padding: 20px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Cards & tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.card h2 { margin: 0 0 14px; font-size: 16px; letter-spacing: -0.01em; }
.card-flat { box-shadow: none; margin-top: 14px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.filters-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters-row select { width: auto; min-width: 130px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--ink-3);
}

.search-box input { border: none; background: transparent; padding: 9px 0; width: 240px; }
.search-box input:focus { box-shadow: none; }

.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-wrap td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: var(--surface-2); }
.row-inactive td { opacity: 0.65; }

.cell-title { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.thumb {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.thumb-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, hsl(var(--thumb-h, 260) 60% 55%), hsl(calc(var(--thumb-h, 260) + 30) 60% 45%));
}

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.stock-input { width: 90px; }

.empty-state { text-align: center; color: var(--ink-3); padding: 28px 12px; font-size: 14px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge svg { flex-shrink: 0; }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-serious { background: var(--serious-bg); color: var(--serious); }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- KPIs & charts ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.kpi-1::before { background: var(--brand-1); }
.kpi-2::before { background: var(--info); }
.kpi-3::before { background: var(--warning); }
.kpi-4::before { background: var(--good); }

.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-label { font-size: 13px; font-weight: 700; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--ink-3); }

.chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 12px; }
.bar-label { font-size: 13px; font-weight: 600; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }

.series-1 { background: linear-gradient(90deg, var(--brand-1), var(--brand-2)); }
.series-2 { background: linear-gradient(90deg, #f59e0b, #d97706); }
.series-3 { background: linear-gradient(90deg, #3b82f6, #1d4ed8); }
.series-4 { background: linear-gradient(90deg, #22c55e, #15803d); }
.series-5 { background: linear-gradient(90deg, #ef4444, #b91c1c); }
.series-6 { background: linear-gradient(90deg, #8b5cf6, #6d28d9); }

.bar-value { font-size: 13px; font-weight: 700; text-align: right; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(15 10 30 / 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade-in 0.15s ease;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: pop-in 0.18s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
}

.modal-header h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.modal-close {
  border: none;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 22px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
}
.modal-close:hover { background: var(--border); color: var(--ink); }

.modal-body { padding: 16px 22px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 22px 20px;
}

.modal-subtitle { font-size: 14px; margin: 16px 0 8px; }
.confirm-text { margin: 4px 0; line-height: 1.5; }

.detail-list { display: flex; flex-direction: column; }
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key { font-weight: 700; color: var(--ink-2); }

.stars { color: #eab308; letter-spacing: 1px; }
.comment-text { margin-top: 4px; color: var(--ink); line-height: 1.5; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: end; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px;
}
.pagination-info { font-size: 13px; color: var(--ink-2); }

/* ---------- Toasts ---------- */
#toast-root {
  position: fixed;
  bottom: 22px;
  right: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.toast {
  background: #1c1830;
  color: #f4f2fb;
  font-size: 13.5px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 340px;
}

.toast.show { opacity: 1; transform: none; }
.toast-error { background: #7f1d1d; }
.toast-success { background: #14532d; }

/* ---------- Misc ---------- */
.picker { width: 260px; }
.role-select { width: 130px; padding: 6px 8px; font-size: 13px; }

.image-manager { display: flex; flex-direction: column; gap: 12px; }
.image-preview { display: flex; justify-content: center; }
.image-preview img { max-width: 100%; max-height: 280px; border-radius: var(--radius); border: 1px solid var(--border); }

.account-card { margin-bottom: 16px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

@media (max-width: 900px) {
  .sidebar { width: 76px; }
  .sidebar-brand span:last-child, .nav-item span, .sidebar-footer .btn { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px 8px 10px; }
  .nav-item { justify-content: center; }
  .content { padding: 14px 14px 40px; }
  .topbar { padding: 14px 14px 0; }
  .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 86px 1fr 36px; }
}
