/* ══════════════════════════════════════════════════
   Xtream Filter Console — Broadcast Control Theme
   Fonts: Barlow Condensed (display) + DM Sans (body) + IBM Plex Mono
   ══════════════════════════════════════════════════ */

:root {
  color-scheme: dark;
  --bg: #090b10;
  --surface: #111420;
  --surface-alt: #161927;
  --surface-solid: #0d1018;
  --ink: #c8cdd8;
  --muted: #868ea8;
  --muted-light: #a4abbe;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.10);
  --accent: #f5a300;
  --accent-hover: #ffb929;
  --accent-light: rgba(245, 163, 0, 0.10);
  --accent-deep: #c47d00;
  --green: #0ddb7a;
  --green-light: rgba(13, 219, 122, 0.10);
  --green-mid: rgba(13, 219, 122, 0.18);
  --danger: #ff4466;
  --danger-light: rgba(255, 68, 102, 0.10);

  --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.65);

  --radius: 6px;
  --radius-lg: 8px;
  --radius-sm: 4px;
  --radius-xs: 3px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 0.18s;

  --font-display: "Barlow Condensed", "Impact", sans-serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.5;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(245, 163, 0, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245, 163, 0, 0.022) 1px, transparent 1px);
  background-size: 40px 40px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Scanline overlay ─── */

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    transparent 1px,
    rgba(0, 0, 0, 0.07) 1px,
    rgba(0, 0, 0, 0.07) 2px
  );
}

/* ─── Layout shell ─── */

.shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 24px 24px 60px;
}

.hidden {
  display: none !important;
}

/* ─── Typography helpers ─── */

.panel-copy,
.meta-label {
  color: var(--muted-light);
}

/* ─── Focus styles ─── */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ─── Base panel ─── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), inset 3px 0 0 var(--accent);
  padding: 20px;
}

/* ─── Auth ─── */

@keyframes authSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10vh;
  min-height: 72vh;
  margin-bottom: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg), inset 3px 0 0 var(--accent);
  overflow: hidden;
  animation: authSlideIn 0.5s var(--ease) both;
}

.auth-card-stripe {
  height: 38px;
  background: rgba(245, 163, 0, 0.05);
  border-bottom: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
}

.auth-card-stripe::before {
  content: "◈";
  color: var(--accent);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.auth-card-stripe::after {
  content: "XTREAM FILTER CONSOLE  ·  AUTH";
  font-family: var(--font-mono);
  font-size: 0.69rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

.auth-card-body {
  padding: 36px 32px 32px;
  display: grid;
  gap: 0;
}

.auth-heading {
  margin: 0 0 28px;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
}

.auth-heading::before {
  content: "> ";
  color: var(--accent);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-hint {
  margin: -4px 0 0;
}

.auth-submit {
  margin-top: 8px;
  width: 100%;
  padding: 13px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  justify-self: stretch;
  border-radius: var(--radius-sm);
}

.auth-toggle {
  margin-top: 24px;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.auth-toggle-btn {
  all: unset;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--muted-light);
  transition: color var(--duration);
}

.auth-toggle-btn span {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.auth-toggle-btn:hover span {
  color: var(--accent-hover);
}

.auth-error {
  margin: 10px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  border: 1px solid rgba(255, 68, 102, 0.2);
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: var(--font-mono);
  line-height: 1.45;
}

.auth-error::before {
  content: "! ";
}

/* ─── Topbar ─── */

.topbar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 20px;
  min-height: 54px;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  position: sticky;
  top: 12px;
  z-index: 100;
}

@keyframes signal-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.topbar-brand {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
  padding-right: 20px;
  color: var(--ink);
}

.topbar-brand::before {
  content: "◈ ";
  color: var(--accent);
  animation: signal-pulse 3s ease-in-out infinite;
}

.topbar-divider {
  width: 1px;
  height: 26px;
  background: var(--border-strong);
  flex-shrink: 0;
}

/* Profile zone */

.topbar-profile {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  padding: 8px 20px;
}

.topbar-profile select {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.3);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  width: 200px;
  transition: border-color var(--duration), background var(--duration);
}

.topbar-profile select:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.5);
}

