:root {
  --p-navy: #0b2f6b;
  --p-navy-dark: #071d45;
  --p-navy-light: #163c7c;
  --p-sidebar: #0a2452;
  --p-sidebar-alt: #0d2c60;
  --p-amber: #f2a93c;
  --p-amber-dark: #d98f1f;
  --p-sky: #3e8ed0;
  --p-bg: #f2f5fa;
  --p-surface: #fff;
  --p-surface-alt: #f7f9fc;
  --p-border: #e4e9f2;
  --p-ink: #1a2233;
  --p-muted: #6b7690;
  --p-heading: var(--p-navy);
  --p-radius: 16px;
  --p-radius-sm: 10px;
  --p-shadow: 0 8px 24px rgba(11,47,107,.06), 0 1px 2px rgba(11,47,107,.04);
  --p-shadow-lg: 0 24px 64px rgba(8,20,45,.16), 0 4px 14px rgba(8,20,45,.08);
  --p-badge-green-bg: #e8f8ef; --p-badge-green-fg: #1c7a45;
  --p-badge-red-bg: #fdeceb; --p-badge-red-fg: #c0392b;
  --p-badge-gray-bg: #eef2f9;
  --p-badge-amber-bg: #fdf1dc; --p-badge-amber-fg: #9a6a12;
  --p-badge-blue-bg: #eaf3fc;
}
:root[data-theme="dark"] {
  --p-bg: #0b1220;
  --p-surface: #131c30;
  --p-surface-alt: #182339;
  --p-border: #263250;
  --p-ink: #e6eaf5;
  --p-muted: #8b96b8;
  --p-heading: #86b6ec;
  --p-shadow: 0 8px 24px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.3);
  --p-shadow-lg: 0 24px 64px rgba(0,0,0,.55), 0 4px 14px rgba(0,0,0,.4);
  --p-badge-green-bg: rgba(46,204,113,.16); --p-badge-green-fg: #6fe3a3;
  --p-badge-red-bg: rgba(231,76,60,.16); --p-badge-red-fg: #ff8a80;
  --p-badge-gray-bg: rgba(255,255,255,.07);
  --p-badge-amber-bg: rgba(242,169,60,.16); --p-badge-amber-fg: #ffcf7a;
  --p-badge-blue-bg: rgba(62,142,208,.16);
}
* { box-sizing: border-box; }
body.panel {
  margin: 0; background: var(--p-bg); color: var(--p-ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--p-amber); color: #402a00; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--p-border); border-radius: 999px; }
:focus-visible { outline: 2px solid var(--p-sky); outline-offset: 2px; }

/* ---------- Layout / sidebar ---------- */
.panel-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px; background: linear-gradient(185deg, var(--p-sidebar-alt) 0%, var(--p-sidebar) 60%, var(--p-navy-dark) 100%);
  color: #cfe0f7; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 100;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 22px 20px; font-weight: 800; color: #fff; font-size: 16.5px; border-bottom: 1px solid rgba(255,255,255,.08); letter-spacing: -.01em; }
.sidebar-brand img { height: 36px; width: 36px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.18); }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 11px; text-decoration: none;
  color: #aebfe0; font-weight: 600; font-size: 14px; position: relative; transition: background .15s ease, color .15s ease;
}
.sidebar-nav a span:first-child { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; opacity: .9; }
.sidebar-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav a.active { background: var(--p-amber); color: #402a00; box-shadow: 0 4px 14px rgba(242,169,60,.35); }
.sidebar-nav a.active span:first-child { opacity: 1; }
.sidebar-foot { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #8195bd; }
.sidebar-foot .company-name { color: #fff; font-weight: 700; display: block; margin-bottom: 3px; font-size: 13px; }

.panel-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--p-surface); border-bottom: 1px solid var(--p-border); padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10;
  box-shadow: 0 1px 0 rgba(11,47,107,.02);
}
.topbar h1 { font-size: 20px; margin: 0; color: var(--p-heading); font-weight: 800; letter-spacing: -.01em; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.topbar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--p-sky), var(--p-navy));
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13.5px;
}
.panel-body { padding: 28px; flex: 1; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 18px; margin-bottom: 26px; }
.kpi-card {
  background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow); padding: 20px 22px;
  border-top: 3px solid var(--p-sky); transition: transform .15s ease, box-shadow .15s ease;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--p-shadow-lg); }
