/* COZONE Web — App Shell Layout (Edition R1: Desktop >=768px & Mobile PWA <768px) */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}

/* =========================================================
   STICKY TOP BAR (Neutral matte translucent backdrop)
   ========================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar-bg-glass, rgba(25, 25, 29, 0.86));
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  backdrop-filter: saturate(140%) blur(18px);
  border-bottom: 1px solid var(--topbar-border);
  flex-shrink: 0;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar {
    background: var(--bg-elevated);
  }
}

/* Desktop Single-Line 56px Top Bar */
.topbar-desktop {
  height: var(--topbar-h);
  padding: 0 36px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.brand-wordmark {
  justify-self: start;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 20px;
  color: var(--text);
  white-space: nowrap;
  user-select: none;
  transition: opacity 0.14s ease;
}

.brand-wordmark:hover {
  opacity: 0.85;
}

.topbar-nav {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 32px;
}

/* Plain text tabs — ZERO pill backgrounds, ZERO lock icons; crisp 1.5px hairline */
.nav-tab {
  position: relative;
  height: var(--topbar-h);
  padding: 0;
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 0;
  white-space: nowrap;
  transition: color 140ms ease;
}

.nav-tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.5px;
  border-radius: 1px;
  background: var(--nav-active);
  opacity: 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 140ms ease, opacity 140ms ease;
  pointer-events: none;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--nav-active);
  font-weight: 600;
}

.nav-tab.active::after {
  opacity: 0.92;
  transform: scaleX(1);
}

.topbar-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  min-width: 0;
}

.search-box {
  position: relative;
  width: 248px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--search-border);
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.search-box:focus-within {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.search-icon {
  flex-shrink: 0;
  color: var(--search-placeholder);
  opacity: 0.9;
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  line-height: 18px;
  color: var(--text);
}

.search-input:focus-visible {
  outline: none;
}

.search-input::placeholder {
  color: var(--search-placeholder);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.14s ease, background-color 0.14s ease;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface);
}

.settings-btn {
  position: relative;
  opacity: 0.86;
}

.settings-btn:hover {
  opacity: 1;
}

.settings-conn-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--health-idle);
  box-shadow: 0 0 0 1.5px var(--bg-elevated);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, background-color 180ms ease;
}

.settings-conn-dot[data-state="healthy"] {
  background: var(--health-ok);
  opacity: 1;
}

.settings-conn-dot[data-state="degraded"] {
  background: var(--health-warn);
  opacity: 1;
}

.settings-conn-dot[data-state="cooldown"],
.settings-conn-dot[data-state="offline"] {
  background: var(--health-bad);
  opacity: 1;
}

/* Mobile header hidden on desktop */
.topbar-mobile {
  display: none;
}

/* =========================================================
   MAIN CONTENT STAGE
   ========================================================= */
.app-stage {
  width: 100%;
  max-width: var(--stage-max-w);
  margin: 0 auto;
  padding: 24px 36px calc(28px + var(--audiobar-h));
  flex: 1 0 auto;
  min-width: 0;
  outline: none;
}

@keyframes stageFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.app-stage.is-entering {
  animation: stageFadeIn 160ms ease-out;
}

/* =========================================================
   REUSABLE R1 UTILITIES: SCROLL STRIP FADE & HEALTH DOTS
   ========================================================= */
.scroll-strip-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.scroll-strip-mask {
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(
    to right,
    #000 0%,
    #000 calc(100% - var(--fade-right, 28px)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    #000 0%,
    #000 calc(100% - var(--fade-right, 28px)),
    transparent 100%
  );
}

.scroll-strip-mask::-webkit-scrollbar {
  display: none;
}

.scroll-strip-mask.fade-both,
.scroll-strip-mask[data-fade="both"] {
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 var(--fade-left, 24px),
    #000 calc(100% - var(--fade-right, 28px)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 var(--fade-left, 24px),
    #000 calc(100% - var(--fade-right, 28px)),
    transparent 100%
  );
}

.scroll-strip-mask.fade-left,
.scroll-strip-mask[data-fade="left"] {
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 var(--fade-left, 24px),
    #000 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 var(--fade-left, 24px),
    #000 100%
  );
}

.scroll-strip-mask.fade-none,
.scroll-strip-mask[data-fade="none"] {
  -webkit-mask-image: none;
  mask-image: none;
}

.scroll-arrow-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.scroll-arrow-btn:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

.scroll-arrow-btn:disabled,
.scroll-arrow-btn.is-hidden {
  opacity: 0.28;
  cursor: default;
  pointer-events: none;
}

.health-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--health-idle);
}

.health-dot--ok,
.health-dot.is-healthy,
.health-dot[data-state="healthy"] {
  background: var(--health-ok);
}

.health-dot--warn,
.health-dot.is-degraded,
.health-dot[data-state="degraded"] {
  background: var(--health-warn);
}

.health-dot--bad,
.health-dot.is-cooldown,
.health-dot.is-offline,
.health-dot[data-state="cooldown"],
.health-dot[data-state="offline"] {
  background: var(--health-bad);
}

.health-dot--idle,
.health-dot.is-untested,
.health-dot[data-state="untested"] {
  background: var(--health-idle);
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11.5px;
  line-height: 1;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}

button.health-pill:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

button.health-pill:disabled {
  opacity: 0.55;
  cursor: wait;
}

.health-ms {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.stage-status {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--text-secondary);
}

.stage-status-title {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.stage-status-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 420px;
}

.stage-loading-rule {
  width: 96px;
  height: 2px;
  border-radius: 1px;
  background: var(--border-strong);
  overflow: hidden;
  position: relative;
}

