/* ==========================================================================
   Shared app shell — sidebar, header, footer, and common primitives.
   Loaded on every page; page-specific styles live in each view's own
   `styles` section so they never leak across pages.
   ========================================================================== */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
}

.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon { font-size: 1.5rem; }
.brand-title { font-size: .95rem; font-weight: 700; color: #fff; }
.brand-sub { font-size: .7rem; color: #9ca3af; }

.sidebar-nav { padding: 1rem .75rem; display: flex; flex-direction: column; gap: .15rem; }
.nav-label {
  font-size: .68rem;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 0 .6rem;
  margin-bottom: .4rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .6rem .65rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #d1d5db;
  font-size: .85rem;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: #4f6ef7; color: #fff; }
.nav-icon { font-size: .95rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.nav-text { flex: 1; }
.nav-count {
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: .1rem .45rem;
  border-radius: 99px;
  min-width: 1.4rem;
  text-align: center;
}
.nav-item.active .nav-count { background: rgba(255,255,255,.25); }

.sidebar-divider { height: 1px; background: rgba(255,255,255,.08); margin: .25rem 1rem; }

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user { display: flex; align-items: center; gap: .65rem; margin-bottom: .85rem; }
.sidebar-user .avatar-circle { background: #4f6ef7; color: #fff; }
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
  font-size: .84rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: .72rem; color: #9ca3af;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-signout {
  width: 100%;
  padding: .5rem;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  background: transparent;
  color: #d1d5db;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-signout:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── Main column ── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.main-topbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 1rem 1.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.main-topbar-heading { flex-shrink: 0; }
.main-topbar h1 { font-size: 1.25rem; font-weight: 700; }
.main-topbar .page-sub { font-size: .82rem; color: #6b7280; margin-top: .1rem; }
.main-topbar-actions { display: flex; align-items: center; gap: .75rem; margin-left: auto; flex-wrap: wrap; }

.hamburger {
  display: none;
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  color: #374151;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.main-content { flex: 1; padding: 1.5rem 1.75rem 2.5rem; }

.app-footer {
  padding: 1.25rem 1.75rem 1.75rem;
  text-align: center;
  font-size: .76rem;
  color: #9ca3af;
}

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 20;
}

/* Responsive: collapse sidebar into an off-canvas drawer */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .hamburger { display: inline-flex; }
  .main-topbar { padding: .85rem 1rem; }
  .main-content { padding: 1.25rem .75rem 2rem; }
}

/* ── Shared primitives ── */
.avatar-circle {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #e0e7ff;
  color: #3730a3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 700;
}

.status {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.spinner, .spinner-inline, .spinner-page {
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner-inline, .spinner-page { display: inline-block; }
/* .spinner defaults hidden — pages toggle it to inline-block/block via JS or an inline style */
.spinner { display: none; width: 17px; height: 17px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; }
.spinner-inline { width: 20px; height: 20px; border: 2px solid #e5e7eb; border-top-color: #4f6ef7; vertical-align: middle; }
.spinner-page { width: 22px; height: 22px; border: 2px solid #e5e7eb; border-top-color: #4f6ef7; }
@keyframes spin { to { transform: rotate(360deg); } }

.state-box { text-align: center; padding: 3rem 1rem; color: #9ca3af; }
.state-box .icon { font-size: 2.2rem; margin-bottom: .6rem; }
.state-box p { font-size: .95rem; }
.state-box a { color: #4f6ef7; font-weight: 600; text-decoration: none; }
.state-box a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── Toast notification ── */
#toast {
  position: fixed;
  /* Clears CI4's debug-bar icon (36px tall, pinned bottom-right in dev) so the
     toast is never sat on top of; harmless spacing in production. */
  bottom: 3.25rem;
  right: 1.5rem;
  background: #111827;
  color: #fff;
  padding: .7rem 1.2rem;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  /* Above the debug toolbar (z-index 10000) so it is never covered. */
  z-index: 10001;
  max-width: 320px;
  /* Hidden state uses opacity+visibility rather than a translate alone: a
     percentage translate is relative to the toast's own height, which is not
     guaranteed to exceed its `bottom` offset, so it used to leave a sliver
     of the toast visible at the bottom of the screen. pointer-events:none
     keeps the hidden box from swallowing clicks in that corner. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(.75rem);
  transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
#toast.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}
#toast.toast-ok  { background: #065f46; }
#toast.toast-err { background: #991b1b; }

/* ==========================================================================
   Auth card — shared by the login overlay (auth.js) and standalone auth
   pages (e.g. reset-password) so both look like one system.
   ========================================================================== */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 32px rgba(0,0,0,.12);
  padding: 2.25rem 2rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.auth-icon { font-size: 2rem; margin-bottom: .5rem; }
.auth-title { font-size: 1.2rem; font-weight: 700; color: #111; margin-bottom: .35rem; }
.auth-sub { font-size: .85rem; color: #6b7280; margin-bottom: 1.5rem; }

.auth-msg { min-height: 1.3rem; margin-bottom: .5rem; font-size: .86rem; word-break: break-word; overflow-wrap: break-word; }
.auth-msg.error   { color: #dc2626; }
.auth-msg.info    { color: #6b7280; }
.auth-msg.success { color: #059669; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1.25rem 0;
  color: #9ca3af;
  font-size: .78rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.auth-form { text-align: left; display: flex; flex-direction: column; }
.auth-form label {
  font-size: .74rem;
  font-weight: 600;
  color: #555;
  margin-top: .75rem;
  margin-bottom: .3rem;
  display: block;
}
.auth-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: .75rem;
}
.auth-label-row label { margin-top: 0; }
.auth-label-row a { font-size: .74rem; color: #4f6ef7; font-weight: 600; text-decoration: none; }
.auth-label-row a:hover { text-decoration: underline; }

.auth-form input {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  font-size: .9rem;
  color: #111;
  transition: border-color .2s;
}
.auth-form input:focus { outline: none; border-color: #4f6ef7; }

.auth-btn-primary {
  width: 100%;
  margin-top: 1.1rem;
  padding: .65rem;
  background: #4f6ef7;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: background .2s, opacity .2s;
}
.auth-btn-primary:hover:not(:disabled) { background: #3a57d4; }
.auth-btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.auth-switch { margin-top: 1.1rem; font-size: .82rem; color: #6b7280; }
.auth-switch a { color: #4f6ef7; font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.auth-footnote { margin-top: 1.25rem; font-size: .75rem; color: #9ca3af; }

.google-btn-wrap { display: flex; justify-content: center; }

.auth-status-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.auth-status-title { font-size: 1.1rem; font-weight: 700; margin-bottom: .75rem; }
.auth-status-msg { font-size: .9rem; color: #374151; line-height: 1.6; margin-bottom: 1.5rem; }

.auth-btn-secondary {
  background: #f3f4f6;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.4rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  color: #374151;
}
.auth-btn-secondary:hover { background: #e5e7eb; }