.profile-source-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  max-width: 200px;
  overflow: hidden;
}

.topbar .source-name {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 90px;
  letter-spacing: 0.03em;
}

.topbar .source-name::before {
  content: "via ";
  font-weight: 400;
}

.topbar .source-meta {
  margin: 0;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--muted);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* Content-type tabs */

.content-type-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  margin: 0 20px;
}

.tab {
  all: unset;
  cursor: pointer;
  padding: 7px 20px;
  font-size: 0.76rem;
  font-weight: 700;
  font-family: var(--font-body);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-light);
  transition: color var(--duration), background var(--duration);
  border-right: 1px solid var(--border-strong);
  white-space: nowrap;
}

.tab:last-child {
  border-right: none;
}

.tab.active {
  background: var(--accent);
  color: #000;
}

.tab:hover:not(.active) {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
}

/* Topbar right */

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 400;
  font-family: var(--font-mono);
  color: var(--muted-light);
  max-width: 220px;
  overflow: hidden;
}

#status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sync {
  padding: 6px 16px;
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

@keyframes syncSpin {
  to { transform: rotate(360deg); }
}

.topbar-sync.syncing {
  pointer-events: none;
  opacity: 0.6;
}

/* Status dot */

@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-light); }
  50% { box-shadow: 0 0 0 5px var(--green-light), 0 0 10px var(--green); }
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(90, 97, 128, 0.15);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
  animation: dot-pulse 2.5s ease-in-out infinite;
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-light);
}

/* ─── Workspace layout ─── */

.workspace {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}

.sidebar,
.content-grid {
  min-height: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-head.compact {
  margin-bottom: 10px;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}

.panel-head h2 {
  font-size: 1.1rem;
}

.panel-head h3 {
  font-size: 0.95rem;
}

.panel-copy {
  margin: 3px 0 0;
  font-size: 0.8rem;
  line-height: 1.45;
  font-family: var(--font-mono);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(380px, 1.15fr);
  gap: 16px;
}

/* ─── Sidebar / Settings ─── */

.stack {
  display: grid;
  gap: 10px;
}

.subpanel {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  transition: border-color 0.15s;
}

.subpanel:hover {
  border-color: var(--border-strong);
}

.subpanel h3 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.compact-form {
  display: grid;
  gap: 10px;
}

.password-form {
  display: grid;
  gap: 10px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
  font-family: var(--font-mono);
  line-height: 1.55;
}

/* ─── Inputs ─── */

select,
.search,
.text-input {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  font-size: 0.86rem;
  color: var(--ink);
  transition: border-color var(--duration), box-shadow var(--duration), background var(--duration);
}

select:hover,
.search:hover,
.text-input:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.5);
}

select:focus,
.search:focus,
.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 163, 0, 0.12);
  background: rgba(0, 0, 0, 0.6);
}

::placeholder {
  color: var(--muted);
  font-weight: 400;
}

/* ─── Buttons ─── */

.button {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  letter-spacing: 0.02em;
  position: relative;
}

.button:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
}

.button:active {
  transform: scale(0.97);
}

.button.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.button.accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button.ghost {
  background: var(--green-light);
  border-color: rgba(13, 219, 122, 0.2);
  color: var(--green);
  font-weight: 500;
}

.button.ghost:hover {
  background: var(--green-mid);
  border-color: rgba(13, 219, 122, 0.35);
}

.button.danger {
  background: var(--danger-light);
  border-color: rgba(255, 68, 102, 0.3);
  color: var(--danger);
  font-weight: 600;
}

.button.danger:hover {
  background: rgba(255, 68, 102, 0.2);
  border-color: rgba(255, 68, 102, 0.5);
}

.button.small {
  padding: 5px 10px;
  font-size: 0.76rem;
}

/* ─── Panel head right group ─── */