.stage-loading-rule::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: var(--text-secondary);
  animation: shell-slide 1.1s ease-in-out infinite;
}

@keyframes shell-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

/* =========================================================
   DESKTOP PERSISTENT 52px MINI-AUDIO BAR
   ========================================================= */
.desktop-audio-mount {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--audiobar-h);
  z-index: 35;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

/* =========================================================
   MOBILE BOTTOM STACK (HIDDEN ON DESKTOP)
   ========================================================= */
.mobile-bottom-stack {
  display: none;
}

/* =========================================================
   NARROW DESKTOP REFINEMENT (768px - 960px)
   ========================================================= */
@media (max-width: 960px) and (min-width: 768px) {
  .topbar-desktop {
    padding: 0 20px;
    gap: 12px;
  }

  .topbar-nav {
    gap: 22px;
  }

  .search-box {
    width: 196px;
  }

  .app-stage {
    padding: 20px 20px calc(24px + var(--audiobar-h));
  }
}

/* =========================================================
   MOBILE PWA LAYOUT (< 768px)
   ========================================================= */
@media (max-width: 767.98px) {
  .topbar-desktop {
    display: none;
  }

  .topbar-mobile {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: transparent;
  }

  .m-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 30px;
  }

  .m-page-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    line-height: 30px;
    letter-spacing: 0.01em;
    color: var(--nav-active);
  }

  .m-header-row .icon-btn {
    width: 32px;
    height: 32px;
    margin-right: -4px;
  }

  .m-search-box {
    position: relative;
    width: 100%;
    height: 36px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--search-border);
    padding: 0 11px;
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .m-search-box:focus-within {
    border-color: var(--border-strong);
  }

  .app-stage {
    padding: 14px 16px calc(22px + var(--mobile-audio-h) + var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px));
  }

  .desktop-audio-mount {
    display: none;
  }

  .mobile-bottom-stack {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
  }

  .mobile-audio-mount {
    height: var(--mobile-audio-h);
    background: var(--mobile-audio-bg);
    border-top: 1px solid var(--mobile-audio-border-top);
    border-bottom: 1px solid var(--mobile-audio-border-bottom);
    flex-shrink: 0;
  }

  .mobile-tabbar {
    background: var(--mobile-tab-bg);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: center;
    padding: 4px 8px env(safe-area-inset-bottom, 0px);
    min-height: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }

  .m-tab {
    height: calc(var(--mobile-tab-h) - 4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--mobile-tab-inactive);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.14s ease;
  }

  .m-tab span {
    font-size: 10px;
    line-height: 12px;
    font-weight: 500;
  }

  .m-tab .icon-solid {
    display: none;
  }

  .m-tab.active {
    color: var(--nav-active);
  }

  .m-tab.active .icon-outline {
    display: none;
  }

  .m-tab.active .icon-solid {
    display: block;
  }
}

/* =========================================================
   QUIET FLAT MODALS (SETTINGS & DIRECT STREAM PLAYER)
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--overlay-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-panel {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  color: var(--text);
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.14s ease, background-color 0.14s ease;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.modal-body {
  padding: 6px 22px 22px;
  display: flex;
  flex-direction: column;
}

.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.settings-hint {
  margin: 0;
  font-size: 12px;
  line-height: 17px;
  color: var(--text-secondary);
}

.settings-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.14s ease;
}

.settings-input::placeholder {
  color: var(--text-muted);
}

.settings-input:focus {
  outline: none;
  border-color: var(--text-secondary);
}

.settings-input.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.settings-actions .btn-primary,
.settings-actions .btn-secondary {
  height: 32px;
  padding: 0 14px;
  font-size: 12.5px;
}

.settings-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 16px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.ok {
  background: var(--status-ok);
}

.status-dot.err {
  background: var(--status-danger);
}

.theme-segment {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
  gap: 2px;
}

.theme-option {
  height: 28px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background-color 0.14s ease, color 0.14s ease;
}

.theme-option:hover {
  color: var(--text);
}

.theme-option.active {
  background: var(--surface-hover);
  color: var(--text);
}

/* Settings: 5-row monochrome Apple-style source health table */
.health-probe-btn {
  height: 28px;
  padding: 0 12px;
  font-size: 12px;
}

.health-table {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.health-row {
  min-height: 36px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.health-row:last-child {
  border-bottom: none;
}

.health-row-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
}

.health-row-metric {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.health-row-count {
  color: var(--text);
}

.health-row-sep {
  color: var(--text-muted);
}

/* Direct Stream Player Modal */
.direct-player-panel {
  max-width: 960px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.direct-player-host {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000000;
  position: relative;
}

/* =========================================================
   QUIET DARK BOTTOM TOAST
   ========================================================= */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--audiobar-h) + 18px);
  transform: translateX(-50%);
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast-item {
  padding: 9px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-popover);
  color: var(--text);
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  max-width: 460px;
  text-align: center;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast-item.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-item.is-error {
  border-color: rgba(239, 68, 68, 0.45);
}

@media (max-width: 767.98px) {
  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-panel {
    max-width: 100%;
    max-height: calc(100dvh - 36px);
  }

  .direct-player-panel {
    align-self: center;
  }

  .toast-container {
    bottom: calc(var(--mobile-audio-h) + var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px) + 14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-stage.is-entering {
    animation: none;
  }

  .nav-tab,
  .nav-tab::after,
  .scroll-arrow-btn,
  .health-pill,
  .settings-conn-dot,
  .toast-item {
    transition: none;
  }

  .stage-loading-rule::after {
    animation: none;
    width: 100%;
    opacity: 0.45;
  }
}
