/* ============================================================================
   static/css/base.css
   ========================================================================== */
/* ============================================================================
   BASE.CSS
   Global tokens, resets, layout shell, topbar, generic utilities & components.
   This file should be included on every page.
   ========================================================================== */

/* 1) Design Tokens (CSS Custom Properties) */
:root {
  --color-primary: #292661;   /* deep indigo (inverted bars) */
  --color-secondary: #313845; /* slate (content accents) */
  --color-accent: #a3adbf;    /* muted steel */
  --color-bg: #ffffff;        /* content cards bg */
  --color-bg-2: #f6f8fc;      /* app shell bg */

  --color-text: #111827;      /* content text */
  --color-text-dim: #4b5563;  /* content text dim */

  --radius-xl: 16px;
  --radius-lg: 12px;

  --shadow-1: 0 8px 20px rgba(0,0,0,0.07);
  --shadow-2: 0 10px 30px rgba(0,0,0,0.10);
  --ring: 0 2px 8px rgba(0,0,0,0.10);

  --transition-fast: 180ms cubic-bezier(.2,.8,.2,1);
  --transition-slow: 300ms cubic-bezier(.2,.8,.2,1);

  --sidebar-w: 210px;
  --sidebar-w-collapsed: 80px;
  --topbar-h: 64px;

  --shell-pad: clamp(10px, 2.2vw, 18px);
  --gap: 12px;
}

/* 2) Resets */
* { box-sizing: border-box; }
html, body { height: 100%; background: var(--color-bg-2); }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--color-text);
}

/* 3) Shell & App Layout */
.shell { min-height: 100vh; height: 100dvh; padding: var(--shell-pad); }

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  gap: var(--gap);
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  transition: grid-template-columns var(--transition-slow);
}

.topbar { grid-area: topbar; min-width: 0; }
.sidebar { grid-area: sidebar; min-height: 0; min-width: 0; }
.content-area {
  grid-area: content;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 20px;
  position: relative;
}

/* 4) Cards & Buttons */
.card { background: var(--color-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-1); }

.btn { cursor: pointer; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.btn-primary { background: var(--color-primary); color: #fff;}
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-secondary { background: var(--color-secondary); color: #fff; }
.btn:active { transform: translateY(1px); }

.muted { color: var(--color-text-dim); }
.chip { background: #eceff6; color: #374151; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.icon { width: 20px; height: 20px; color: currentColor; }
.icon-lg { width: 24px; height: 24px; }

/* 5) Inverted Topbar (dark bg, white content) */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  background: var(--color-primary);
  border: 1px solid rgba(255,255,255,0.08);
  height: var(--topbar-h);
  padding: 0 16px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-1);
  color: #fff;
  overflow: visible;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand-toggle {
  width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,0.16);
  display: grid; place-items: center; box-shadow: var(--shadow-1);
  border: none; cursor: pointer;
}
.brand-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.brand-toggle svg { width: 22px; height: 22px; color: #fff; }
.brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .2px;
  color: #fff;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .chip { background: rgba(255,255,255,0.18); color: #fff; }

.topbar-right { margin-left: auto; display:flex; align-items:center; gap: 12px; flex: 0 0 auto; }
.topbar-actions { display:flex; align-items:center; gap: 8px; }
.topbar-action { white-space: nowrap; }
.topbar-form { margin: 0; display: inline-flex; }
.topbar-actions .btn-ghost { color: #fff; border: 1px solid rgba(255,255,255,0.24); }
.topbar-actions .btn-ghost:hover { background: rgba(255,255,255,0.10); }
.topbar-actions .btn-primary { background: #fff; color: var(--color-primary); }

.topbar-user {
  position: relative;
  display: flex;
  align-items: center;
}

.topbar-user__trigger {
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: rgba(255,255,255,0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    background var(--transition-fast),
    box-shadow var(--transition-fast);
}

.topbar-user__trigger:hover,
.topbar-user.is-open .topbar-user__trigger {
  background: rgba(255,255,255,0.14);
  box-shadow: 0 12px 24px rgba(0,0,0,0.18);
  transform: translateY(-1px);
}

.topbar-user__trigger:focus-visible {
  outline: 2px solid rgba(255,255,255,0.9);
  outline-offset: 2px;
}

.topbar-user__avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.38), transparent 45%),
    linear-gradient(145deg, rgba(255,255,255,0.2), rgba(11,19,41,0.4));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}

.topbar-user__avatar::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #c5cedd;
  border: 2px solid var(--color-primary);
}

.topbar-user.is-authenticated .topbar-user__avatar::after {
  background: #39d98a;
}

.topbar-user__avatar--large {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  flex: 0 0 auto;
}

.topbar-user__avatar--large::after {
  width: 11px;
  height: 11px;
  right: 4px;
  bottom: 4px;
  border-color: #ffffff;
}

.topbar-user__avatar-fallback {
  width: 22px;
  height: 22px;
  display: inline-flex;
}

.topbar-user__avatar--large .topbar-user__avatar-fallback {
  width: 28px;
  height: 28px;
}

.topbar-user__avatar-fallback svg {
  width: 100%;
  height: 100%;
}

.topbar-user__avatar-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topbar-user__menu {
  position: absolute;
  top: calc(100% + 14px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid rgba(17,24,39,0.08);
  background:
    linear-gradient(180deg, rgba(255,255,255,1) 0%, rgba(246,248,252,1) 100%);
  box-shadow: 0 24px 60px rgba(17,24,39,0.22);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px) scale(0.98);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast),
    visibility var(--transition-fast);
}

.topbar-user__menu::before {
  content: "";
  position: absolute;
  top: -8px;
  right: 18px;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border-top: 1px solid rgba(17,24,39,0.08);
  border-left: 1px solid rgba(17,24,39,0.08);
  transform: rotate(45deg);
}

.topbar-user.is-open .topbar-user__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.topbar-user__summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(17,24,39,0.08);
}

