/* Supah Work shell chrome — topbar, primary rail, subdrawer, context pane, app body. */

.app-shell {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
  background: var(--ground);
  color: var(--ink);
  overflow: hidden;
}

/* Topbar */
.app-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--ground) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  z-index: 30;
}
.app-topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.app-topbar .brand .dot-glyph { color: var(--muted); padding: 0 0.08em; }
.app-topbar .workspace {
  color: var(--muted);
  font-size: 13px;
  border-left: 1px solid var(--hairline);
  padding-left: 12px;
  margin-left: 4px;
}
.app-topbar .topbar-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.app-topbar .topbar-search:hover { border-color: var(--hairline-strong); }
.app-topbar .topbar-search .icon svg { width: 13px; height: 13px; }
.app-topbar .topbar-search kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--tint);
  color: var(--muted);
}
.app-topbar .op {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.app-topbar .op-initials {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Frame below topbar */
.app-frame {
  display: grid;
  grid-template-columns: 72px auto var(--context-width, 340px) 1fr;
  min-height: 0;
}
.app-frame[data-context-hidden] { grid-template-columns: 72px auto 0 1fr; }
.app-frame[data-subdrawer-hidden] { grid-template-columns: 72px 0 var(--context-width, 340px) 1fr; }
.app-frame[data-subdrawer-hidden][data-context-hidden] { grid-template-columns: 72px 0 0 1fr; }

/* Primary action rail */
.app-rail {
  grid-column: 1;
  background: var(--rail-bg);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  min-height: 0;
  overflow-y: auto;
}
.app-rail a, .app-rail button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 9px;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.app-rail a:hover, .app-rail button:hover {
  background: var(--tint);
  color: var(--ink);
}
.app-rail a[aria-current="page"] {
  background: var(--tint);
  color: var(--ink);
}
.app-rail a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--ink);
}
.app-rail a svg, .app-rail button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.75;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.app-rail .rail-spacer { flex: 1; }
.app-rail .rail-status {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 28px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
}
.app-rail .rail-status .dot { margin-right: 4px; }

/* Secondary subdrawer */
.app-subdrawer {
  grid-column: 2;
  background: var(--drawer-bg);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  min-height: 0;
  overflow-y: auto;
  width: 64px;
}
.app-subdrawer a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  margin: 0 8px 4px;
  padding: 8px 4px;
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
}
.app-subdrawer a:hover { background: var(--tint); color: var(--ink); }
.app-subdrawer a[aria-current="page"] { background: var(--tint); color: var(--ink); font-weight: 600; }
.app-subdrawer a svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* Context pane */
.app-context {
  grid-column: 3;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.app-context .pane-head {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 14px 16px 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
  z-index: 2;
}
.app-context .pane-head h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.app-context .pane-head .count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}
.app-context .pane-head .filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--hairline);
  background: var(--surface);
  padding: 5px 9px;
  border-radius: var(--radius);
  cursor: pointer;
}
.app-context .pane-head .filter-btn:hover { border-color: var(--hairline-strong); color: var(--ink); }
.app-context .pane-head .filter-btn .icon svg { width: 12px; height: 12px; }
.app-context .pane-quick {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--hairline);
}
.app-context .pane-quick a {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}
.app-context .pane-quick a:hover { color: var(--ink); background: var(--tint); }
.app-context .pane-quick a.active { background: var(--ink); color: var(--surface); }
.app-context .pane-rows {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.context-row {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: start;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  color: inherit;
  transition: background 120ms ease;
}
.context-row:hover { background: var(--quiet); }
.context-row[aria-current="true"] { background: var(--tint); }
.context-row .dot { margin-top: 6px; }
.context-row .row-main { min-width: 0; }
.context-row .row-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.context-row .row-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.context-row .row-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: right;
  white-space: nowrap;
}
.context-row .row-meta .badge { display: inline-block; margin-top: 4px; }

/* App body */
.app-body {
  grid-column: 4;
  background: var(--ground);
  overflow-y: auto;
  min-width: 0;
  min-height: 0;
}
.app-body .body-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 28px 80px;
}
.app-body .body-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-tile);
  padding: 20px;
  margin-bottom: 12px;
}
.app-body .body-empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}
.app-body .body-empty strong {
  display: block;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}

/* Tile grids */
.body-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.body-cards-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.body-cards-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

