:root {
  /* Brand */
  --color-primary:        #6366f1;
  --color-primary-hover:  #4f46e5;
  --color-primary-subtle: #eef2ff;
  --color-secondary:      #64748b;
  --color-success:        #10b981;
  --color-danger:         #ef4444;
  --color-warning:        #f59e0b;
  --color-info:           #06b6d4;

  /* Neutral */
  --color-dark:           #0f172a;
  --color-muted:          #94a3b8;
  --color-border:         #e2e8f0;
  --color-bg:             #f8fafc;
  --color-bg-subtle:      #f1f5f9;
  --color-surface:        #ffffff;

  /* Sidebar */
  --sidebar-width:        220px;
  --sidebar-bg:           #0f172a;
  --sidebar-text:         #94a3b8;
  --sidebar-text-active:  #ffffff;
  --sidebar-hover-bg:     rgba(255,255,255,.06);
  --sidebar-active-bg:    rgba(99,102,241,.18);
  --sidebar-active-text:  #a5b4fc;
  --sidebar-border:       rgba(255,255,255,.06);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.8125rem;
  --font-size-base: 0.9375rem;
  --font-size-lg:   1.0625rem;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semi:   600;
  --font-weight-bold:   700;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 3rem;

  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
}

/* ── Inter font ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Base reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background: var(--color-bg);
  color: var(--color-dark);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-content {
  flex: 1;
  padding: 1.75rem 2rem;
  max-width: 1400px;
  width: 100%;
}

/* ── Sidebar brand ──────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1.25rem 1rem 1rem;
  color: #fff;
  font-weight: var(--font-weight-semi);
  font-size: 1rem;
  text-decoration: none;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 0.5rem;
}
.sidebar-brand img { border-radius: var(--radius-sm); }
.sidebar-brand:hover { color: #fff; }

/* ── Sidebar nav ────────────────────────────────────────────── */
.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: var(--font-weight-semi);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(148,163,184,.5);
  padding: 1rem 1rem 0.35rem;
}

.sidebar-nav {
  list-style: none;
  padding: 0 0.5rem;
  margin: 0;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.sidebar-nav .nav-link i { font-size: 1rem; flex-shrink: 0; }
.sidebar-nav .nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: #fff;
}
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

/* Nested submenu */
.sidebar-submenu {
  list-style: none;
  margin: 0.125rem 0 0.25rem 2rem;
  padding: 0;
  border-left: 1px solid var(--sidebar-border);
}
.sidebar-submenu .nav-link {
  font-size: var(--font-size-xs);
  padding: 0.3rem 0.625rem 0.3rem 0.75rem;
  color: rgba(148,163,184,.75);
}
.sidebar-submenu .nav-link:hover { color: #fff; }

/* Collapse chevron */
.sidebar-nav .nav-link .chevron {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform .2s;
}
.sidebar-nav .nav-link[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

/* ── Sidebar bottom ─────────────────────────────────────────── */
.sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid var(--sidebar-border);
  padding: 0.75rem 0.5rem;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  transition: background .15s;
  cursor: pointer;
}
.sidebar-user:hover { background: var(--sidebar-hover-bg); color: #fff; }
.sidebar-user img, .sidebar-user .avatar-placeholder {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
}
.sidebar-user .avatar-placeholder {
  background: rgba(99,102,241,.3);
  display: flex; align-items: center; justify-content: center;
  color: var(--sidebar-active-text); font-size: 0.75rem;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar-org {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-secondary);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 1.25rem;
  font-weight: var(--font-weight-semi);
}

/* ── Tables ─────────────────────────────────────────────────── */
.table { font-size: var(--font-size-sm); }
.table thead th {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semi);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-secondary);
  border-bottom-width: 1px;
}
.table-hover tbody tr:hover { background: var(--color-bg-subtle); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn { font-weight: var(--font-weight-medium); border-radius: var(--radius-md); }
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge { font-weight: var(--font-weight-medium); border-radius: var(--radius-sm); }

/* ── Flash messages ─────────────────────────────────────────── */
.flash-message {
  border-radius: var(--radius-md);
  padding: 0.625rem 1rem;
  font-size: var(--font-size-sm);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .25s; }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-content { padding: 1rem; }
}
