:root {
  --primary: #0057a8;
  --primary2: #0076c8;
  --cyan: #00a8df;
  --ink: #14213d;
  --muted: #667085;
  --bg: #f4f7fb;
  --card: #fff;
  --line: #e4e9f0;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(16, 42, 67, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Roboto, Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code {
  background: #eef4fb;
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* App Shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 256px;
  background: linear-gradient(180deg, #004d96, #003b74);
  color: #fff;
  padding: 18px 14px 70px;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
}
.brandmark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  color: var(--primary);
  font-weight: 900;
  font-size: 18px;
  flex-shrink: 0;
}
.brand b { display: block; font-size: 15px; }
.brand small { opacity: .75; font-size: 11px; }

.nav { margin-top: 14px; }
.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #eaf4ff;
  text-align: left;
  padding: 11px 13px;
  border-radius: 10px;
  margin: 2px 0;
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s ease;
}
.nav button:hover, .nav button.active {
  background: rgba(255, 255, 255, .16);
  color: #fff;
}
.nav .section {
  font-size: 10px;
  opacity: .6;
  letter-spacing: 1.2px;
  margin: 16px 12px 6px;
  font-weight: 700;
}
.sidebar-foot {
  margin-top: 24px;
  padding: 12px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, .14);
  font-size: 11px;
  opacity: .75;
}

.main {
  margin-left: 256px;
  width: calc(100% - 256px);
  min-width: 0;
}
.topbar {
  height: 70px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}
.top-title { font-size: 18px; font-weight: 800; }
.top-right { display: flex; align-items: center; gap: 12px; }
.online {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--success);
  font-weight: 800;
  background: #ecfdf3;
  padding: 5px 10px;
  border-radius: 999px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
}
.user-meta { line-height: 1.2; text-align: left; }
.user-meta b { display: block; font-size: 12px; color: var(--ink); }
.user-meta small { display: block; font-size: 10px; color: var(--primary); font-weight: 700; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e8f3ff;
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 800;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.btn-logout {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
}
.btn-logout:hover { background: #fee2e2; }

.content { padding: 22px; max-width: 1500px; margin: auto; }
.page { display: none; }
.page.active { display: block; }
.page > h2 { margin: 0 0 16px; font-size: 20px; }

.hero {
  background: linear-gradient(120deg, #0057a8, #007dc4);
  color: #fff;
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}
.hero h1 { margin: 0 0 7px; font-size: 24px; }
.hero p { margin: 0; opacity: .88; font-size: 13px; }
.hero-badge {
  background: rgba(255, 255, 255, .15);
  padding: 10px 14px;
  border-radius: 12px;
  text-align: center;
  min-width: 165px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px;
  box-shadow: var(--shadow);
}
.stat { display: flex; justify-content: space-between; align-items: flex-start; }
.label { font-size: 12px; color: var(--muted); font-weight: 700; }
.num { font-size: 29px; font-weight: 850; margin-top: 7px; }
.icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #eaf4ff;
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.grid2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 16px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.panel h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); font-size: 12px; }

.formgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
  color: #344054;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #d6dde6;
  border-radius: 9px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 87, 168, .1);
}
textarea { min-height: 86px; resize: vertical; }
.full { grid-column: 1 / -1; }

