:root {
  --color-bg: #f9f9f9;
  --color-surface: #ffffff;
  --color-text: #2d2d2d;
  --color-text-muted: #6b6b6b;
  --color-border: #e8e8e8;

  --color-primary: #eb6800;
  --color-primary-hover: #bd5400;
  --color-primary-active: #963f00;

  --color-online: #2e7d32;
  --color-danger: #c73326;
  --color-danger-bg: #fbdfde;

  --sidebar-width: 240px;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The [hidden] attribute loses to any author rule that sets its own
   `display` (e.g. .card-grid's `display: grid`), since author styles beat
   user-agent defaults regardless of specificity. Force it to always win. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Sidebar: fixed to the left, white, full height on every page so
   navigation and session state stay in the same place throughout the app. */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 20;
  transition: transform 0.2s ease;
}

body.sidebar-collapsed .sidebar { transform: translateX(-100%); }

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem 1rem;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}

.sidebar-toggle:hover { background: var(--color-bg); }
.sidebar-toggle svg { width: 18px; height: 18px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--color-text);
  min-width: 0;
}

.sidebar-brand svg {
  width: 22px;
  height: 22px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.sidebar-brand-title { font-weight: 800; font-size: 0.95rem; line-height: 1.2; white-space: nowrap; }
.sidebar-brand-subtitle { font-size: 0.75rem; color: var(--color-text-muted); white-space: nowrap; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  border-left: 3px solid transparent;
}

.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-link:hover { background: var(--color-bg); }

.sidebar-link.active {
  background: var(--color-bg);
  color: var(--color-primary);
  font-weight: 700;
  border-left-color: var(--color-primary);
}

@supports (background: color-mix(in srgb, red 10%, white)) {
  .sidebar-link.active {
    background: color-mix(in srgb, var(--color-primary) 10%, white);
  }
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-byline { font-size: 0.75rem; color: var(--color-text-muted); }

/* Floating button that reopens a collapsed sidebar */
.sidebar-reopen {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 21;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  color: var(--color-text);
  cursor: pointer;
}

.sidebar-reopen svg { width: 18px; height: 18px; }
body.sidebar-collapsed .sidebar-reopen { display: flex; }

/* Content area reserves space for the fixed sidebar, then centers its
   content within whatever space remains rather than hugging the sidebar. */
.content-area {
  margin-left: var(--sidebar-width);
  padding: 2.5rem 2rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: margin-left 0.2s ease;
}

.content-area > * {
  width: 100%;
  max-width: 900px;
}

body.sidebar-collapsed .content-area { margin-left: 0; }

@media (max-width: 640px) {
  .sidebar { box-shadow: 2px 0 16px rgba(0, 0, 0, 0.12); }
  .content-area,
  body.sidebar-collapsed .content-area { margin-left: 0; padding: 1.5rem 1.25rem 2rem; }
}

.hero { margin-bottom: 2rem; }
.hero h1 { font-size: 1.75rem; font-weight: 800; margin: 0 0 0.5rem; }
.hero p { color: var(--color-text-muted); margin: 0; }

/* Gradient hero banner for the app-selection landing page */
.hero-banner {
  background: linear-gradient(135deg, var(--color-primary), #ff8712);
  color: #fff;
  border-radius: 16px;
  padding: 2.5rem;
  margin-bottom: 2rem;
}

.hero-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.85;
  margin-bottom: 0.5rem;
}

.hero-banner h1 { font-size: 2rem; font-weight: 800; margin: 0 0 0.5rem; color: #fff; }
.hero-banner p { color: rgba(255, 255, 255, 0.92); margin: 0; max-width: 520px; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.app-card h3 {
  margin: 0.75rem 0 0.25rem;
  font-size: 1.1rem;
}

.app-card p {
  margin: 0 0 1rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* Apps are data-driven (see apps.json) and can carry an arbitrary --accent
   color; color-mix derives a tint so no per-app CSS is ever needed. */
.app-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--color-bg);
  color: var(--accent, var(--color-primary));
}

.badge-accent {
  background: var(--color-bg);
  color: var(--accent, var(--color-primary));
}

@supports (background: color-mix(in srgb, red 10%, white)) {
  .app-icon,
  .badge-accent {
    background: color-mix(in srgb, var(--accent, var(--color-primary)) 16%, white);
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-outline:hover { background: var(--color-bg); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }

/* Account panel */
.account-panel dt {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.75rem;
}
.account-panel dd { margin: 0.15rem 0 0; }
.account-panel dd .badge { margin: 0.15rem 0.3rem 0.15rem 0; }

/* Loading skeleton */
.skeleton {
  display: inline-block;
  height: 0.9em;
  width: 140px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--color-border) 25%, #eef1f4 37%, var(--color-border) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
}

@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Status page (unauthorized, protected app placeholders) */
.status-page {
  text-align: center;
  padding: 3rem 1.5rem;
}

.status-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  color: var(--accent, var(--color-primary));
}

.status-icon svg { width: 28px; height: 28px; }
.status-icon.danger { color: var(--color-danger); }

@supports (background: color-mix(in srgb, red 10%, white)) {
  .status-icon {
    background: color-mix(in srgb, var(--accent, var(--color-primary)) 16%, white);
  }
  .status-icon.danger {
    background: color-mix(in srgb, var(--color-danger) 16%, white);
  }
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
}

.status-dot.online { background: var(--color-online); }

.nav-link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.nav-link:hover { text-decoration: underline; }
