:root {
  --purple-deep: #211735;
  --purple-action: #6541a5;
  --lime: #c8ff32;
  --yellow: #ffd400;
  --orange: #ff5a1f;
  --pink: #ff2e93;
  --bg-light: #f7f8f4;
  --bg-dark: #181621;
  --text: #211735;
  --text-muted: #6b6478;
  --surface: #ffffff;
  --border: #e6e3ec;
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg-light: #181621;
  --text: #f2f0f7;
  --text-muted: #a79fc2;
  --surface: #241a3d;
  --border: #362a55;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg-light);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--purple-deep);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  transition: width 0.18s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
  white-space: nowrap;
  overflow: hidden;
}
.brand-full { height: 22px; filter: brightness(0) invert(1); flex-shrink: 0; }
.brand-mini {
  display: none;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}
.brand-mini::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--orange);
  margin-left: 2px;
  vertical-align: super;
}
.sidebar.collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .brand-full { display: none; }
.sidebar.collapsed .brand-mini { display: inline; }

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9b8fc2;
  padding: 14px 10px 6px;
  white-space: nowrap;
}
.sidebar.collapsed .nav-group-label { opacity: 0; height: 0; padding: 0; overflow: hidden; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: #d9d2ec;
  white-space: nowrap;
  margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--lime); color: var(--purple-deep); font-weight: 600; }
.nav-link .ic {
  width: 20px; height: 20px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.nav-link .lbl { overflow: hidden; text-overflow: ellipsis; }
.sidebar.collapsed .nav-link .lbl { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; }

.badge-soon {
  font-size: 10px;
  background: rgba(255,255,255,0.12);
  color: #d9d2ec;
  padding: 2px 6px;
  border-radius: 20px;
  margin-left: auto;
}
.sidebar.collapsed .badge-soon { display: none; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 14px;
}
.sidebar-footer .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--purple-action);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.sidebar-footer .who { font-size: 12px; line-height: 1.3; overflow: hidden; white-space: nowrap; }
.sidebar-footer .who b { display: block; font-size: 13px; }
.sidebar.collapsed .sidebar-footer .who { display: none; }

.collapse-btn {
  background: none;
  border: none;
  color: #9b8fc2;
  width: 100%;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11px;
  cursor: pointer;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 0.75;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.collapse-btn:hover { background: rgba(255,255,255,0.06); opacity: 1; color: #d9d2ec; }
.collapse-mini { display: none; }
.sidebar.collapsed .collapse-full { display: none; }
.sidebar.collapsed .collapse-mini { display: inline; }
.sidebar.collapsed .collapse-btn { font-size: 16px; }

/* ---- Main ---- */
.main { flex: 1; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 2px rgba(20,10,40,0.04);
}
.search {
  flex: 1;
  max-width: 360px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.topbar-spacer { flex: 1; }
.demo-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--orange);
  color: #2b1200;
  padding: 5px 10px;
  border-radius: 20px;
}
.theme-toggle {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.content { padding: 32px 40px 56px; max-width: 1760px; margin: 0 auto; }

.page-title { font-size: 24px; font-weight: 700; margin: 0 0 2px; }
.page-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 26px; }

/* ---- KPI cards ---- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
@media (max-width: 1100px) and (min-width: 521px) { .kpi-row { grid-template-columns: repeat(2, 1fr) !important; } }
@media (max-width: 520px) { .kpi-row { grid-template-columns: 1fr !important; } }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(20,10,40,0.04), 0 6px 16px rgba(20,10,40,0.03);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.kpi-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; background: var(--kpi-tint, rgba(200,255,50,0.16));
  order: 2;
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 25px; font-weight: 700; letter-spacing: -0.01em; }
.kpi-delta { font-size: 12px; margin-top: 6px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.kpi-delta.up { color: #1d8a4a; }
.kpi-delta.down { color: #c2551a; }

/* ---- Panels / charts / tables ---- */
.panel-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 18px; }
.panel-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 18px; }
@media (min-width: 1500px) { .panel-row-3 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .panel-row, .panel-row-3 { grid-template-columns: 1fr; } }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(20,10,40,0.04), 0 6px 16px rgba(20,10,40,0.03);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel h3 { margin: 0; font-size: 14px; font-weight: 600; }
.panel .panel-sub { font-size: 12px; color: var(--text-muted); margin: -10px 0 14px; }

@keyframes bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bars { display: flex; align-items: flex-end; gap: 12px; height: 150px; }
.bars.bars-sm { height: 90px; }
.bars .bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; }
.bars .bar {
  width: 100%; border-radius: 6px 6px 2px 2px; position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--lime), #a3e600);
  transform-origin: bottom; animation: bar-grow 0.5s cubic-bezier(.2,.8,.2,1) backwards;
  transition: filter 0.15s ease, transform 0.15s ease;
}
.bars .bar:hover { filter: brightness(1.08); transform: scaleY(1.015); }
.bars .bar-col:nth-child(1) .bar { animation-delay: 0.02s; }
.bars .bar-col:nth-child(2) .bar { animation-delay: 0.08s; }
.bars .bar-col:nth-child(3) .bar { animation-delay: 0.14s; }
.bars .bar-col:nth-child(4) .bar { animation-delay: 0.2s; }
.bars .bar-col:nth-child(5) .bar { animation-delay: 0.26s; }
.bars .bar-col:nth-child(6) .bar { animation-delay: 0.32s; }
.bars .bar-col span { font-size: 11px; color: var(--text-muted); }