.btn {
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: #004682; }
.btn.secondary { background: #eef5fc; color: var(--primary); }
.btn.secondary:hover { background: #dcebfa; }
.btn.danger { background: #fee4e2; color: var(--danger); }
.btn.danger:hover { background: #fecdd3; }
.btn.sm { padding: 6px 10px; font-size: 11.5px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 13px;
  min-width: 650px;
}
th, td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12.5px;
  vertical-align: top;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  background: #eef2f6;
  color: #344054;
}
.ok { background: #dcfce7; color: #166534; }
.warn { background: #fef3c7; color: #92400e; }
.bad { background: #fee2e2; color: #991b1b; }
.blue { background: #e0f2fe; color: #075985; }
.purple { background: #f3e8ff; color: #6b21a8; }

.progress {
  height: 8px;
  background: #e9eef5;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}
.empty { padding: 26px; text-align: center; color: var(--muted); font-size: 13px; }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  font-weight: 800;
  color: var(--ink);
}
.quick button:hover { border-color: var(--primary); background: #f8fbff; }
.quick button small { display: block; color: var(--muted); font-weight: 500; margin-top: 4px; }

.status-edit {
  border: 1px solid #cfe0f5;
  border-radius: 9px;
  padding: 6px 9px;
  background: #fff;
  color: #12304f;
  font-weight: 700;
  min-width: 105px;
  cursor: pointer;
}
.status-edit:focus { outline: 2px solid #7db7ff; outline-offset: 1px; }

/* Charts */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 2vw, 18px);
  height: 230px;
  margin-top: 16px;
  padding: 12px 8px 4px;
  border-bottom: 1px solid #dbe3ed;
  overflow-x: auto;
  overflow-y: hidden;
}
.chart-row {
  flex: 1 0 54px;
  min-width: 54px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}
.chart-value { font-size: 12px; font-weight: 800; color: #344054; }
.chart-track {
  height: 165px;
  width: min(100%, 42px);
  background: #edf1f5;
  border-radius: 8px 8px 3px 3px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.chart-track span {
  display: block;
  width: 100%;
  border-radius: 7px 7px 2px 2px;
  min-height: 0;
  transition: height .25s ease;
}
.chart-label {
  font-size: 11px;
  color: #344054;
  text-align: center;
  line-height: 1.25;
  max-width: 90px;
  overflow-wrap: anywhere;
  min-height: 28px;
}
.chart-empty { color: #667085; font-size: 13px; padding: 22px 8px; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  font-size: 11px;
  color: #475467;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* Customer Toolbar & Modal */
.customer-toolbar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}
.customer-name { font-weight: 700; color: var(--ink); }
.customer-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.click-row { cursor: pointer; }
.click-row:hover { background: #f5f9ff; }
.customer-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 60;
}
.modal.show { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-close {
  border: 0;
  background: #f1f5f9;
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-weight: 800;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.detail-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.detail-item.full { grid-column: 1 / -1; }
.detail-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.detail-value { font-size: 13.5px; font-weight: 600; color: var(--ink); margin-top: 4px; word-break: break-word; }

/* RBAC Matrix & Role Cards */
.role-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.role-tab {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 13px;
}
.role-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.rbac-groups {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.rbac-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #fafcff;
}
.rbac-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.rbac-group-head b { font-size: 13.5px; color: var(--primary); }
.rbac-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 6px 4px;
  cursor: pointer;
  font-size: 12.5px;
}
.rbac-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.rbac-check small { display: block; color: var(--muted); font-size: 11px; }

/* Toast */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #172b4d;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 80;
  font-size: 13px;
  font-weight: 600;
}
.toast.err { background: #991b1b; }

/* Login Page */
.login-body {
  min-height: 100vh;
  background: linear-gradient(135deg, #003b74 0%, #0057a8 50%, #0082c8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-shell {
  width: 100%;
  max-width: 1040px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: center;
}
.login-showcase { color: #fff; padding: 16px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand b { display: block; font-size: 19px; letter-spacing: .4px; }
.login-brand small { opacity: .82; font-size: 12px; }
.login-showcase h1 { margin: 0 0 12px; font-size: 30px; line-height: 1.25; }
.login-lead { margin: 0 0 24px; opacity: .9; font-size: 14px; line-height: 1.6; }
.login-features { display: grid; gap: 12px; }
.login-feat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 14px;
  padding: 12px 14px;
}
.login-feat-item span { font-size: 22px; }
.login-feat-item b { display: block; font-size: 13.5px; }
.login-feat-item small { opacity: .85; font-size: 12px; }

.login-card {
  background: #fff;
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 20, 50, .3);
}
.login-card-head h2 { margin: 0 0 4px; font-size: 22px; color: var(--ink); }
.login-form { margin-top: 18px; display: grid; gap: 14px; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 42px; }
.toggle-pw {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  font-size: 16px;
  padding: 4px 6px;
}
.login-submit { width: 100%; justify-content: center; padding: 12px; font-size: 14.5px; margin-top: 4px; }
.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b42318;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 14px;
}

.security-banner {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.pagination-btns { display: flex; gap: 6px; align-items: center; }

.mobile-nav { display: none; }

@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid2, .rbac-groups, .login-shell { grid-template-columns: 1fr; }
  .customer-toolbar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .sidebar { display: none; }
  .main { margin-left: 0; width: 100%; }
  .topbar { height: 62px; padding: 0 12px; }
  .top-title { font-size: 15px; }
  .online, .user-meta { display: none; }
  .content { padding: 12px 12px 86px; }
  .hero { padding: 18px; border-radius: 15px; }
  .hero h1 { font-size: 19px; }
  .hero-badge { display: none; }
  .cards { gap: 9px; }
  .card { padding: 13px; }
  .num { font-size: 24px; }
  .formgrid, .detail-grid, .customer-toolbar { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .quick { grid-template-columns: 1fr; }
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 66px;
    background: #fff;
    border-top: 1px solid var(--line);
    z-index: 30;
    justify-content: space-around;
    overflow-x: auto;
  }
  .mobile-nav button {
    border: 0;
    background: transparent;
    font-size: 10px;
    color: var(--muted);
    font-weight: 700;
    padding: 7px 6px;
    min-width: 56px;
  }
  .mobile-nav button.active { color: var(--primary); }
  .mobile-nav span { display: block; font-size: 19px; margin-bottom: 2px; }
}