.topbar-user__details {
  min-width: 0;
}

.topbar-user__name,
.topbar-user__email {
  margin: 0;
}

.topbar-user__name {
  font-size: 15px;
  font-weight: 800;
  color: var(--color-text);
}

.topbar-user__email {
  margin-top: 4px;
  min-height: 1.2em;
  font-size: 13px;
  color: var(--color-text-dim);
  word-break: break-word;
}

.topbar-user__email.is-empty::before {
  content: "\00a0";
}

.topbar-user__menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-user__status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3b4283;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar-user__action {
  min-width: 108px;
}

.topbar-user__action--logout {
  background: #ffffff;
  color: var(--color-text);
  border: 1px solid rgba(17,24,39,0.12);
  box-shadow: none;
}

.topbar-user__action--logout:hover {
  background: #f8fafc;
}

/* 6) Responsive Tweaks */
@media (max-width: 1200px) {
  :root{ --sidebar-w: 260px; --sidebar-w-collapsed: 78px; }
}
@media (max-width: 980px) {
  .topbar .chip { display: none; }
  .topbar-action--secondary { display: none; }
}
@media (max-width: 760px) {
  .topbar-right { gap: 8px; }
  .topbar-actions { gap: 6px; }
  .topbar-action--primary {
    padding: 0.45rem 0.85rem;
    font-size: 13px;
  }
  .topbar-user__trigger {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }
  .topbar-user__avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }
  .brand-name { font-size: 16px; }
}
@media (max-width: 560px) {
  .topbar {
    padding: 0 10px;
  }

  .topbar-right {
    gap: 6px;
  }

  .topbar-action--primary {
    padding: 0.42rem 0.72rem;
    font-size: 12px;
  }

  .topbar-user__menu {
    width: min(300px, calc(100vw - 20px));
    right: -2px;
  }
}
@media (max-width: 720px) {
  :root{ --shell-pad: 8px; --gap: 10px; }
}

@media (max-height: 860px) {
  :root { --topbar-h: 56px; --shell-pad: 8px; --gap: 8px; }

  .topbar { padding: 0 12px; }
  .brand-name { font-size: 16px; }
  .topbar .chip { display: none; }

  .topbar .btn {
    padding: 0.4rem 0.75rem;
    font-size: 13px;
  }
}
a.btn,
button.btn {
  display: inline-flex;         /* consistent layout */
  align-items: center;          /* vertical centering */
  justify-content: center;      /* horizontal centering */
  padding: 0.5rem 1rem;         /* same spacing */
  font-size: 14px;              /* lock in font size */
  line-height: 1.2;             /* avoid inherited line-height issues */
  border: none;                 /* buttons already have this, links don’t */
  text-decoration: none;        /* remove underline */
  cursor: pointer;              /* make link behave like button */
}

/* remove padding for specific pages */
.content-area.no-pad { padding: 0; }


/* ── Impersonation banner ────────────────────────────────────────────────── */
.impersonate-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #fef3c7;
  border-bottom: 2px solid #f59e0b;
  font-size: 13px;
  font-weight: 600;
  color: #92400e;
}

.impersonate-bar__btn {
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid rgba(245,158,11,.45);
  background: #fff;
  color: #92400e;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease;
}
.impersonate-bar__btn:hover { background: #fffbeb; }