.panel-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Pills ─── */

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 1px 8px;
  border-radius: 2px;
  background: rgba(245, 163, 0, 0.08);
  border: 1px solid rgba(245, 163, 0, 0.22);
  color: var(--accent);
  font-size: 0.73rem;
  font-family: var(--font-mono);
  font-weight: 400;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

/* ─── Toggle switches ─── */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  color: var(--muted-light);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.22s var(--ease), border-color 0.22s;
  padding: 0;
}

.toggle input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.22s var(--ease), background 0.22s;
}

.toggle input[type="checkbox"]:checked {
  background: var(--green);
  border-color: var(--green);
}

.toggle input[type="checkbox"]:checked::after {
  transform: translateX(16px);
  background: #000;
}

.toggle input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 10px;
}

/* Favourite toggle variant */
.toggle input.favorite-toggle:checked {
  background: var(--accent);
  border-color: var(--accent);
}

/* ─── Item actions ─── */

.item-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* ─── Meta label ─── */

.meta-label {
  display: block;
  font-size: 0.77rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--muted-light);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

/* ─── Credential card ─── */

.credential-card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.3);
}

.credential-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

.credential-label {
  font-size: 0.74rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--muted);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.credential-row code {
  padding: 4px 9px;
  border-radius: var(--radius-xs);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  word-break: break-all;
}

.credential-value-group {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}

/* ─── Source list ─── */

.source-list {
  display: grid;
  gap: 8px;
}

.source-pill {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.25);
  transition: border-color var(--duration), background var(--duration);
}

.source-pill:hover {
  border-color: var(--border-strong);
  background: rgba(0, 0, 0, 0.4);
}

.source-pill strong {
  display: block;
  margin-bottom: 2px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}

.source-pill .source-copy {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  word-break: break-all;
}

/* ─── Scrollable list containers ─── */

.list {
  display: grid;
  gap: 4px;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.list::-webkit-scrollbar {
  width: 6px;
}

.list::-webkit-scrollbar-track {
  background: transparent;
}

.list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* ─── Item cards ─── */

.item-card {
  border: 1px solid var(--border);
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-alt);
  overflow: hidden;
  transition: border-color var(--duration), box-shadow var(--duration), opacity var(--duration);
}

.item-card:hover {
  border-color: var(--border-strong);
  border-left-color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.item-card.is-hidden {
  opacity: 0.3;
}

.item-card.is-hidden:hover {
  opacity: 0.5;
}

.item-card.is-hidden .title-button,
.item-card.is-hidden .item-title {
  text-decoration: line-through;
  text-decoration-color: rgba(200, 205, 216, 0.3);
  text-decoration-thickness: 1px;
}

/* Active category highlight */
.item-card[style*="outline"] {
  outline: 2px solid rgba(13, 219, 122, 0.35) !important;
  border-left-color: var(--green);
  background: rgba(13, 219, 122, 0.04);
}

/* Category card */

.cat-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  flex-wrap: wrap;
}

.cat-row-main .toggle {
  flex-shrink: 0;
}

.title-button {
  all: unset;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.84rem;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  transition: color var(--duration);
  color: var(--ink);
}

.title-button:hover {
  color: var(--accent);
}

.cat-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 9px;
}

.cat-row-actions .stream-button {
  flex-shrink: 0;
  padding: 5px 12px;
  font-size: 0.76rem;
  margin-left: auto;
}

.cat-row-edit {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border);
}

.cat-row-edit .text-input {
  padding: 6px 9px;
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
}

.cat-row-edit .custom-sort {
  flex: 0 0 60px;
}

.cat-row-edit .save-button {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.76rem;
}

/* Stream card */

.stream-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  flex-wrap: wrap;
}

.stream-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.item-title {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  color: var(--ink);
}

.stream-toggles {
  display: flex;
  gap: 14px;
  flex-shrink: 0;
}

.stream-row-edit {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border);
}

.stream-row-edit .text-input {
  padding: 6px 9px;
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
}

.stream-row-edit .custom-sort {
  flex: 0 0 60px;
}

