/* CapitalXB design system.
   Clean white light theme + refined deep-navy dark theme.
   Inter + Material Symbols, primary #135bec, soft layered shadows,
   class-based dark mode (html.dark). */

:root {
  --primary: #135bec;
  --primary-hover: #0f4fd4;
  --primary-soft: rgba(19, 91, 236, .10);
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eef1f6;
  --border: #e9edf3;
  --border-strong: #dde3ea;
  --text: #0d1526;
  --muted: #667085;
  --head: #0a1020;
  --chart-grid: #eef1f6;
  --tooltip-bg: #0f172a;
  --tooltip-fg: #ffffff;
  --success: #047857;
  --success-bg: #e7f7ee;
  --warning: #b45309;
  --warning-bg: #fdf3e3;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .04);
  --shadow-lg: 0 14px 34px rgba(16, 24, 40, .12), 0 4px 10px rgba(16, 24, 40, .05);
  --radius: .625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --glow: radial-gradient(1200px 500px at 50% -200px, rgba(19, 91, 236, .05), transparent 70%);
  color-scheme: light;
}

html.dark {
  --primary: #5b8dff;
  --primary-hover: #7aa2ff;
  --primary-soft: rgba(91, 141, 255, .16);
  --bg: #0a0e16;
  --surface: #10151f;
  --surface-2: #161d29;
  --surface-3: #1d2433;
  --border: #212a38;
  --border-strong: #2c3848;
  --text: #e7edf6;
  --muted: #93a1b5;
  --head: #f4f7fc;
  --chart-grid: rgba(148, 163, 184, .12);
  --tooltip-bg: #1d2433;
  --tooltip-fg: #e7edf6;
  --success: #34d399;
  --success-bg: rgba(16, 185, 129, .14);
  --warning: #fbbf24;
  --warning-bg: rgba(217, 119, 6, .18);
  --danger: #f87171;
  --danger-bg: rgba(220, 38, 38, .18);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
  --glow: radial-gradient(1200px 520px at 50% -220px, rgba(91, 141, 255, .12), transparent 72%);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--glow);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  line-height: 1; vertical-align: middle;
}
.material-symbols-outlined.filled { font-variation-settings: 'FILL' 1; }

a { color: inherit; text-decoration: none; }
::selection { background: var(--primary-soft); }

/* ── Header ── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  height: 66px; padding: 0 28px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header .left { display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 11px; }

/* Logo: purple wordmark in light mode, white in dark mode; green bar always. */
.brand-logo { display: block; width: auto; color: #312b6b; }
html.dark .brand-logo { color: #ffffff; }
.brand .brand-logo { height: 30px; }
.auth-logo .brand-logo { height: 46px; margin: 0 auto; }
.error-logo .brand-logo { height: 30px; margin: 0 auto 18px; }
.header-divider { width: 1px; height: 26px; background: var(--border); }
.header-actions { display: flex; align-items: center; gap: 9px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.theme-icon-sun { display: none; }
html.dark .theme-icon-sun { display: inline; }
html.dark .theme-icon-moon { display: none; }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 9px 5px 5px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.user-chip:hover { border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.avatar {
  width: 30px; height: 30px; border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), #3b7bff); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .74rem; font-weight: 700;
}
.user-chip .meta { line-height: 1.15; }
.user-chip .meta .name { font-size: .78rem; font-weight: 650; color: var(--text); }
.user-chip .meta .role { font-size: .65rem; color: var(--muted); text-transform: capitalize; }

/* ── Nav ── */
.app-nav { display: flex; align-items: center; gap: 4px; }
.nav-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; color: var(--muted);
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius);
  font-size: .82rem; font-weight: 650; cursor: pointer;
  border: 1px solid transparent; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px color-mix(in srgb, var(--primary) 40%, transparent); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 35%, transparent); transform: translateY(-1px); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(.97); }
.btn-sm { padding: 6px 11px; font-size: .74rem; }

/* ── Forms ── */
input, select, textarea {
  font-family: inherit; font-size: .84rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--primary-soft);
}

/* ── Cards ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

/* ── Page shell ── */
.page { max-width: 1440px; margin: 0 auto; padding: 28px 28px 44px; }
.page-title { font-size: 1.4rem; font-weight: 780; color: var(--head); letter-spacing: -.02em; }
.page-sub { font-size: .84rem; color: var(--muted); margin-top: 4px; }

/* ── Tables ── */
.table-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
thead th {
  background: var(--surface-2); color: var(--muted); text-align: left;
  padding: 12px 16px; font-weight: 650; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: .7rem; font-weight: 650;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ── Flash messages ── */
.flash-stack { display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.flash {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 15px; border-radius: var(--radius);
  font-size: .82rem; font-weight: 550; border: 1px solid transparent;
  box-shadow: var(--shadow-xs);
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }

/* ── Dropdown menu ── */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 10px);
  min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 7px; z-index: 60;
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transform-origin: top right; transition: opacity .14s, transform .14s;
}
.menu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.menu .menu-head { padding: 9px 11px; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.menu .menu-head .name { font-size: .82rem; font-weight: 650; color: var(--text); }
.menu .menu-head .email { font-size: .72rem; color: var(--muted); margin-top: 1px; word-break: break-all; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border-radius: var(--radius); border: none;
  background: transparent; color: var(--text); font-size: .82rem; font-weight: 550;
  cursor: pointer; text-align: left; transition: background .12s;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.menu .danger { color: var(--danger); }

/* ── Admin add-user form ── */
.user-add-form { display: grid; grid-template-columns: 1.4fr 1fr .7fr auto; gap: 10px; align-items: end; }
.table-scroll { overflow-x: auto; }

/* ── Responsive ── */
@media (max-width: 760px) {
  .app-header { padding: 0 16px; }
  .app-nav { display: none; }
  .header-divider { display: none; }
  .user-chip .meta { display: none; }
  .header-actions { gap: 6px; }
  .page { padding: 20px 16px 36px; }
}
@media (max-width: 720px) {
  .user-add-form { grid-template-columns: 1fr; }
  .user-add-form .btn { width: 100%; justify-content: center; }
}

/* ── Footer ── */
.app-footer {
  text-align: center; padding: 24px; font-size: .74rem; color: var(--muted);
  border-top: 1px solid var(--border); margin-top: 8px;
}
