:root {
  --ink: #0f2438;
  --ink-soft: #3a5168;
  --surface: #f3f6f9;
  --panel: #ffffff;
  --line: #d7e0ea;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #ccfbf1;
  --warn: #b45309;
  --danger: #b91c1c;
  --sidebar-w: 268px;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 36, 56, 0.08);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d8f3ef 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e8eef5 0%, transparent 50%),
    var(--surface);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #0b1f31 0%, #12324a 100%);
  color: #e8eef5;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 8px 20px rgba(20,184,166,.35);
}
.brand-name { font-family: var(--display); font-size: 1.05rem; line-height: 1.1; }
.brand-tag { font-size: .72rem; opacity: .65; margin-top: 2px; }
.sidebar-nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-section {
  margin: 14px 10px 8px;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: rgba(232,238,245,.45); font-weight: 600;
}
.app-sidebar .nav-link {
  display: flex; align-items: center; gap: 10px;
  color: rgba(232,238,245,.82);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 2px;
  font-size: .92rem;
}
.app-sidebar .nav-link i { width: 18px; opacity: .9; }
.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
  background: rgba(20,184,166,.16);
  color: #fff;
}
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(8,18,28,.45); z-index: 1035;
}
.app-main {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.app-topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px 8px;
  gap: 12px;
}
.page-title {
  font-family: var(--display);
  font-size: 1.55rem;
  letter-spacing: -.02em;
}
.page-subtitle { color: var(--ink-soft); font-size: .82rem; }
.role-pill {
  background: var(--accent-soft) !important;
  color: var(--accent-2) !important;
  border: 1px solid #99f6e4;
  font-weight: 600;
}
.user-menu {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px 4px 4px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: .85rem; font-weight: 600;
}
.app-content { padding: 8px 24px 28px; flex: 1; }
.app-footer {
  display: flex; justify-content: space-between;
  padding: 12px 24px 18px; color: var(--ink-soft); font-size: .82rem;
}
.demo-banner {
  background: linear-gradient(90deg, #ecfeff, #f0f9ff);
  border: 1px solid #a5f3fc;
  color: #155e75;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .9rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.stat-card, .panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card { padding: 18px 18px 16px; position: relative; overflow: hidden; }
.stat-card::after {
  content: ""; position: absolute; right: -20px; top: -20px;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(15,118,110,.12), transparent 70%);
}
.stat-label { color: var(--ink-soft); font-size: .82rem; margin-bottom: 6px; }
.stat-value { font-family: var(--display); font-size: 1.8rem; line-height: 1; }
.stat-meta { margin-top: 8px; font-size: .78rem; color: var(--accent); }

.panel-card { padding: 18px; margin-bottom: 18px; }
.panel-card .panel-title {
  font-family: var(--display); font-size: 1.15rem; margin-bottom: 2px;
}
.panel-card .panel-sub { color: var(--ink-soft); font-size: .84rem; margin-bottom: 14px; }

.table thead th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); background: #f8fafc; border-bottom-color: var(--line);
}
.table td, .table th { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f8fbfb; }

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-2);
  --bs-btn-hover-border-color: var(--accent-2);
  --bs-btn-active-bg: var(--accent-2);
  --bs-btn-active-border-color: var(--accent-2);
}
.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
}
.btn-soft {
  background: #eef6f5; color: var(--accent-2); border: 1px solid #cce8e4;
}
.btn-icon {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff;
  display: inline-grid; place-items: center;
}
.form-control, .form-select {
  border-color: var(--line); border-radius: 10px; padding: .6rem .85rem;
}
.form-control:focus, .form-select:focus {
  border-color: #5eead4;
  box-shadow: 0 0 0 .2rem rgba(15,118,110,.15);
}
.nav-tabs .nav-link { color: var(--ink-soft); border: none; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--accent-2); border-bottom-color: var(--accent); background: transparent; font-weight: 600; }
.empty-state {
  text-align: center; padding: 42px 20px; color: var(--ink-soft);
}
.empty-state i { font-size: 2rem; color: var(--accent); opacity: .7; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15,36,56,.88), rgba(15,118,110,.75)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    #0f2438;
}
.login-card {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.login-aside {
  padding: 42px 36px;
  background: linear-gradient(160deg, #0f2438 0%, #134e4a 100%);
  color: #fff;
}
.login-aside h2 {
  font-family: var(--display); font-size: 2rem; margin: 18px 0 10px;
}
.login-aside p { opacity: .8; max-width: 34ch; }
.login-form-wrap { padding: 42px 36px; }
.demo-creds {
  background: #f8fafc; border: 1px dashed var(--line); border-radius: 12px;
  padding: 12px; font-size: .82rem; margin-top: 18px;
}
.demo-creds code { color: var(--accent-2); }

.role-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 18px;
  background: #fff; height: 100%;
  transition: transform .2s ease, box-shadow .2s ease;
}
.role-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.perm-matrix th, .perm-matrix td { text-align: center; vertical-align: middle; }
.perm-matrix th:first-child, .perm-matrix td:first-child { text-align: left; }
.family-tree li { margin-bottom: 6px; }
.customer-hero {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(120deg, #0f2438, #115e59);
  color: #fff; border-radius: 16px; padding: 22px;
  margin-bottom: 18px;
}
.customer-hero .meta { opacity: .8; font-size: .9rem; }

@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 992px) {
  .app-sidebar { transform: translateX(-105%); }
  .app-sidebar.show { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .app-main { margin-left: 0; width: 100%; }
  .login-card { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}
@media (max-width: 576px) {
  .stat-grid { grid-template-columns: 1fr; }
  .app-content, .app-topbar { padding-left: 16px; padding-right: 16px; }
}