.linechart { width: 100%; height: 100px; }
.linechart .grid-line { stroke: var(--border); stroke-width: 1; }
.linechart .line-path {
  fill: none; stroke: var(--lime); stroke-width: 2.5;
  stroke-dasharray: 500; stroke-dashoffset: 500; animation: line-draw 1s ease-out forwards;
}
@keyframes line-draw { to { stroke-dashoffset: 0; } }
.linechart .line-fill { fill: url(#lineFillGradient); opacity: 0.6; }
.linechart .line-dot { fill: var(--lime); }
.linechart-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.donut-wrap { display: flex; align-items: center; gap: 26px; }
.donut-ring { position: relative; width: 108px; height: 108px; flex-shrink: 0; transition: transform 0.2s ease; }
.donut-ring:hover { transform: scale(1.04); }
.donut-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-ring circle { fill: none; stroke-width: 13; stroke-linecap: round; }
.donut-ring .donut-seg { transition: stroke-dashoffset 0.2s ease; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center .n { font-size: 18px; font-weight: 700; }
.donut-center .l { font-size: 10px; color: var(--text-muted); }
.legend { font-size: 12.5px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.legend .row { display: flex; align-items: center; gap: 8px; }
.legend .row .pct { margin-left: auto; font-weight: 600; color: var(--text); }
.legend .sw { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; box-shadow: 0 0 6px 0 currentColor; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 10px; border-bottom: 1px solid var(--border); }
td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-light); }

.status-chip { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; display: inline-block; }
.status-ok { background: #e4f7ea; color: #1d8a4a; }
.status-warn { background: #fff2d6; color: #9a6a00; }
.status-bad { background: #ffe4dc; color: #b8390a; }
.status-info { background: #ffe3f1; color: var(--pink); }
[data-theme="dark"] .status-ok { background: #113221; }
[data-theme="dark"] .status-warn { background: #3a2c07; }
[data-theme="dark"] .status-bad { background: #3a1608; }
[data-theme="dark"] .status-info { background: #3a0f28; }

/* ---- EPI catalog ---- */
.epi-tabs { display: flex; gap: 4px; margin-bottom: 22px; background: var(--bg-light); border: 1px solid var(--border); border-radius: 10px; padding: 4px; width: fit-content; }
.epi-tab { padding: 8px 16px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; border: none; background: none; }
.epi-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(20,10,40,0.08); }
.epi-view { display: none; }
.epi-view.active { display: block; }

.epi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.epi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
  box-shadow: 0 1px 2px rgba(20,10,40,0.04), 0 6px 16px rgba(20,10,40,0.03);
  cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.epi-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(20,10,40,0.06), 0 10px 24px rgba(20,10,40,0.06); }
.epi-thumb {
  aspect-ratio: 1.4;
  border-radius: 10px;
  background: var(--bg-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; margin-bottom: 12px; color: var(--text-muted);
}
.epi-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.epi-cat { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.epi-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; }

/* ---- EPI detail slide-over ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(20,10,40,0.35);
  display: none; align-items: stretch; justify-content: flex-end; z-index: 30;
}
.overlay.open { display: flex; }
.slideover {
  width: 420px; max-width: 92vw; background: var(--surface); height: 100vh; overflow-y: auto;
  padding: 26px 26px 40px; box-shadow: -8px 0 32px rgba(20,10,40,0.14);
}
.slideover-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; float: right; }
.slideover-thumb { aspect-ratio: 2; border-radius: 12px; background: var(--bg-light); display: flex; align-items: center; justify-content: center; font-size: 48px; margin: 8px 0 16px; }
.slideover h2 { font-size: 19px; margin: 0 0 4px; }
.slideover .epi-cat { margin-bottom: 14px; }
.slideover .field-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.slideover .field-row .k { color: var(--text-muted); }
.slideover .field-row .v { font-weight: 600; }
.slideover .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

.btn { border: none; border-radius: 9px; padding: 11px 16px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--lime); color: var(--purple-deep); }
.btn-primary:hover { filter: brightness(0.96); }
.btn-secondary { background: var(--bg-light); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.delivery-form { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.delivery-form.open { display: block; }
.delivery-form label { display: block; font-size: 12px; color: var(--text-muted); margin: 10px 0 5px; }
.delivery-form input, .delivery-form select {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-light); color: var(--text); font-size: 13px; font-family: var(--font);
}
.delivery-form .form-error { color: #c2551a; font-size: 12px; margin-top: 8px; display: none; }
.delivery-form .form-error.show { display: block; }
.delivery-form .form-ok { color: #1d8a4a; font-size: 12px; margin-top: 8px; display: none; }
.delivery-form .form-ok.show { display: block; }

.placeholder-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-light);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 18px;
}

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 20; height: 100vh; }
  .content { padding: 18px; }
}
