/* App shell: sidebar, top bar, mobile drawer, login and error layouts. */

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

/* --- sidebar ------------------------------------------------------------------------------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 30;
  display: flex; flex-direction: column; gap: 22px; padding: 20px 14px;
  background: var(--bg-1); border-right: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--text-1); }
.brand:hover { color: var(--text-1); }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto; display: grid; place-items: center;
  font-weight: 800; font-size: 13px; color: var(--text-on-accent);
  background: linear-gradient(135deg, #5ee6a8, #2bb87a); box-shadow: 0 6px 18px rgba(62, 207, 142, 0.35);
}
.brand-name { font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; }

.nav { display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); padding: 0 10px 6px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 10px;
  border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; text-decoration: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text-1); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--text-1); }
.nav-link[aria-current="page"] .icon { color: var(--accent); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent); box-shadow: 0 0 12px var(--accent);
}

.sidebar-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-1);
}
.sidebar-user .who { line-height: 1.25; min-width: 0; }
.sidebar-user .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sidebar-user .who small { color: var(--text-3); font-size: var(--fs-xs); }
.sidebar-user form { margin: 0 0 0 auto; }
.icon-button {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border-radius: var(--r-sm);
  background: none; border: 1px solid transparent; color: var(--text-2); cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.icon-button:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--line); }

/* --- top bar ------------------------------------------------------------------------------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s-3);
  padding: 14px var(--s-8); background: rgba(11, 13, 16, 0.8); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .menu-button { display: none; }
.topbar-brand { display: none; }
.topbar-search { position: relative; flex: 0 1 380px; margin-right: auto; }
.topbar-search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.topbar-search input { padding-left: 38px; padding-right: 40px; background: var(--surface-1); min-height: 40px; }
.topbar-search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.topbar-actions { display: flex; align-items: center; gap: var(--s-2); }

.content { width: 100%; max-width: var(--content-max); padding: var(--s-6) var(--s-8) 56px; }
.content > h1:first-child, .content > .breadcrumbs + h1 { margin-bottom: var(--s-5); }
.content > h1 + p.muted { margin: calc(var(--s-3) * -1) 0 var(--s-5); }

.drawer-overlay { display: none; }

/* --- tablet: icon-only sidebar ------------------------------------------------------------- */
@media (max-width: 1180px) and (min-width: 768px) {
  .app { grid-template-columns: var(--sidebar-w-compact) minmax(0, 1fr); }
  .sidebar { padding: 20px 10px; align-items: center; }
  .brand { padding: 0; }
  .brand-text, .nav-title, .nav-link span, .sidebar-user .who { display: none; }
  .nav-link { justify-content: center; width: 48px; padding: 0; }
  .nav-link[aria-current="page"]::before { left: -10px; }
  .sidebar-user { flex-direction: column; padding: 8px; }
  .sidebar-user form { margin: 0; }
  .topbar { padding: 14px var(--s-6); }
  .content { padding: var(--s-6) var(--s-6) 48px; }
}

/* --- phone: off-canvas drawer -------------------------------------------------------------- */
@media (max-width: 767px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw); height: 100%;
    transform: translateX(-102%); transition: transform var(--t-med) var(--ease); box-shadow: var(--shadow-pop);
  }
  .drawer-open .sidebar { transform: none; }
  .drawer-overlay {
    display: block; position: fixed; inset: 0; z-index: 25; background: rgba(5, 7, 9, 0.6);
    opacity: 0; pointer-events: none; transition: opacity var(--t-med) var(--ease);
  }
  .drawer-open .drawer-overlay { opacity: 1; pointer-events: auto; }
  .drawer-open { overflow: hidden; }
  .topbar { padding: 10px var(--s-4); flex-wrap: wrap; gap: var(--s-2); }
  .topbar .menu-button { display: grid; margin-left: -6px; }
  .topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text-1); margin-right: auto; }
  .topbar-brand .brand-logo { width: 28px; height: 28px; font-size: 11px; border-radius: 8px; }
  .topbar-search { order: 3; flex: 1 1 100%; margin: 0; }
  .topbar-search kbd { display: none; }
  .topbar-actions .button .label { display: none; }
  .topbar-actions .button { width: 40px; padding: 0; }
  .content { padding: var(--s-4) var(--s-4) 40px; }
  .stats { grid-template-columns: 1fr 1fr; gap: var(--s-3); }
  .stat { padding: 14px; }
}

/* --- anonymous pages (login, errors before login) ----------------------------------------- */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: var(--s-6) var(--s-4);
  background:
    radial-gradient(600px 400px at 50% -10%, rgba(62, 207, 142, 0.16), transparent 70%),
    radial-gradient(500px 300px at 100% 100%, rgba(167, 139, 250, 0.08), transparent 70%),
    var(--bg-0);
}
.auth-card { width: min(420px, 100%); padding: 32px; border-radius: 20px; animation: ds-rise var(--t-slow) var(--ease) both; }
.auth-card .brand { padding: 0; margin-bottom: var(--s-6); }
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card .lead { color: var(--text-3); margin-bottom: var(--s-6); }
.auth-card .button-primary { min-height: 44px; margin-top: var(--s-2); }
.auth-foot { margin-top: var(--s-5); display: flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: var(--fs-xs); }

.error-card { max-width: 560px; }
.error-card .error-code { font-size: var(--fs-xs); color: var(--text-3); font-family: var(--font-mono); }