/* Filter popover */
.filter-popover {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-tile);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12);
  padding: 14px;
  min-width: 240px;
  display: none;
}
.filter-popover[data-open] { display: block; }
.filter-popover .popover-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.filter-popover .popover-head h3 { font-size: 12px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; }
.filter-popover .popover-head button { color: var(--muted); }
.filter-popover .chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.filter-popover .chip {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline);
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
}
.filter-popover .chip.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* Detail drawer (desktop: right-side slide-in over body) */
.detail-drawer {
  position: fixed;
  top: 48px;
  right: 0;
  bottom: 0;
  width: min(540px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.06);
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detail-drawer[data-open] { transform: translateX(0); }

/* AI composer dock (body-anchored) */
.ai-dock {
  position: sticky;
  bottom: 16px;
  margin: 16px auto 0;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.06);
  color: var(--muted);
  font-size: 13px;
}
.ai-dock .icon svg { width: 14px; height: 14px; color: var(--processing); }
.ai-dock input {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  outline: none;
}
.ai-dock input::placeholder { color: var(--muted); }
.ai-dock .send {
  border: 0;
  background: var(--ink);
  color: var(--surface);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.ai-dock .send svg { width: 14px; height: 14px; }

/* Sparkline (Monitor app) */
.sparkline { width: 100%; height: 88px; }
.sparkline .line-open { fill: none; stroke: var(--processing); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.sparkline .line-good { fill: none; stroke: var(--good); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.sparkline .area-open { fill: var(--processing-soft); opacity: 0.6; }
.sparkline-axis { font-family: var(--font-mono); font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; margin-top: 6px; }

/* Mobile bottom sheet (context pane) */
.mobile-sheet-trigger {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  border: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  z-index: 35;
}
.mobile-sheet { display: none; }

/* Responsive */
@media (max-width: 980px) {
  .app-frame,
  .app-frame[data-subdrawer-hidden],
  .app-frame[data-context-hidden],
  .app-frame[data-subdrawer-hidden][data-context-hidden] {
    grid-template-columns: 72px 0 1fr 0;
  }
  .app-context { display: none; }
  .app-context[data-mobile-open] {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: 56px;
    top: 96px;
    border-radius: 16px 16px 0 0;
    border-right: 0;
    border-top: 1px solid var(--hairline);
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.1);
    z-index: 32;
  }
  .app-body { grid-column: 3 / 4; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-rows: 44px 1fr; }
  .app-topbar { padding: 0 12px; grid-template-columns: auto 1fr auto; }
  .app-topbar .topbar-search { display: none; }
  .app-topbar .workspace { display: none; }
  .app-frame,
  .app-frame[data-subdrawer-hidden],
  .app-frame[data-context-hidden],
  .app-frame[data-subdrawer-hidden][data-context-hidden] {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 56px;
  }
  .app-rail {
    grid-row: 2;
    grid-column: 1;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--hairline);
    padding: 6px 12px;
    gap: 0;
    justify-content: space-around;
    overflow-x: auto;
  }
  .app-rail .rail-status, .app-rail .rail-spacer { display: none; }
  .app-rail a[aria-current="page"]::before {
    left: 8px; right: 8px; top: -6px; bottom: auto;
    width: auto; height: 2px;
  }
  .app-subdrawer {
    grid-row: 1;
    grid-column: 1;
    width: auto;
    flex-direction: row;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    padding: 6px 12px;
    gap: 4px;
    overflow-x: auto;
  }
  .app-context { display: none; }
  .app-body { grid-row: 1; grid-column: 1; }
  .app-body .body-inner { padding: 18px 16px 90px; }
  .body-tiles { grid-template-columns: 1fr 1fr; }
  .body-cards-3, .body-cards-2 { grid-template-columns: 1fr; }
  .mobile-sheet-trigger { display: inline-flex; align-items: center; gap: 6px; }
  .app-context[data-mobile-open] {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: 56px;
    top: 86px;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.1);
    z-index: 32;
  }
  .app-context[data-mobile-open]::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--hairline-strong);
    margin: 8px auto;
  }
  .detail-drawer {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 70px;
    width: auto;
    max-height: 70vh;
    border-radius: 14px;
    border: 1px solid var(--hairline);
    transform: translateY(120%);
  }
  .detail-drawer[data-open] { transform: translateY(0); }
}