.stream-row-edit .save-button {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.76rem;
}

/* ─── Prefix panel toggle ─── */

.prefix-panel-toggle {
  all: unset;
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  color: var(--accent);
  transition: color var(--duration), background var(--duration), border-color var(--duration);
}

.prefix-panel-toggle::after {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentcolor;
  border-bottom: 2px solid currentcolor;
  transform: rotate(-135deg);
  margin-top: 3px;
  transition: transform 0.25s var(--ease), margin-top 0.25s var(--ease);
}

.prefix-panel-toggle:not(.open)::after {
  transform: rotate(45deg);
  margin-top: -3px;
}

.prefix-panel-toggle:hover {
  color: var(--accent-hover);
  background: var(--accent-light);
  border-color: rgba(245, 163, 0, 0.3);
}

/* ─── Prefix panel ─── */

.prefix-panel {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(245, 163, 0, 0.03);
}

.prefix-list {
  display: grid;
  gap: 6px;
}

.prefix-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  transition: border-color var(--duration);
}

.prefix-card:hover {
  border-color: var(--border-strong);
}

.prefix-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.prefix-title {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--ink);
}

.prefix-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

/* ─── Empty state ─── */

.empty-state {
  padding: 28px 20px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

/* ─── Search ─── */

.search {
  width: 160px;
  flex-shrink: 0;
}

/* ─── Mobile status bar ─── */

.mobile-status {
  display: none;
}

/* ─── Sidebar toggle ─── */

.sidebar-toggle {
  display: none;
}

/* ─── Guide sections ─── */

.guide-toggle {
  all: unset;
  cursor: pointer;
  display: block;
  width: 100%;
  font-size: 0.77rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  text-align: center;
  padding: 10px 0;
  transition: color var(--duration);
  position: relative;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.guide-toggle::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentcolor;
  border-bottom: 1.5px solid currentcolor;
  transform: rotate(45deg);
  margin-left: 8px;
  vertical-align: 2px;
  transition: transform 0.25s var(--ease);
}

.guide-toggle.open::after {
  transform: rotate(-135deg);
  vertical-align: -1px;
}

.guide-toggle:hover {
  color: var(--accent-hover);
}

.sidebar-guide-toggle {
  text-align: left;
  padding: 0;
}

.sidebar-guide-toggle h3 {
  display: inline;
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  cursor: pointer;
  transition: color var(--duration);
}

.sidebar-guide-toggle:hover h3 {
  color: var(--accent-hover);
}

.sidebar-guide-toggle::after {
  vertical-align: 1px;
}

.auth-guide {
  max-width: 400px;
  width: 100%;
  margin: 18px auto 0;
}

/* Smooth expand/collapse for guide bodies */
.guide-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s var(--ease);
}

.guide-body > * {
  overflow: hidden;
}

.guide-body.open {
  grid-template-rows: 1fr;
}

.guide-content {
  padding: 0 20px;
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.65;
}

.guide-body.open .guide-content {
  padding-top: 16px;
  padding-bottom: 20px;
}

