/* ════════════════════════════════════════════════════════════════════
 * CorpStack — app shell (Phase L.1.6)
 * ────────────────────────────────────────────────────────────────────
 * Persistent left sidebar + topbar, with the page's existing <main>
 * rendering in the remaining flex column. Builds on shared.css tokens
 * (--primary, --accent, --bg, --slate-*, etc.) — does NOT redefine
 * colors.
 * ──────────────────────────────────────────────────────────────────── */

/* shared.css makes <body> flex-column to stack header+main; we override
 * that to a plain block so #app-shell can become the flex row container. */
body.app-shell-active {
  display: block;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}
body.app-shell-active #app-shell {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────────────── */
.app-sidebar {
  flex: 0 0 240px;
  width: 240px;
  background: var(--primary);
  color: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  box-shadow: 1px 0 0 rgba(0,0,0,0.08);
  z-index: 5;
}
.app-sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  text-decoration: none;
  color: white;
}
.app-sidebar-brand .brand-logo {
  height: 32px;
  width: auto;
  /* The logo SVG is dark navy on transparent; on the navy sidebar we
     invert to white via filter so the wordmark stays legible. */
  filter: brightness(0) invert(1);
  opacity: 0.95;
}
.app-sidebar-brand .brand-firm {
  font-size: 11px;
  opacity: 0.65;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 2px;
}

.app-sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.app-sidebar-nav .nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin: 14px 12px 6px;
}
.app-sidebar-nav .nav-section-label:first-child { margin-top: 0; }

.app-nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border-radius: 6px;
  color: rgba(255,255,255,0.78);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.app-nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}
.app-nav-item.active {
  background: rgba(37, 99, 235, 0.22);
  color: white;
  font-weight: 600;
}
.app-nav-item.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.app-nav-item .nav-icon {
  flex: 0 0 18px;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  opacity: 0.85;
}
.app-nav-item .nav-label { flex: 1; }
.app-nav-item .nav-badge {
  background: rgba(255,255,255,0.16);
  color: white;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 9px;
  letter-spacing: 0;
}
.app-nav-item .nav-badge.urgent {
  background: var(--danger);
}
.app-nav-item .nav-badge.warn {
  background: var(--warning);
}

.app-sidebar-foot {
  border-top: 1px solid rgba(255,255,255,0.10);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-sidebar-foot .avatar {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.16);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}
.app-sidebar-foot .who {
  flex: 1;
  min-width: 0;
}
.app-sidebar-foot .who .name {
  font-size: 12.5px;
  font-weight: 600;
  color: white;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.app-sidebar-foot .who .email {
  font-size: 11px;
  opacity: 0.65;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.app-sidebar-foot .signout {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  border: none;
  color: white;
  cursor: pointer;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.app-sidebar-foot .signout:hover { background: rgba(255,255,255,0.16); }

/* ─── Main column (topbar + content) ──────────────────────────────── */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 56px;
  box-sizing: border-box;
}
.app-topbar .topbar-title {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.app-topbar .topbar-title h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}
.app-topbar .topbar-title .crumbs {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.app-topbar .topbar-title .crumbs a {
  color: var(--text-muted);
  text-decoration: none;
}
.app-topbar .topbar-title .crumbs a:hover { color: var(--accent); }

.app-topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-topbar .topbar-search {
  position: relative;
  width: 320px;
  max-width: 30vw;
}
.app-topbar .topbar-search input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  background: var(--slate-50);
  color: var(--text);
}
.app-topbar .topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: white;
}
.app-topbar .topbar-search::before {
  content: "🔍";
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  opacity: 0.5;
  pointer-events: none;
}

.app-topbar-bell {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--slate-700);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.app-topbar-bell:hover { background: var(--slate-100); }

/* Phase 14 polish — Feedback link in the topbar so the lawyer can ping us. */
.app-topbar-feedback {
  font-size: 12px;
  font-weight: 500;
  color: var(--slate-700);
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--slate-50);
  transition: background .12s, color .12s, border-color .12s;
}
.app-topbar-feedback:hover {
  background: white;
  color: var(--accent);
  border-color: var(--accent);
}
@media (max-width: 880px) {
  .app-topbar-feedback { display: none; }
}
.app-topbar-bell .badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--danger);
  color: white;
  font-size: 9.5px;
  font-weight: 700;
  padding: 0 5px;
  height: 14px; line-height: 14px;
  border-radius: 7px;
  min-width: 14px;
  text-align: center;
}

.app-content {
  flex: 1;
  width: 100%;
  padding: 24px 32px;
  box-sizing: border-box;
}
.app-content.full-bleed { padding: 0; }

/* When app shell is active, suppress the legacy .header from showing */
body.app-shell-active > header.header,
body.app-shell-active > .header { display: none !important; }

/* The legacy .main-wide / .main classes get neutralized inside the
 * shell so existing pages work without a class swap. */
body.app-shell-active main.main-wide,
body.app-shell-active main.main {
  max-width: none;
  padding: 24px 32px;
  margin: 0;
}

/* ─── Matter workspace (entity.html) sub-tabs ─────────────────────── */
.matter-tabs {
  display: flex;
  gap: 2px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  box-sizing: border-box;
  overflow-x: auto;
  position: sticky;
  top: 56px;
  z-index: 3;
}
.matter-tabs .tab {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
  border-top: none; border-left: none; border-right: none;
}
.matter-tabs .tab:hover { color: var(--text); }
.matter-tabs .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.matter-tabs .tab .tab-count {
  margin-left: 5px;
  background: var(--slate-100);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}
.matter-tabs .tab.active .tab-count {
  background: var(--accent-50);
  color: var(--accent);
}

/* Matter context header (entity name + status pill above the tabs) */
.matter-header {
  background: var(--card);
  padding: 18px 24px 14px;
  border-bottom: 1px solid transparent;
}
.matter-header .matter-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  letter-spacing: -0.01em;
}
.matter-header .matter-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}
.matter-header .matter-meta .pill {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--slate-100);
  color: var(--slate-700);
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 880px) {
  body.app-shell-active { flex-direction: column; }
  .app-sidebar {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .app-sidebar-brand { border-bottom: none; padding: 10px 14px; }
  .app-sidebar-nav { flex-direction: row; padding: 8px; gap: 4px; flex: 1; }
  .app-nav-item.active::before { display: none; }
  .app-sidebar-foot { display: none; }
  .app-topbar .topbar-search { display: none; }
  .matter-tabs { top: 0; }
}
