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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #252836;
  --border: #2a2d3a;
  --text: #e4e6ed;
  --text-muted: #a1a5b8;
  --accent: #6c8cff;
  --accent-hover: #8ba4ff;
  --accent-subtle: rgba(108, 140, 255, 0.12);
  --radius: 10px;
  --sidebar-w: 240px;
  --content-max: 1120px;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

body {
  min-height: 100dvh;
}

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

a:hover {
  color: var(--accent-hover);
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 6px 6px;
  font-size: 0.875rem;
  z-index: 1100;
}

.skip-link:focus {
  top: 0;
}

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
}

.app-shell.no-sidebar {
  grid-template-columns: 1fr;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 60;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-brand:hover {
  color: var(--text);
}

.sidebar-brand strong {
  color: var(--text);
}

.brand-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  min-height: 2.5rem;
  transition: background 0.12s, color 0.12s;
  width: 100%;
  font-family: inherit;
}

.sidebar-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-link.active svg {
  color: var(--accent);
}

.sidebar-footer {
  padding: 0.5rem 0.5rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem 0.75rem;
  min-width: 0;
}

.sidebar-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.sidebar-user-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-user-name {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-email {
  font-size: 0.7rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-signout {
  margin-top: 0.25rem;
}

.sidebar-overlay {
  display: none;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 3.5rem;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: var(--text-muted);
}

.topbar-brand:hover {
  color: var(--text);
}

.topbar-brand strong {
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  min-height: 2.5rem;
  min-width: 2.5rem;
  align-items: center;
  justify-content: center;
}

.nav-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  min-height: 2.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-large {
  padding: 0.7rem 2rem;
  font-size: 1rem;
}

/* Content */
.content {
  padding: 2rem 2rem 3rem;
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
}

.content-footer {
  padding: 1rem 2rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  text-align: center;
}

.page {
  display: flex;
  flex-direction: column;
}

/* Greeting */
.greeting {
  padding: 0 0 0.5rem;
}

.greeting h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
}

.greeting p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* Login hero (unauthenticated) */
.login-hero {
  text-align: center;
  padding: 2.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

/* Quick Cards */
.quick-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.quick-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-hover) 100%);
  border: 1px solid color-mix(in srgb, var(--accent) 15%, var(--border));
  border-radius: var(--radius);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.quick-card:hover {
  background: var(--surface-hover);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.qicon {
  flex-shrink: 0;
  color: var(--accent);
}

.qtext .name {
  font-weight: 600;
  font-size: 0.9rem;
}

.qtext .desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Section Label */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  margin-top: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Service Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 1.1rem;
  min-height: 2.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.tile:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.tile .icon {
  color: var(--text-muted);
}

.tile .name {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.ext-icon {
  opacity: 0.4;
}

.tile .desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Admin */
.admin-layout {
  gap: 1.5rem;
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.admin-nav a {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.admin-nav a:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.admin-nav a.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.admin-page h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.placeholder {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-top: 1rem;
}

.placeholder-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.placeholder-text {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.placeholder-sub {
  font-size: 0.8rem;
}

/* Error banner */
.error-banner {
  background: #3a1c1c;
  color: #f8b4b4;
  border: 1px solid #5a2d2d;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* Loading */
.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 0;
}

.loading::before {
  content: "";
  display: block;
  width: 24px;
  height: 24px;
  margin: 0 auto 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Focus — visible ring for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.quick-card:focus-visible,
.tile:focus-visible {
  background: var(--surface-hover);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.btn-primary:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.sidebar-link:focus-visible,
.nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Responsive */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.3);
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .topbar {
    padding: 0.65rem 1rem;
  }

  .content {
    padding: 1.5rem 1rem 2rem;
  }

  .content-footer {
    padding: 1rem 1rem 1.5rem;
    text-align: center;
  }
}

@media (max-width: 600px) {
  .greeting h2 {
    font-size: 1.4rem;
  }

  .quick-row {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .login-hero {
    padding: 1.5rem 1rem;
  }
}
