/* ============================================================
   LAYOUT.CSS — Backend v2 · Porcelain + Midnight
   App shell · Sidebar · Topbar · Tab bar · Content
   iOS execution: frosted chrome, filled nav pills, large titles
   ============================================================ */

/* ── App shell ─────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar (228px / 60px collapsed) ──────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-base);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-md), min-width var(--transition-md);
  z-index: 100;
}

#sidebar.collapsed {
  width: var(--sidebar-collapsed);
  min-width: var(--sidebar-collapsed);
}

/* Sidebar header — logo + toggle */
.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: var(--space-3);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: color var(--transition), background var(--transition),
              transform 120ms var(--ease-ios);
  flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-highlight); }
.sidebar-toggle:active { transform: scale(0.92); }

.sidebar-logo {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
  flex: 1;
  height: 100%;
}

/* Backend tile mark — 2x2 midnight mosaic, rounded tiles */
.tessera-mark {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  width: 18px;
  height: 18px;
  min-width: 18px;
  flex-shrink: 0;
}
.tessera-mark > span {
  background: var(--silver-light);
  border-radius: 2.5px;
  transition: background var(--transition-md);
}
.tessera-mark > span:nth-child(1),
.tessera-mark > span:nth-child(4) {
  background: var(--accent);
}
.sidebar-logo:hover .tessera-mark > span:nth-child(1),
.sidebar-logo:hover .tessera-mark > span:nth-child(4) {
  background: var(--accent-2);
}

.sidebar-logo .logo-text {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Sidebar nav — iOS sidebar: filled rounded rows */
.sidebar-nav {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  padding: var(--space-4) var(--space-3) var(--space-1);
  white-space: nowrap;
  overflow: hidden;
}

#sidebar.collapsed .nav-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-3);
  margin: 1px 0;
  color: var(--text-secondary);
  cursor: pointer;
  /* press feel: highlight snaps in, eases out on release */
  transition: background var(--transition), color var(--transition),
              transform 0.25s var(--ease-ios);
  border-radius: var(--radius);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  user-select: none;
  font-size: var(--text-md);
}

.nav-item:hover {
  background: var(--bg-highlight);
  color: var(--text-primary);
}
.nav-item:active {
  transform: scale(0.97);
  transition-duration: 0.08s;
}

.nav-item.active {
  background: var(--accent);
  color: #FFFFFF;
}
[data-theme="dark"] .nav-item.active {
  background: var(--blue-dim);
  color: var(--blue-bright);
}

/* Hide ::before bar from previous theme */
.nav-item.active::before { content: none; }

/* SVG icon wrap (used by nav + tabbar) */
.nav-icon-wrap {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity var(--transition);
}

.nav-item .nav-icon {
  font-size: 13px;
  min-width: 16px;
  text-align: center;
  opacity: 0.7;
}
.nav-item .nav-icon:empty { display: none; }

.nav-item .nav-label {
  font-size: var(--text-md);
  font-weight: 500;
  letter-spacing: -0.006em;
}

.nav-item:hover .nav-icon-wrap { opacity: 1; }
.nav-item.active .nav-icon-wrap,
.nav-item.active .nav-icon {
  opacity: 1;
  color: inherit;
  filter: none;
}

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent-2);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
}
.nav-item.active .nav-badge {
  background: rgba(255, 255, 255, 0.25);
}

#sidebar.collapsed .nav-label,
#sidebar.collapsed .nav-badge,
#sidebar.collapsed .nav-section-label { display: none; }
#sidebar.collapsed .logo-text { display: none; }

/* Sidebar footer / user block */
.user-avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  color: #FFFFFF;
  font-family: var(--font-ui);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  overflow: hidden;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow: hidden;
}

.sidebar-user .avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  color: #FFFFFF;
  font-family: var(--font-ui);
}

.sidebar-user .user-info { overflow: hidden; }
.sidebar-user .user-name {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: none;
}
.sidebar-user .user-role {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: none;
}

#sidebar.collapsed .user-info { display: none; }

/* ── Main area ───────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* ── Topbar (52px, frosted) ──────────────────────────────── */
#topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: 50;
}

.topbar-left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-title {
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--text-primary);
  text-transform: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar-title::before { content: none; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  overflow: hidden;
  max-width: 60%;
}

/* ── Responsive collapse ──────────────────────────────────── */
@media (max-width: 900px) {
  .topbar-title { display: none; }
  .topbar-right .topbar-link { font-size: var(--text-sm); padding: 0 6px; }
  .notif-bell { font-size: 12px; }
}

@media (max-width: 700px) {
  #sidebar { display: none; }
  #main { width: 100%; }
  .topbar-link { display: none; }
}

/* Theme toggle removed from topbar (Phase 9) — lives in Settings only */

/* Plain text topbar link (Settings, Alerts) */
.topbar-link {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  text-transform: none;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}
.topbar-link:hover { color: var(--text-primary); background: var(--bg-highlight); }
.topbar-link:active { opacity: 0.6; }

/* API status verbose label removed in Phase 10 — replaced by .api-status-dot in components.css */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Legacy topbar bits (kept for layout completeness) */
.topbar-toggle,
.topbar-breadcrumb,
.topbar-search,
.topbar-actions,
.topbar-action-btn { display: none; }

/* ── Tab bar removed (v2) — all navigation lives in the sidebar ──
   menuPop kept: it animates dropdown menus elsewhere. */
@keyframes menuPop {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Content area ────────────────────────────────────────── */
#content,
.content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-7) var(--space-8);
  background: var(--bg-base);
}

/* Page-enter transition — applied by app.js on tab switch.
   Horizontal slide + fade (phone-swipe feel) to match the mobile screen
   transition, with a short per-child stagger. Transform/opacity only —
   GPU-friendly, under 300ms, reduced-motion handled in base.css. */
@keyframes pageEnter {
  from { opacity: 0; transform: translateX(22px); }
  to   { opacity: 1; transform: translateX(0); }
}
#content.page-enter > * {
  animation: pageEnter 280ms var(--ease-ios) both;
}
#content.page-enter > *:nth-child(2) { animation-delay: 30ms; }
#content.page-enter > *:nth-child(3) { animation-delay: 60ms; }
#content.page-enter > *:nth-child(n+4) { animation-delay: 90ms; }

/* Content loading state */
#content.loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Page header — iOS Large Title */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  padding-bottom: 0;
  border-bottom: none;
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.1;
  color: var(--text-primary);
}
.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: 6px;
  letter-spacing: -0.006em;
  text-transform: none;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }

/* Two-column layouts */
.layout-with-sidebar {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-5);
  align-items: start;
}

.layout-with-sidebar-wide {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--space-5);
  align-items: start;
}

/* Inner tabs — iOS segmented control */
.inner-tabs {
  display: inline-flex;
  gap: 2px;
  border-bottom: none;
  background: var(--bg-highlight);
  border-radius: var(--radius);
  padding: 3px;
}
.inner-tab {
  padding: 6px var(--space-4);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 500;
  letter-spacing: -0.006em;
  text-transform: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: calc(var(--radius) - 3px);
  border-bottom: none;
  transition: color var(--transition), background var(--transition-md), box-shadow var(--transition-md),
              transform 120ms var(--ease-ios);
}
.inner-tab:hover { color: var(--text-primary); }
.inner-tab:active { transform: scale(0.96); }
.inner-tab.active {
  color: var(--text-primary);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  border-bottom: none;
}
