:root {
  --pc-red: #D7141A;
  --pc-red-dark: #9B0F13;
  --pc-red-deep: #6E0A0D;
  --pc-ink: #141414;
  --pc-ink-soft: #3A3A3A;
  --pc-muted: #6A6A6A;
  --pc-cream: #F4EEEA;
  --pc-line: #EEEAEA;
  --pc-paper: #FFFFFF;
  --pc-snow: #FAFAFA;
  --pc-radius: 14px;
  --pc-shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --pc-shadow-md: 0 6px 18px rgba(0,0,0,.08);
  --pc-shadow-red: 0 6px 18px rgba(215, 20, 26, 0.18);
  --pc-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--pc-font);
  color: var(--pc-ink);
  background: var(--pc-snow);
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }

.muted { color: var(--pc-muted); }
[hidden] { display: none !important; }

/* Sidebar */
.side {
  background: linear-gradient(180deg, var(--pc-ink) 0%, #0d0d0d 100%);
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 12px; }
.side-brand img { width: 42px; height: 42px; }
.side-brand strong { display: block; font-size: 16px; line-height: 1; }
.side-brand small { display: block; font-size: 10px; letter-spacing: 1.4px; opacity: .65; }

.side-nav { display: flex; flex-direction: column; gap: 4px; }
.tab {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,.78);
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .2px;
  transition: background .15s, color .15s;
}
.tab:hover { background: rgba(255,255,255,.06); color: #fff; }
.tab.active {
  background: var(--pc-red);
  color: #fff;
  box-shadow: var(--pc-shadow-red);
}

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; font-size: 12px; }
.side-foot .muted { color: rgba(255,255,255,.55); }

/* Buttons */
.btn-primary {
  background: var(--pc-red);
  color: #fff;
  border: 0;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .2px;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--pc-red-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
}
.btn-ghost:hover { background: rgba(255,255,255,.06); }
.btn-link {
  background: transparent;
  border: 0;
  color: var(--pc-red);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
}
.btn-link.danger { color: var(--pc-red-deep); }
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  background: transparent;
  border: 0;
  font-size: 22px;
  color: var(--pc-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--pc-cream); color: var(--pc-ink); }

/* Content */
.content {
  padding: 32px 36px;
  overflow-x: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.panel-head h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--pc-paper);
  border: 1px solid var(--pc-line);
  border-radius: var(--pc-radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--pc-shadow-sm);
}
.kpi.accent {
  background: linear-gradient(160deg, var(--pc-red) 0%, var(--pc-red-dark) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--pc-shadow-red);
}
.kpi.accent .kpi-num, .kpi.accent .kpi-label { color: #fff; }
.kpi.accent .kpi-label { opacity: .85; }
.kpi-num {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--pc-ink);
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--pc-muted);
}
.kpi-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--pc-muted);
  margin-top: 4px;
  line-height: 1.3;
}
.kpi.accent .kpi-sub { color: rgba(255,255,255,.78); }

.uni-bar {
  position: relative;
  width: 140px;
  height: 8px;
  background: var(--pc-snow);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--pc-line);
}
.uni-bar__fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--pc-red) 0%, var(--pc-red-dark) 100%);
  border-radius: 999px;
}

.card {
  background: var(--pc-paper);
  border: 1px solid var(--pc-line);
  border-radius: var(--pc-radius);
  margin-bottom: 22px;
  overflow: hidden;
  box-shadow: var(--pc-shadow-sm);
}
.card-head {
  background: var(--pc-cream);
  padding: 12px 18px;
  border-bottom: 1px solid var(--pc-line);
}
.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--pc-ink);
}
.card-body { padding: 18px; }
.chart-wrap { position: relative; height: 320px; }

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--pc-line);
}
.data-table th {
  background: var(--pc-snow);
  color: var(--pc-ink-soft);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: rgba(215, 20, 26, 0.04); }
.data-table .actions { white-space: nowrap; text-align: right; }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.pill.on { background: rgba(46, 160, 67, .1); color: #1a7f37; }
.pill.off { background: rgba(215, 20, 26, .1); color: var(--pc-red-dark); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20,20,20,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-card {
  background: var(--pc-paper);
  border-radius: 18px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--pc-line);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-body { padding: 22px; display: grid; gap: 14px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--pc-line);
  background: var(--pc-snow);
}
.modal-foot .btn-ghost {
  border: 1px solid var(--pc-line);
  color: var(--pc-ink-soft);
  background: var(--pc-paper);
}
.modal-foot .btn-ghost:hover { background: var(--pc-cream); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--pc-ink-soft); }
.field input, .field textarea, .field select {
  padding: 10px 12px;
  border: 1px solid var(--pc-line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--pc-paper);
  color: var(--pc-ink);
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 0;
  border-color: var(--pc-red);
  box-shadow: 0 0 0 3px rgba(215,20,26,.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-check { display: flex; align-items: center; gap: 8px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pc-ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,.25);
  z-index: 200;
}
.toast.error { background: var(--pc-red-dark); }

/* Auth (login page) */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(800px 380px at 80% -10%, rgba(215,20,26,.18), transparent 60%),
    radial-gradient(500px 240px at -10% 110%, rgba(110,10,13,.10), transparent 60%),
    var(--pc-cream);
}
.auth-card {
  background: var(--pc-paper);
  border-radius: 22px;
  padding: 36px 32px;
  width: min(420px, 92%);
  box-shadow: 0 20px 60px rgba(20,20,20,.10);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand img { width: 48px; height: 48px; }
.auth-brand strong { display: block; font-size: 16px; line-height: 1; }
.auth-brand small { display: block; font-size: 10px; letter-spacing: 1.4px; color: var(--pc-muted); }
.auth-card h1 { margin: 0 0 6px 0; font-size: 24px; font-weight: 700; }
.auth-card p { margin: 0 0 18px 0; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; }
.auth-form span { font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--pc-ink-soft); }
.auth-form input {
  padding: 12px 14px;
  border: 1px solid var(--pc-line);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
}
.auth-form input:focus {
  outline: 0;
  border-color: var(--pc-red);
  box-shadow: 0 0 0 3px rgba(215,20,26,.15);
}
.auth-form .btn-primary { padding: 12px 20px; font-size: 15px; }
.auth-error {
  background: rgba(215,20,26,.08);
  color: var(--pc-red-dark);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
}

@media (max-width: 880px) {
  body { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .side-nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .side-foot { margin-left: auto; flex-direction: row; align-items: center; }
  .content { padding: 22px 18px; }
  .field-row { grid-template-columns: 1fr; }
}
