:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef3f8;
  --text: #17202a;
  --muted: #64748b;
  --line: #dce4ee;
  --green: #16b75f;
  --blue: #2c7be5;
  --red: #e04f5f;
  --amber: #dd9b22;
  --sidebar: #102845;
  --sidebar-active: #1d3f69;
  --shadow: 0 18px 42px rgba(21, 32, 43, 0.1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08111d;
  --panel: #101a27;
  --panel-2: #162233;
  --text: #eff5fb;
  --muted: #91a0b5;
  --line: #223148;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}
button, input, select, textarea { font: inherit; }
button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }
button.secondary { background: var(--panel-2); border-color: var(--line); color: var(--text); }
button.blue { background: var(--blue); border-color: var(--blue); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.ghost { min-height: 32px; padding: 0 10px; background: transparent; border-color: transparent; color: var(--muted); }
button.small { min-height: 30px; padding: 0 10px; font-size: 12px; }
input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
textarea { min-height: 92px; resize: vertical; }
a { color: #77b7ff; }
.muted { color: var(--muted); }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.error-text { color: var(--red); }
.success-text { color: var(--green); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  position: relative;
  width: min(430px, 100%);
  padding: 30px 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.login-logo { width: 128px; margin: 0 0 26px; display: block; }
html[data-theme="dark"] .login-logo-light, html[data-theme="light"] .login-logo-dark { display: none; }
.login-card h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.1; }
.login-card > p { margin: 0 0 20px; color: var(--muted); }
.login-card label, .form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.login-card label { margin-top: 12px; }
.login-card button[type="submit"] { width: 100%; margin-top: 18px; }
.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  min-width: 40px;
  height: 36px;
  padding: 0 10px;
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}
.login-error { margin: 14px 0 0 !important; color: var(--red) !important; }

.shell { width: 100%; min-height: 100vh; display: flex; }
.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: 254px;
  height: 100vh;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sidebar);
  border-right: 1px solid #0a1b31;
  color: #fff;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 18px; min-height: 104px; }