.guide-content h3 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.guide-content h4 {
  margin: 18px 0 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.guide-content p {
  margin: 0 0 8px;
}

.guide-content ul {
  margin: 6px 0 12px;
  padding-left: 20px;
}

.guide-content li {
  margin-bottom: 4px;
}

.auth-guide .guide-body {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.subpanel .guide-content {
  padding: 0;
}

.subpanel .guide-body.open .guide-content {
  padding: 10px 0 0;
}

.subpanel .guide-content h4 {
  margin-top: 14px;
}

.subpanel .guide-content h4:first-child {
  margin-top: 0;
}

/* ─── Toast notifications ─── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  pointer-events: none;
  max-width: 380px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 400;
  line-height: 1.4;
  pointer-events: auto;
  transform: translateY(12px) scale(0.95);
  opacity: 0;
  transition: all 0.28s var(--ease);
  box-shadow: var(--shadow);
  cursor: default;
  letter-spacing: 0.02em;
}

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

.toast-ok {
  background: var(--green);
  color: #000;
}

.toast-error {
  background: var(--danger);
  color: white;
}

.toast-neutral {
  background: var(--surface-alt);
  color: var(--ink);
  border: 1px solid var(--border-strong);
}

/* ─── Confirmation modal ─── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 3px 0 0 var(--accent);
  overflow: hidden;
  animation: authSlideIn 0.2s var(--ease) both;
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(245, 163, 0, 0.04);
}

.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink);
}

.modal-body {
  padding: 18px 20px;
}

.modal-body p {
  margin: 0;
  font-size: 0.84rem;
  font-family: var(--font-mono);
  line-height: 1.6;
  color: var(--muted-light);
}

.modal-warning {
  margin-top: 12px !important;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 68, 102, 0.08);
  border: 1px solid rgba(255, 68, 102, 0.2);
  color: var(--danger) !important;
  font-size: 0.79rem !important;
}

.modal-warning::before {
  content: "⚠ ";
}

.modal-actions {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* ─── Legal disclaimer footer ─── */

.legal-disclaimer {
  margin-top: 48px;
  padding: 0 4px;
}

.legal-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  line-height: 1.65;
}

.legal-inner h4 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.77rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.legal-inner p {
  margin: 0 0 8px;
}

.legal-inner p:last-child {
  margin-bottom: 0;
}

.legal-inner strong {
  color: var(--muted-light);
  font-weight: 600;
}

/* ─── Favourites list button (stream card) ─── */

.fav-list-button {
  font-size: 0.74rem;
  padding: 4px 10px;
  color: var(--accent);
  border-color: rgba(245, 163, 0, 0.3);
  flex-shrink: 0;
}

.fav-list-button:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.fav-list-button.fav-active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* ─── Favourites picker modal ─── */

.fav-picker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  margin-bottom: 10px;
}

.fav-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  transition: border-color var(--duration);
}

.fav-picker-item:hover {
  border-color: var(--border-strong);
}