.kpi-card .label { font-size: 12px; color: var(--p-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi-card .value { font-size: 27px; font-weight: 800; color: var(--p-heading); margin-top: 8px; letter-spacing: -.02em; }

/* ---------- Cards ---------- */
.panel-card { background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow); padding: 24px; margin-bottom: 22px; }
.panel-card h2 { margin: 0 0 16px; font-size: 16.5px; color: var(--p-heading); font-weight: 800; letter-spacing: -.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; }
.card-sub { color: var(--p-muted); font-size: 13px; margin: -10px 0 16px; }

/* ---------- Tables ---------- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--p-muted); padding: 11px 12px; border-bottom: 2px solid var(--p-border); font-weight: 700; }
table.data-table td { padding: 13px 12px; border-bottom: 1px solid var(--p-border); vertical-align: middle; }
table.data-table tbody tr { transition: background .12s ease; }
table.data-table tr:hover td { background: var(--p-surface-alt); }
table.data-table tr:last-child td { border-bottom: none; }

/* ---------- Buttons ---------- */
.pbtn {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 18px; border-radius: 10px; border: none;
  font-weight: 700; font-size: 13.5px; cursor: pointer; text-decoration: none; font-family: inherit;
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.pbtn:active { transform: translateY(1px); }
.pbtn-primary { background: var(--p-navy); color: #fff; box-shadow: 0 4px 12px rgba(11,47,107,.25); }
.pbtn-primary:hover { background: var(--p-navy-dark); }
.pbtn-amber { background: var(--p-amber); color: #402a00; }
.pbtn-amber:hover { background: var(--p-amber-dark); }
.pbtn-ghost { background: var(--p-surface); border: 1.5px solid var(--p-border); color: var(--p-heading); }
.pbtn-ghost:hover { background: var(--p-surface-alt); }
.pbtn-danger { background: var(--p-badge-red-bg); color: var(--p-badge-red-fg); }
.pbtn-danger:hover { filter: brightness(0.96); }
.pbtn-sm { padding: 7px 13px; font-size: 12.5px; border-radius: 8px; }

/* ---------- Badges ---------- */
.badge { padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; display: inline-block; letter-spacing: .01em; }
.badge-green { background: var(--p-badge-green-bg); color: var(--p-badge-green-fg); }
.badge-red { background: var(--p-badge-red-bg); color: var(--p-badge-red-fg); }
.badge-gray { background: var(--p-badge-gray-bg); color: var(--p-muted); }
.badge-amber { background: var(--p-badge-amber-bg); color: var(--p-badge-amber-fg); }
.badge-blue { background: var(--p-badge-blue-bg); color: var(--p-heading); }

/* ---------- Forms ---------- */
.p-field { margin-bottom: 16px; }
.p-field label { display: block; font-size: 12px; font-weight: 700; color: var(--p-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 7px; }
.p-field input, .p-field select, .p-field textarea {
  width: 100%; padding: 11px 13px; border-radius: 9px; border: 1.5px solid var(--p-border); font-size: 14.5px; font-family: inherit; background: var(--p-surface-alt); color: var(--p-ink);
  transition: border-color .15s ease, background .15s ease;
}
.p-field input:focus, .p-field select:focus, .p-field textarea:focus { outline: none; border-color: var(--p-sky); background: var(--p-surface); box-shadow: 0 0 0 3px rgba(62,142,208,.15); }
.p-field input:disabled, .p-field select:disabled, .p-field textarea:disabled { opacity: .6; cursor: not-allowed; }
.p-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.p-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(120% 140% at 20% -10%, var(--p-navy-light) 0%, var(--p-navy) 45%, var(--p-navy-dark) 100%); padding: 20px; }
.login-card { background: var(--p-surface); border-radius: 20px; padding: 40px 36px; width: 380px; max-width: 100%; box-shadow: var(--p-shadow-lg); text-align: center; }
.login-card img { height: 58px; border-radius: 50%; margin-bottom: 16px; box-shadow: 0 0 0 4px rgba(11,47,107,.08); }
.login-card h1 { font-size: 20px; color: var(--p-heading); margin: 0 0 22px; font-weight: 800; }

/* ---------- Flash ---------- */
.p-flash { padding: 13px 17px; border-radius: 11px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.p-flash-success { background: var(--p-badge-green-bg); color: var(--p-badge-green-fg); }
.p-flash-error { background: var(--p-badge-red-bg); color: var(--p-badge-red-fg); }
.p-flash-info { background: var(--p-badge-blue-bg); color: var(--p-heading); }

/* ---------- Filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
.filter-bar input, .filter-bar select { padding: 9px 13px; border-radius: 999px; border: 1.5px solid var(--p-border); font-size: 13.5px; background: var(--p-surface); color: var(--p-ink); }

.empty-state { text-align: center; padding: 46px 20px; color: var(--p-muted); font-size: 14px; }
.empty-state::before { content: "🗂️"; display: block; font-size: 28px; margin-bottom: 10px; opacity: .6; }

.perm-list label { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 14px; }

/* ---------- Modal ---------- */
body.modal-open { overflow: hidden; }
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(8,16,32,.55); backdrop-filter: blur(2px);
  z-index: 1000; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow-lg);
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; animation: pagModalIn .18s ease;
}
.modal.modal-wide { max-width: 760px; }
@keyframes pagModalIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--p-border); position: sticky; top: 0; background: var(--p-surface); border-radius: var(--p-radius) var(--p-radius) 0 0; }
.modal-header h3 { margin: 0; font-size: 17px; color: var(--p-heading); font-weight: 800; }
.modal-close {
  border: none; background: var(--p-surface-alt); color: var(--p-muted); width: 32px; height: 32px; border-radius: 50%;
  font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s ease, color .15s ease;
}
.modal-close:hover { background: var(--p-badge-red-bg); color: var(--p-badge-red-fg); }
.modal-body { padding: 22px 24px 24px; }
.modal-body .p-grid-2:last-child, .modal-body form > div:last-child { margin-bottom: 0; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -252px; z-index: 200; transition: left .2s ease; }
  .sidebar.open { left: 0; }
  .p-grid-2, .p-grid-3 { grid-template-columns: 1fr; }
  .panel-body { padding: 18px; }
  .topbar { padding: 14px 18px; }
  .modal { max-height: 92vh; }
}
