/* =========================================================================
   base.css — resets, typography, and the app layout shell (sidebar + header).
   ========================================================================= */

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-3);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--text);
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-h4); }
h5 { font-size: var(--fs-h5); }
h6 { font-size: var(--fs-h6); }

p { margin: 0 0 var(--sp-3); }

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

small { font-size: var(--fs-small); }

code, kbd, pre {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--text);
}

/* Slimmer, softer scrollbars to match the refined chrome */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* --- App shell layout ---------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  transition: grid-template-columns var(--dur-mid) var(--ease);
}
.app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* --- Sidebar ------------------------------------------------------------- */
.sidebar {
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
}
.sidebar__brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--green-400), var(--green-600));
  display: grid; place-items: center;
  color: var(--green-900);
  font-weight: var(--fw-bold);
  flex: none;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--green-600) 45%, transparent);
  transition: transform var(--dur-mid) var(--ease-spring),
    box-shadow var(--dur-mid) var(--ease);
}
.sidebar__brand:hover .sidebar__brand-mark {
  transform: scale(1.08) rotate(-4deg);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--green-600) 60%, transparent);
}
.sidebar__brand-name {
  font-weight: var(--fw-bold);
  letter-spacing: 0.5px;
  font-size: var(--fs-h6);
}
.app.sidebar-collapsed .sidebar__brand-name { display: none; }

.sidebar__nav {
  padding: var(--sp-3);
  overflow-y: auto;
  flex: 1;
}
.sidebar__section-label {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--fs-caption);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.app.sidebar-collapsed .sidebar__section-label { text-align: center; padding-left: 0; padding-right: 0; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  margin-bottom: 2px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
  transform: translateX(3px);
}
.nav-link:active { transform: translateX(3px) scale(0.98); }
.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}
/* left indicator pill on the active item */
.nav-link.is-active::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  height: 60%;
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transform: translateY(-50%);
  animation: nav-indicator var(--dur-mid) var(--ease-out);
}
@keyframes nav-indicator {
  from { opacity: 0; height: 0; }
  to { opacity: 1; height: 60%; }
}
.nav-link .icon { flex: none; transition: transform var(--dur-fast) var(--ease-spring); }
.nav-link:hover .icon { transform: scale(1.12); }

/* --- Sidebar account footer (signed-in operator + sign out) ------------- */
.sidebar__footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.account {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  min-width: 0;
}
.account__avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: var(--fw-semibold);
  color: var(--green-900);
  background: linear-gradient(135deg, var(--green-400), var(--green-600));
  box-shadow: 0 2px 8px color-mix(in srgb, var(--green-600) 40%, transparent);
}
.account__info { min-width: 0; }
.account__name {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-small);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account__meta { font-size: var(--fs-caption); color: var(--text-faint); }

.account__signout {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast) var(--ease);
}
.account__signout .icon { flex: none; }
.account__signout:hover {
  background: color-mix(in srgb, var(--status-danger) 12%, transparent);
  color: var(--status-danger);
  border-color: color-mix(in srgb, var(--status-danger) 40%, var(--border));
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.account__signout:active { transform: translateY(0) scale(0.98); }

/* Collapsed sidebar: show only avatar + icon */
.app.sidebar-collapsed .sidebar__footer { padding: var(--sp-2); }
.app.sidebar-collapsed .account { justify-content: center; padding: var(--sp-1); }
.app.sidebar-collapsed .account__info { display: none; }
.app.sidebar-collapsed .account__signout { justify-content: center; }
.app.sidebar-collapsed .account__signout-label { display: none; }
.app.sidebar-collapsed .nav-link__label { display: none; }
.app.sidebar-collapsed .nav-link { justify-content: center; }

/* --- Main + header ------------------------------------------------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}
.header {
  height: var(--header-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.header__spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease-spring), box-shadow var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.icon-btn:active { transform: translateY(0) scale(0.94); }

.content {
  padding: var(--sp-6);
  overflow-y: auto;
  flex: 1;
  animation: content-in var(--dur-slow) var(--ease-out);
}
@keyframes content-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.page-head h1 { font-size: var(--fs-h3); margin: 0; }
.breadcrumb {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  color: var(--text-faint);
  font-size: var(--fs-small);
  margin-bottom: var(--sp-2);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { color: var(--text-faint); }

/* --- Responsive: collapse sidebar to a drawer below tablet -------------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 60;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--dur-mid) var(--ease);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .scrim {
    position: fixed; inset: 0; background: var(--overlay);
    z-index: 55; opacity: 0; pointer-events: none;
    transition: opacity var(--dur-mid) var(--ease);
  }
  .app.sidebar-open .scrim { opacity: 1; pointer-events: auto; }
  .content { padding: var(--sp-4); }
}
@media (min-width: 901px) {
  .scrim { display: none; }
  .menu-toggle-mobile { display: none; }
}

/* --- Staggered entrance for cards/stats/rows within a page ------------- */
.content .grid > .stat,
.content .grid > .card,
.content > .grid,
.content > .card,
.content > .table-wrap {
  animation: rise-in var(--dur-slow) var(--ease-out) both;
}
.content .grid > *:nth-child(1) { animation-delay: 0.02s; }
.content .grid > *:nth-child(2) { animation-delay: 0.06s; }
.content .grid > *:nth-child(3) { animation-delay: 0.10s; }
.content .grid > *:nth-child(4) { animation-delay: 0.14s; }
.content .grid > *:nth-child(5) { animation-delay: 0.18s; }
.content .grid > *:nth-child(6) { animation-delay: 0.22s; }
@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* --- Respect reduced-motion preferences ------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .content,
  .content .grid > *,
  .content > * { animation: none !important; }
}