.fav-picker-item span:nth-child(2) {
  flex: 1;
  font-size: 0.83rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fav-picker-toggle {
  font-size: 1rem;
  color: var(--muted);
  min-width: 32px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.fav-picker-toggle[data-in-list="true"] {
  color: var(--accent);
  border-color: rgba(245, 163, 0, 0.3);
}

.fav-picker-create {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.fav-picker-create .text-input {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  font-size: 0.8rem;
}

/* ─── Favourites management cards (settings sidebar) ─── */

.fav-list-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 6px;
  transition: border-color var(--duration);
}

.fav-list-card:hover {
  border-color: var(--border-strong);
}

.fav-list-name {
  flex: 1;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.fav-list-card .item-actions {
  margin-top: 0;
  flex-shrink: 0;
}

/* ─── Reduced motion ─── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ══════════════════════════════════════════════════
   Responsive: tablet & mobile shared (<=1100px)
   ══════════════════════════════════════════════════ */

@media (max-width: 1100px) {
  body {
    overflow-x: hidden;
  }

  .shell {
    overflow-x: hidden;
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    min-height: auto;
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 10px;
    position: static;
  }

  .topbar-divider {
    display: none;
  }

  .topbar-profile {
    padding: 0;
    flex-shrink: 1;
    min-width: 0;
  }

  .topbar-profile select {
    width: 100%;
  }

  .profile-source-row {
    max-width: none;
  }

  .content-type-tabs {
    margin: 0;
  }

  .topbar-right {
    border-left: none;
    padding-left: 0;
    flex-shrink: 1;
    min-width: 0;
    flex-wrap: wrap;
  }

  #user-chip {
    display: none !important;
  }

  .topbar-status {
    min-width: 0;
    flex: 1;
  }

  #status-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .list {
    max-height: none;
  }

  .search {
    width: 100%;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar {
    display: none;
  }

  .sidebar.sidebar-open {
    display: block;
  }

  /* Larger touch targets */
  .button {
    min-height: 44px;
    padding: 10px 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .toggle input[type="checkbox"] {
    width: 44px;
    height: 26px;
    border-radius: 13px;
  }

  .toggle input[type="checkbox"]::after {
    width: 20px;
    height: 20px;
  }

  .toggle input[type="checkbox"]:checked::after {
    transform: translateX(18px);
  }

  .toggle {
    gap: 10px;
    font-size: 0.8rem;
  }

  .cat-row-main,
  .stream-row-main {
    padding: 12px 14px;
    gap: 10px;
  }

  .cat-row-actions .stream-button {
    padding: 8px 16px;
    font-size: 0.8rem;
    min-height: 40px;
  }
}

/* ══════════════════════════════════════════════════
   Responsive: phone (<=680px)
   ══════════════════════════════════════════════════ */

@media (max-width: 680px) {
  .shell {
    padding: 12px 10px 40px;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
    border-radius: var(--radius);
  }

  .topbar-brand {
    font-size: 1.1rem;
    padding-right: 0;
    margin-right: auto;
  }

  .topbar-right {
    width: auto;
    order: 0;
    gap: 6px;
  }

  .topbar-status {
    display: none;
  }

  .mobile-status:not(.hidden) {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-bottom: 10px;
    font-size: 0.74rem;
    font-family: var(--font-mono);
    color: var(--muted-light);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
  }

  .mobile-status span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .topbar-profile {
    width: 100%;
    order: 10;
  }

  .content-type-tabs {
    order: 11;
    width: 100%;
    justify-content: center;
  }

  .tab {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    font-size: 0.7rem;
  }

  .workspace {
    gap: 12px;
  }

  .panel {
    padding: 14px;
    border-radius: var(--radius);
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* Category cards */
  .cat-row-main {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .cat-row-main .toggle {
    order: 1;
  }

  .cat-row-main .title-button {
    order: 2;
    flex: 1;
  }

  .cat-row-actions .stream-button {
    width: 100%;
    text-align: center;
    min-height: 44px;
    margin-left: 0;
  }

  .cat-row-edit {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
  }

  .cat-row-edit .text-input {
    min-width: 0;
  }

  .cat-row-edit .custom-sort {
    flex: 0 0 80px;
  }

  .cat-row-edit .save-button {
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  /* Stream cards */
  .stream-row-main {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px;
  }

  .stream-heading {
    flex-wrap: wrap;
    gap: 6px;
  }

  .item-title {
    white-space: normal;
    word-break: break-word;
  }

  .stream-toggles {
    justify-content: flex-start;
  }

  .stream-row-edit {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
  }

  .stream-row-edit .custom-sort {
    flex: 0 0 80px;
  }

  .stream-row-edit .save-button {
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  /* Sidebar */
  .subpanel {
    padding: 12px;
  }

  .credential-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .credential-value-group {
    justify-content: flex-start;
  }

  .credential-row code {
    font-size: 0.72rem;
    word-break: break-all;
    min-width: 0;
  }

  .prefix-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .item-actions {
    flex-wrap: wrap;
  }

  .item-actions .button {
    flex: 1;
    text-align: center;
    min-width: 0;
  }

  /* Auth */
  .auth-panel {
    padding-top: 6vh;
    padding-left: 10px;
    padding-right: 10px;
  }

  .auth-card-body {
    padding: 28px 20px 24px;
  }

  .auth-heading {
    font-size: 1.15rem;
  }

  .auth-submit {
    min-height: 48px;
    font-size: 0.85rem;
  }

  .guide-content {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Toasts */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 16px;
    max-width: none;
  }
}

/* ══════════════════════════════════════════════════
   Responsive: narrow phone (<=400px)
   ══════════════════════════════════════════════════ */

@media (max-width: 400px) {
  .shell {
    padding: 8px 6px 32px;
  }

  .topbar {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
  }

  .panel {
    padding: 12px 10px;
    border-radius: var(--radius);
  }

  .tab {
    padding: 10px 4px;
    font-size: 0.66rem;
  }

  .topbar-brand {
    font-size: 1rem;
  }
}