.brand img { width: 170px; height: auto; display: block; }
.brand small { color: #c6ddf3; font-size: 12px; line-height: 1; text-align: center; }
.side-nav { display: grid; gap: 6px; }
.side-nav button {
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #d8e8f7;
  font-weight: 500;
  text-align: left;
}
.side-nav button:hover, .side-nav button.active { background: var(--sidebar-active); color: #fff; filter: none; }
.nav-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; font-size: 16px; line-height: 1; }
.nav-chevron { margin-left: auto; font-size: 11px; }
.nav-group { display: grid; gap: 4px; margin: -2px 0 2px 18px; padding-left: 8px; border-left: 1px solid #33547a; }
.nav-group button { min-height: 29px; font-size: 12px; }
.sidebar-credit { margin-top: auto; color: #c6ddf3; font-size: 12px; line-height: 1.25; text-align: center; }
.sidebar-credit span { display: block; }
.sidebar-credit span + span { margin-top: 5px; font-size: 11px; white-space: nowrap; }

.content { width: calc(100% - 254px); min-height: 100vh; margin-left: 254px; padding: 20px 24px 64px; min-width: 0; }
.topbar { height: 40px; display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.search-wrap { flex: 1; position: relative; }
.top-search {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}
.top-search input { min-height: 34px; padding: 0; border: 0; background: transparent; }
.top-search input:focus-visible { outline: 0; }
.search-results {
  position: absolute;
  z-index: 50;
  top: 46px;
  inset-inline: 0;
  max-height: 350px;
  overflow: auto;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.search-result { width: 100%; display: grid; gap: 2px; padding: 9px 10px; background: transparent; border: 0; color: var(--text); text-align: left; }
.search-result span { color: var(--muted); font-size: 12px; }
.icon-button { width: 40px; min-width: 40px; padding: 0; background: var(--panel); border-color: var(--line); color: var(--text); }
.profile { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.profile > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: #1d3f69; color: #fff; font-weight: 700; }
.profile strong, .profile small { display: block; }
.profile small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.title-row h1 { margin: 0 0 6px; font-size: 26px; }
.title-row p { margin: 0; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; }
.status-strip { margin-bottom: 16px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.metric { min-height: 108px; padding: 16px; display: flex; align-items: center; gap: 12px; }
.metric-icon { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border-radius: 8px; font-weight: 800; }
.metric-icon.green { background: rgba(22,183,95,.18); color: var(--green); }
.metric-icon.blue { background: rgba(44,123,229,.18); color: var(--blue); }
.metric-icon.amber { background: rgba(221,155,34,.18); color: var(--amber); }
.metric-icon.red { background: rgba(224,79,95,.18); color: var(--red); }
.metric span, .metric small { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 7px 0 3px; color: var(--text); font-size: 23px; line-height: 1; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 16px; }
.panel { padding: 16px; min-width: 0; }
.panel-head { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.audit-feed { display: grid; gap: 8px; }
.audit-item { display: grid; grid-template-columns: 10px minmax(0,1fr) auto; gap: 10px; align-items: start; padding: 9px 0; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--blue); }
.audit-item strong, .audit-item span { display: block; }
.audit-item span, .audit-item time { color: var(--muted); font-size: 12px; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 120px; gap: 10px; padding: 12px; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.toolbar.two { grid-template-columns: minmax(220px, 1fr) 180px; }
.table-card { overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; background: var(--panel); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--panel-2); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(44,123,229,.08); }
tbody tr:last-child td { border-bottom: 0; }
.table-name strong, .table-name span { display: block; }
.table-name span { margin-top: 3px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-weight: 700; font-size: 11px; text-transform: capitalize; }
.badge.active { background: rgba(22,183,95,.16); color: #54d98e; }
.badge.joiner { background: rgba(44,123,229,.18); color: #77b7ff; }
.badge.leaver { background: rgba(224,79,95,.16); color: #ff8995; }
.badge.inactive { background: rgba(145,160,181,.15); color: var(--muted); }
.link-out { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 14px; }
.settings-card { padding: 18px; }
.settings-card h2 { margin: 0 0 8px; font-size: 16px; }
.settings-card p { min-height: 40px; margin: 0 0 16px; color: var(--muted); line-height: 1.45; }
.role-list { display: grid; gap: 10px; margin-top: 16px; }
.role-row { padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; }
.role-row strong, .role-row span { display: block; }
.role-row span { margin-top: 4px; color: var(--muted); font-size: 12px; }

.drawer-backdrop { position: fixed; z-index: 70; inset: 0; background: rgba(0,0,0,.48); }
.drawer {
  position: fixed;
  z-index: 80;
  top: 0;
  right: 0;
  width: min(540px, 100%);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 42px rgba(0,0,0,.24);
}
.drawer-head { padding: 18px 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0 0 5px; font-size: 20px; }
.drawer-head p { margin: 0; color: var(--muted); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-actions { padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); background: var(--panel-2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label span { color: var(--text); font-size: 12px; }
.drawer-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.drawer-section h3 { margin: 0 0 10px; font-size: 14px; }
.access-chip-list { display: flex; flex-wrap: wrap; gap: 7px; }
.access-chip { padding: 6px 9px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 12px; }
.audit-detail { margin: 0; padding: 12px; overflow: auto; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; color: var(--text); font: 12px/1.5 Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .sidebar { width: 84px; }
  .content { width: calc(100% - 84px); margin-left: 84px; }
  .brand { min-height: 72px; }
  .brand img, .brand small, .side-nav button > span:not(.nav-icon), .nav-chevron, .sidebar-credit { display: none; }
  .side-nav button { justify-content: center; }
  .nav-group { margin-left: 0; padding-left: 0; border-left: 0; }
  .profile div { display: none; }
  .toolbar, .toolbar.two { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .sidebar { display: none; }
  .content { width: 100%; margin-left: 0; padding: 14px 12px 50px; }
  .topbar { height: auto; flex-wrap: wrap; }
  .search-wrap { min-width: 100%; order: 2; }
  .profile { margin-left: auto; }
  .title-row { align-items: stretch; flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .settings-grid, .toolbar, .toolbar.two, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .drawer-actions { align-items: stretch; flex-direction: column-reverse; }
  .drawer-actions > div { width: 100%; display: flex; gap: 8px; }
  .drawer-actions button { flex: 1; }
}
