/* ============================================================
   ROOT TOKENS  (merged Index + Gallery into one block)
   ============================================================ */
:root {
  /* Backgrounds: Deep Midnight Blue */
  --bg:      #0A0F14;
  --surface: rgba(16, 22, 30, 0.85); /* Slightly lighter midnight for surfaces */
  --panel:   rgba(22, 30, 40, 0.75);
  --border:  rgba(255, 255, 255, 0.08);
  --border-bright: rgba(255, 255, 255, 0.15);

  /* Accent: Silicon Valley Blue (Standard Apple) */
  --accent: #007aff;
  --adim:   rgba(0, 122, 255, 0.12);
  --aglow:  rgba(0, 122, 255, 0.3);

  /* Text: High contrast readable */
  --text:   #ffffff;
  --muted:  #a0a0a5; /* Slightly softer gray */
  --hint:   #424245;

  /* Semantic */
  --ok:   #30d158;
  --err:  #ff453a;
  --warn: #ff9f0a;

  /* Media Categories */
  --photo: #0a84ff;
  --video: #bf5af2;
  --doc:   #ff9f0a;

  /* Modern Font Stack */
  --font: "Inter", "Roboto", -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;

  /* Radii & Sizes (Softer 8px UI) */
  --r:  8px;
  --rs: 8px;
  --gap: 24px;
  --row-h: 220px;
  --sidebar-w: 280px;
  --sidebar-collapsed-w: 72px;
  --drawer-w: 0px;
  --drawer-w-active: 360px;
  --std-h: 36px; /* Slightly taller for better touch/click targets */

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:     #f0f2f8;
    --panel:  #fff;
    --border: #dde0ee;
    --text:   #1a1d2e;
    --muted:  #72788a;
    color-scheme: light;
  }
}


/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

img, video { display: block; }
input, button, select { font-family: inherit; cursor: pointer; }

/* ============================================================
   BASE
   ============================================================ */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
  min-height: 100dvh;
  letter-spacing: -0.01em;
  overscroll-behavior-y: none;
}

/* App shell locks scroll; gallery page scrolls freely */
body.app-shell {
  height: 100vh;
  overflow: hidden;
}


/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar       { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.05); }
::-webkit-scrollbar-thumb { 
  background: var(--muted); 
  border-radius: 10px; 
  border: 2px solid transparent; 
  background-clip: content-box; 
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: content-box; }


/* ============================================================
   VIEWS
   ============================================================ */
.view        { display: none; height: 100vh; }
.view.active { display: flex; }

/* Auth views */
#va,
#vo {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: radial-gradient(ellipse 80% 60% at 50% 0%,
              rgba(79, 142, 255, .08), transparent 70%);
}


/* ============================================================
   AUTH CARD
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 40px;
  width: 400px;
  box-shadow: 0 32px 96px rgba(0, 0, 0, .6);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: var(--rs);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.logo-text { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.logo-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }

h2   { font-size: 18px; font-weight: 600; margin-bottom: 6px; }

.sub {
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.5;
  font-size: 13px;
}
.sub a { color: var(--accent); }

.f     { margin-bottom: 16px; }
.twofa { display: none; }

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

input[type=text],
input[type=number],
input[type=password],
input[type=tel],
input[type=date] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--adim);
}

.hint { font-size: 11px; color: var(--muted); margin-top: 5px; }

.err-msg {
  background: rgba(255, 87, 87, .1);
  border: 1px solid rgba(255, 87, 87, .3);
  border-radius: var(--rs);
  padding: 10px 14px;
  color: var(--err);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}


/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--rs);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-top: 4px;
}
.btn:active { transform: scale(0.96); }

.btn-p { 
  background: var(--accent); 
  color: #fff; 
  box-shadow: 0 4px 12px var(--aglow); 
}
.btn-p:hover { background: #3a78ff; transform: translateY(-1px); }

.btn-g { 
  background: rgba(255, 255, 255, 0.03); 
  color: var(--muted); 
  border: 1px solid var(--border); 
}
.btn-g:hover { 
  border-color: var(--border-bright); 
  color: var(--text); 
  background: rgba(255, 255, 255, 0.06); 
}


/* ============================================================
   APP LAYOUT
   ============================================================ */
#vapp { flex-direction: column; }

.topbar {
  height: 52px;
  background: rgba(10, 15, 20, 0.4);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 1000;
}


.header-controls {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

.search-wrap {
  width: 320px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: var(--r);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: var(--std-h);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}
.search-wrap:focus-within {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 0 3px var(--adim), inset 0 2px 4px rgba(0,0,0,0.5);
  width: 380px;
}
.search-icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
  margin-right: 8px;
}
.search-wrap input {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  height: 100% !important;
  font-size: 13px;
  color: var(--text);
  width: 100%;
}
.search-wrap input::placeholder { color: var(--hint); }

.filter-controls {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--r);
  border: 1px solid var(--border);
  height: var(--std-h);
  padding: 0 4px;
}
.mfilter-dropdown {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 0 12px;
  cursor: pointer;
  outline: none;
}
.filter-divider { width: 1px; height: 16px; background: var(--border); }
.header-action-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.header-action-btn:hover { color: var(--text); }
.header-action-btn i { width: 14px; height: 14px; }

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: 12px;
}
.logout-btn:hover {
  background: rgba(255, 69, 58, 0.1);
  border-color: var(--err);
  color: var(--err);
}
.logout-btn i { width: 14px; height: 14px; }


.tsp { flex: 1; }

.status-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 30px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
}
.status-pill:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--border-bright); }
.status-pill.active { color: var(--ok); background: rgba(48, 209, 88, 0.1); border-color: rgba(48, 209, 88, 0.2); }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  margin-left: 4px;
}
.conn-dot.active {
  background: var(--ok);
  box-shadow: 0 0 10px rgba(48, 209, 88, 0.4);
}

.ws {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 4px 1fr 4px var(--drawer-w, 0px);
  overflow: hidden;
  height: calc(100vh - 52px);
  position: relative;
  transition: grid-template-columns 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.ws.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 4px 1fr 4px var(--drawer-w, 0px);
}

.ws.drawer-open {
  grid-template-columns: var(--sidebar-w, 300px) 4px 1fr 4px var(--drawer-w-active);
}

.pd {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  transition: opacity 0.3s;
}

.ws:not(.drawer-open) .pd,
.ws:not(.drawer-open) #p-gutter {
  opacity: 0;
  pointer-events: none;
}

.gutter {
  width: 8px;
  margin: 0 -4px;
  background: transparent;
  cursor: col-resize;
  transition: background .2s;
  flex-shrink: 0;
  z-index: 1000; /* Ensure it stays above everything */
  position: relative;
}
.gutter:hover, .gutter.active {
  background: var(--adim);
  box-shadow: inset 0 0 0 1px var(--border);
}
.gutter::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 32px;
  background: var(--muted);
  border-radius: 1px;
  opacity: 0.3;
  pointer-events: none;
}
.gutter.active::after { background: var(--accent); opacity: 1; }


/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(10, 15, 20, 0.4);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.3s;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar.collapsed {
  width: var(--sidebar-collapsed-w);
}



.sidebar.collapsed .ci,
.sidebar.collapsed .stabs span,
.sidebar.collapsed .ss,
.sidebar.collapsed .ftabs,
.sidebar.collapsed .list-section,
.sidebar.collapsed .cn,
.sidebar.collapsed .cm .mem-count,
.sidebar.collapsed .ch-folder,
.sidebar.collapsed .sidebar-footer {
  display: none !important;
}



.sidebar.collapsed .ch {
  padding: 10px 0;
  justify-content: center;
}

.sidebar.collapsed .av {
  width: 44px;
  height: 44px;
  margin: 0;
}


.sidebar.collapsed .stab {
  padding: 16px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
.sidebar.collapsed .stabs {
  flex-direction: column;
}


.sidebar.collapsed .ch {
  justify-content: center;
  padding: 10px 0;
}

.sidebar.collapsed .av {
  width: 44px;
  height: 44px;
}

.sidebar.collapsed .cr {
  position: absolute;
  top: 6px;
  right: 12px;
}

.mem-badge {
  position: absolute;
  bottom: -4px;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  padding: 1px 4px;
  font-size: 8px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 1px;
  z-index: 2;
}

.sidebar.collapsed .mem-badge { display: flex; }
.sidebar:not(.collapsed) .mem-badge { display: none; }

.sidebar.collapsed .ch-unread {
  width: 14px;
  height: 14px;
  font-size: 8px;
}

/* Main tabs (Channels / External) */
.stabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.15);
}

.stab {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s, background .2s;
  letter-spacing: .3px;
}
.stab:hover { color: var(--text); background: rgba(79, 142, 255, .04); }
.stab.active { color: var(--accent); border-color: var(--accent); }

.sidebar-pane {
  flex: 1;
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto; /* Allow the pane itself to scroll if content is long */
  scrollbar-gutter: stable;
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-top: 1px solid var(--border);
  display: none;
  flex-direction: column;
  gap: 10px;
}
.sidebar-footer.active { display: flex; }
.ch-actions-count { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; }
.ch-actions-row { display: flex; gap: 8px; }
.ch-actions-row .vbtn { flex: 1; padding: 10px; border-radius: 8px; font-size: 12px; }
.sidebar-pane.active { display: flex; }

.s-section-header {
  padding: 18px 15px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(15, 18, 25, 1) 0%, rgba(15, 18, 25, 0) 100%);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ── Folder tabs ───────────────────────────────────────── */
.ftabs {
  display: flex;
  gap: 6px;
  padding: 10px 10px 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  scrollbar-width: none;
  background: rgba(0,0,0,.08);
}
.ftabs::-webkit-scrollbar { display: none; }

.ftab {
  padding: 5px 14px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all .2s cubic-bezier(.4, 0, .2, 1);
  letter-spacing: .2px;
}
.ftab:hover {
  background: rgba(79, 142, 255, .1);
  color: var(--text);
  transform: translateY(-1px);
}
.ftab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(79, 142, 255, .35);
}

.folder-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.folder-dropdown select {
  font-family: inherit;
  outline: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
}

.folder-dropdown select:focus {
  border-color: var(--accent);
}

/* ── Folder badge on channel card ──────────────────────── */
.ch-folder {
  display: inline-block;
  background: linear-gradient(135deg, rgba(79, 142, 255, .15), rgba(79, 142, 255, .08));
  color: var(--accent);
  font-size: 9px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: .2px;
}

/* ── Search strip ──────────────────────────────────────── */
.ss { padding: 10px; border-bottom: 1px solid var(--border); }
.sw { position: relative; }
.sw input {
  padding-left: 34px;
  background: rgba(255,255,255,.04);
  font-size: 12px;
  border-color: rgba(255,255,255,.06);
  border-radius: 10px;
}
.sw input:focus {
  background: rgba(79, 142, 255, .06);
}
.si { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }

/* ── Channel list ──────────────────────────────────────── */
.cl { flex: 1; overflow-y: auto; padding: 6px; }

.list-section {
  padding: 12px 14px 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  opacity: 0.6;
}

.ch-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 4px;
  box-shadow: 0 0 10px var(--adim);
}

.ch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s cubic-bezier(.4, 0, .2, 1);
  user-select: none;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.ch:hover {
  background: rgba(255,255,255,.04);
  transform: translateX(2px);
}
.ch.sel {
  background: var(--adim);
  border-color: var(--accent);
  box-shadow: 0 4px 15px rgba(0, 122, 255, 0.15);
}
.ch.sel .av { background: var(--accent) !important; color: #fff !important; }
.ch.sel .cn { color: #fff; font-weight: 600; }


.av {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  flex-shrink: 0;
  transition: transform .2s;
}
.ch:hover .av { transform: scale(1.05); }

.ci  { flex: 1; min-width: 0; transition: opacity 0.2s; }
.cn  { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cm  { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; }
.cm .mem-icon { font-size: 9px; opacity: 0.6; }

.cr {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.ch-unread {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  padding: 0 5px;
  box-shadow: 0 2px 8px var(--adim);
  animation: badgeIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badgeIn {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

.ck {
  width: 18px; height: 18px;
  border: 1.5px solid rgba(255,255,255,.15);
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: all .2s cubic-bezier(.34, 1.56, 0.64, 1);
}
.ch:hover .ck { border-color: rgba(79, 142, 255, .4); }
.ch.sel .ck {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(79, 142, 255, .3);
  transform: scale(1.1);
}

/* ── Sidebar footer ────────────────────────────────────── */
.floating-cta {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(20, 20, 22, 0.85);
  backdrop-filter: blur(25px) saturate(180%);
  border: 1px solid var(--border-bright);
  border-radius: 50px;
  padding: 6px 6px 6px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1100;
  box-shadow: 0 15px 45px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.floating-cta.active {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}

.cta-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.cta-count b {
  color: var(--accent);
}

.vbtn {
  flex: 1;
  height: 100%;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 40px;
  font-size: 11px; 
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.vbtn:hover { 
  background: var(--accent); 
  color: #fff; 
  border-color: var(--accent);
  transform: translateY(-1px); 
}
.vbtn:active { transform: scale(0.96); }
.vbtn:disabled { opacity: .4; cursor: default; }

.vbtn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

#selall-ch {
  flex: 0 0 auto;
  background: rgba(255,255,255,.05) !important;
  border: 1px solid rgba(255,255,255,.1) !important;
  color: var(--muted) !important;
  transition: all .2s !important;
}
#selall-ch:hover {
  background: rgba(255, 255, 255, 0.1) !important;
  color: var(--text) !important;
}


/* ============================================================
   EXTERNAL PANE
   ============================================================ */
.ext-pane {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ext-pane textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 10px;
  color: var(--text);
  font-size: 13px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
.ext-pane textarea:focus { border-color: var(--accent); }

.ext-pane select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  outline: none;
}
.ext-pane .btn-p { margin-top: 0; }

.ext-history, 
#mir-syncs { 
  display: flex;
  flex-direction: column;
  padding: 0 10px 20px;
}

.ext-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 12px;
  margin-bottom: 8px;
  font-size: 12px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.ext-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(79, 142, 255, 0.3);
  transform: translateY(-1px);
}

.ext-url { 
  color: var(--text); 
  font-weight: 600;
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  margin-bottom: 6px; 
}

.ext-status {
  font-size: 11px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ext-prog { 
  height: 4px; 
  background: var(--border); 
  border-radius: 4px; 
  margin: 10px 0; 
  overflow: hidden; 
}

.ext-pbar { 
  height: 100%; 
  background: var(--accent-grad); 
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); 
  border-radius: 4px; 
  width: 0%; 
}

.m-logs {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  padding: 8px;
  margin-top: 10px;
  max-height: 250px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.4;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.m-logs div {
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.sync-rule-card {
  border-left: 3px solid var(--ok);
  background: linear-gradient(90deg, rgba(53, 212, 123, 0.05) 0%, transparent 100%);
}


/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  overflow: hidden; 
  min-height: 0; min-width: 0; /* Fix grid overflow scroll */
}

/* Toolbar */
.toolbar {
  position: sticky;
  top: 12px;
  z-index: 100;
  margin: 6px auto;
  width: fit-content;
  max-width: 90%;
  pointer-events: none;
}

.toolbar .t1 {
  pointer-events: auto;
  background: rgba(25, 25, 27, 0.8);
  backdrop-filter: blur(30px) saturate(150%);
  -webkit-backdrop-filter: blur(30px) saturate(150%);
  border: 1px solid var(--border-bright);
  border-radius: 100px;
  padding: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toolbar .t1:hover {
  background: rgba(30, 30, 32, 0.85);
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.2);
}

.pills { display: flex; gap: 6px; align-items: center; }

.pill {
  height: var(--std-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 30px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.pill.active { background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 12px var(--aglow); }
.pill:hover:not(.active) { background: rgba(255, 255, 255, 0.08); color: var(--text); }

select.pill {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2386868B' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 32px;
  cursor: pointer;
}

select.pill:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--adim);
}

#selall-btn {
  width: var(--std-h);
  padding: 0;
}

.tsp2 { flex: 1; }

.search-wrap { position: relative; width: 180px; display: flex; align-items: center; }
.search-wrap input { 
  height: var(--std-h);
  padding: 0 12px 0 32px; 
  font-size: 12px; 
  background: rgba(0, 0, 0, 0.2);
  border-radius: 30px;
  border: 1px solid transparent;
  width: 100%;
  transition: all 0.2s;
}
.search-wrap input:focus {
  background: rgba(0, 0, 0, 0.4);
  border-color: var(--accent);
  width: 220px;
}
.search-wrap .si { font-size: 13px; opacity: 0.5; left: 12px; position: absolute; top: 50%; transform: translateY(-50%); }

.sort-wrap {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--std-h);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 30px;
  border: 1px solid transparent;
  transition: background 0.2s;
}
.sort-wrap:hover { background: rgba(255, 255, 255, 0.08); }

select.sort {
  background: transparent;
  border: none;
  width: 38px;
  height: 100%;
  font-size: 0;
  padding: 0;
  cursor: pointer;
  outline: none;
}

.ibox-btn {
  padding: 7px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.ibox-btn:hover {
  background: rgba(79, 142, 255, 0.15);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}
/* Zoom Slider */
.zoom-wrap { display: flex; align-items: center; gap: 8px; margin-right: 15px; opacity: 0.8; transition: opacity 0.2s; }
.zoom-wrap:hover { opacity: 1; }
.zoom-wrap span { font-size: 14px; }
#grid-zoom {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
#grid-zoom::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px var(--aglow);
  transition: transform 0.1s;
}
#grid-zoom::-webkit-slider-thumb:hover { transform: scale(1.2); }

.ibox-btn:active { transform: scale(0.94) translateY(0) !important; }
.ibox-btn.primary { background: var(--adim); color: var(--accent); border-color: var(--adim); }

.ibox-btn.all-selected {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
  box-shadow: 0 4px 15px var(--aglow) !important;
}
.ibox-btn.all-selected:hover {
  background: #3a78ff !important;
}

/* Date row */
.t2 { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.t2 input { width: 150px; padding: 5px 10px; font-size: 12px; background: var(--panel); }
.t2 input::-webkit-calendar-picker-indicator { filter: invert(.5); }


/* ============================================================
   STREAM BAR
   ============================================================ */
.stream-bar {
  padding: 4px 16px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: none;               /* hidden by default */
  align-items: center;
  gap: 10px;
  overflow: hidden;
}
.stream-bar.active { display: flex; }   /* show when streaming */

.sb-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

.pause-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--muted);
}
.pause-btn:hover { color: var(--text); border-color: var(--text); }


/* ============================================================
   MEDIA GRID
   ============================================================ */
.media-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding: 0;
  -webkit-overflow-scrolling: touch;
  will-change: scroll-position;
  background: var(--bg);
}

.lasso {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(0, 122, 255, 0.15);
  z-index: 1000;
  pointer-events: none;
  border-radius: 4px;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}
.empty-icon { font-size: 48px; opacity: .2; }


/* ============================================================
   MEDIA CARD  (.mc)
   ============================================================ */
/* ============================================================
   MEDIA CARD  (.mc)
   ============================================================ */
/* ── Skeleton Loading ──────────────────────────────────────── */
@keyframes shimmer {
  0% { background-position: -468px 0; }
  100% { background-position: 468px 0; }
}

.sk {
  background: rgba(255,255,255,0.03);
  background-image: linear-gradient(to right, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.08) 20%, rgba(255,255,255,0.03) 40%, rgba(255,255,255,0.03) 100%);
  background-repeat: no-repeat;
  background-size: 800px 100%;
  border-radius: 8px;
  animation: shimmer 1.2s linear infinite;
  border: none !important;
}

.mc {
  position: relative;
  border-radius: var(--rs);
  overflow: hidden;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0; /* No padding for full visual */
  display: flex !important;
  flex-direction: column;
  box-sizing: border-box;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  animation: fadeUp 0.4s ease-out;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.mc:hover {
  transform: translateY(-6px) scale(1.05); /* Sensory Cue: Physical scale up */
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}


.mc.sel { 
  box-shadow: 0 0 0 3px var(--accent);
  background: var(--adim);
}

.mc.dl { opacity: .4; }

/* Tactical Focus (Neon Overlay) */
.mc.kb-focus {
  outline: 3px solid #00f3ff; /* Electric Blue */
  outline-offset: 4px;
  box-shadow: 0 0 25px rgba(0, 243, 255, 0.6);
  z-index: 100;
  transform: scale(1.02);
}


/* Thumbnail / Media Area */
.m-thumb-area {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9; /* Consistent cinematic aspect ratio */
  background: var(--bg);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* Subtle bottom-to-top dark gradient for text legibility */
.m-thumb-area::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.4) 40%, transparent 80%);
  z-index: 2;
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

.mc:hover .m-thumb-area::after {
  opacity: 1;
}

.mc img, .mc video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  transition: transform .6s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  z-index: 1;
}

.mc:hover img, .mc:hover video { 
  transform: scale(1.1); 
}

/* Ambient blur background (removed as we have solid background now) */
.mc::before { display: none; }

/* Placeholder / Document Icon */
.mc .nth {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; color: var(--muted);
}
.mc .nth .ti { 
  font-size: 32px; 
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

/* Checkbox */
.mchk {
  position: absolute;
  top: 8px; left: 8px;
  width: 26px; height: 26px;
  background: rgba(var(--bg), 0.8);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center; justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 5;
  opacity: 0;
  transform: scale(0.9);
}
.mc:hover .mchk, .mc.sel .mchk { opacity: 1; transform: scale(1); }

.mchk svg {
  display: block;
  opacity: 0;
  width: 14px; height: 14px;
  transform: scale(0.5);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mc.sel .mchk { 
  background: var(--accent); 
  border-color: #fff; 
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.5); 
}
.mc.sel .mchk svg { 
  opacity: 1; transform: scale(1.2); stroke: #ffffff !important; stroke-width: 2.5px !important;
}

/* Type badge */
.tbadge {
  position: absolute;
  top: 8px; right: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 9px; font-weight: 800;
  letter-spacing: .5px;
  backdrop-filter: blur(8px);
  z-index: 5;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.bp { background: rgba(0, 122, 255, 0.85); color: #fff; }
.bv { background: rgba(191, 90, 242, 0.85); color: #fff; }
.bd { background: rgba(255, 159, 10, 0.85);  color: #fff; }

/* Media Details (Ghost Metadata) */
.m-details {
  position: absolute;
  top: 14px;
  left: 50px; /* Offset to avoid checkbox */
  right: 14px;
  z-index: 10;
  opacity: 0; 
  transform: translateY(-5px);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.mc:hover .m-details, .mc.sel .m-details {
  opacity: 1;
  transform: translateY(0);
}

.mfn { 
  font-size: 11px; 
  font-weight: 700; 
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
}
.msz { 
  font-size: 10px; 
  color: rgba(255,255,255,0.7); 
  font-weight: 600;
}

/* Document specific */
.mc-doc .m-thumb-area {
  background: rgba(var(--doc), 0.05);
}
.mc-doc .nth .ti {
  font-size: 48px;
}

/* Preview eye */
.mpreview {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.5);
  background: rgba(0, 0, 0, .4);
  color: #fff;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center; justify-content: center;
  font-size: 18px;
  opacity: 0;
  transition: all .3s cubic-bezier(.175, .885, .32, 1.275);
  backdrop-filter: blur(8px);
  z-index: 3;
}
.mc:hover .mpreview { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* Caption (Slang/Meaning Overlay) */
.mcap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  z-index: 5;
  font-size: 15px; /* Slightly larger for prominence */
  font-weight: 700;
  color: #ffffff;
  line-height: 1.3;
  font-family: var(--font); /* High-contrast white sans-serif */
  text-shadow: 0 2px 15px rgba(0,0,0,0.8);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mc:hover .mcap {
  transform: translateY(-5px);
}

/* Gallery mode tweaks (Pruning redundant overrides) */
.gallery-mode .mc { 
  padding: 0;
}
.gallery-mode .mc .m-thumb-area {
  aspect-ratio: 16 / 9;
}

.card-vid { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }


/* ── Selection Action Pill ────────────────────────────────────── */
.selection-pill {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translate(-50%, 100px);
  background: rgba(10, 15, 20, 0.4);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 8px 12px 8px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 2100;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s;
}

.selection-pill.active {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: all;
}

.pill-count {
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  opacity: 0.9;
  white-space: nowrap;
}

.pill-count b {
  font-weight: 700;
  color: var(--accent);
}

.pill-divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.1);
  flex-shrink: 0;
}

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

.pill-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pill-btn:hover {
  background: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px var(--aglow);
}

.pill-btn.danger:hover {
  background: var(--err);
  box-shadow: 0 8px 16px rgba(255, 69, 58, 0.4);
}

.pill-btn i {
  width: 18px;
  height: 18px;
}

@media (max-width: 768px) {
  .selection-pill {
    bottom: 80px;
    padding: 8px;
    gap: 8px;
    width: auto;
    max-width: 90vw;
  }
}


/* ============================================================
   BOTTOM BAR
   ============================================================ */
.bb {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 64px;
  background: rgba(10, 10, 12, 0.85);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-top: 1px solid var(--border-bright);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 20px;
  z-index: 2000;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  transform: translateY(100px);
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s;
  opacity: 0;
  pointer-events: none;
}

.bb.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}


/* Text */
.bbc {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bbc b {
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

/* Button */
.dlbtn {
  margin-left: auto;

  padding: 10px 22px;
  border: none;
  border-radius: 999px;

  font-size: 13px;
  font-weight: 600;

  display: flex;
  align-items: center;
  gap: 6px;

  color: #fff;
  background: var(--accent);

  cursor: pointer;

  transition:
    background 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.1s ease;
}

/* Hover */
.dlbtn:hover {
  background: #3a78ff;
  box-shadow: 0 4px 20px var(--aglow);
}

/* Active press feel */
.dlbtn:active {
  transform: scale(0.97);
}

/* Disabled */
.dlbtn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

/* Focus (like your button example) */
.dlbtn:focus-visible {
  outline: 1.5px solid var(--text-primary);
  outline-offset: 2.5px;
}

/* Icon */
.dlbtn svg {
  width: 15px;
  height: 15px;
}
/* ── Floating Contextual Action Bar ────────────────────────── */
.floating-cta {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 15, 20, 0.7);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  padding: 8px 16px;
  border-radius: 40px;
  border: 1px solid var(--border-bright);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: none; /* Only show when items are selected */
  align-items: center;
  gap: 12px;
  z-index: 2500;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.floating-cta.active { display: flex; }
.cta-count { font-size: 11px; font-weight: 600; color: var(--muted); padding-left: 8px; border-right: 1px solid var(--border); padding-right: 12px; }

@media (max-width: 768px) {
  .floating-cta {
    bottom: 80px;
    width: calc(100% - 32px);
    justify-content: space-between;
  }
}


.pd {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s;
  height: 100%;
  flex-shrink: 0;
  z-index: 100;
  min-height: 0; min-width: 0; /* Fix grid overflow scroll */
}
/*.pd.open is no longer needed as it's part of the persistent grid */

.dh { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.dt { font-weight: 600; flex: 1; font-size: 13px; }
.dc { background: none; border: none; color: var(--muted); font-size: 17px; line-height: 1; }
.dc:hover { color: var(--text); }

.pl      { flex: 1; overflow-y: auto; padding: 10px; }
.pitem   { background: var(--panel); border-radius: var(--rs); padding: 10px; margin-bottom: 7px; }
.pn      { font-size: 11px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.pb-wrap { background: var(--border); border-radius: 3px; height: 3px; overflow: hidden; }
.pb      { height: 100%; background: var(--accent); transition: width .3s; border-radius: 3px; }

.pm      { display: flex; justify-content: space-between; margin-top: 5px; font-size: 10px; color: var(--muted); }
.perr    { color: var(--err); font-size: 10px; margin-top: 3px; }

.pcancel { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px; font-size: 10px; color: var(--muted); margin-top: 5px; }
.pcancel:hover { border-color: var(--err); color: var(--err); }

/* ============================================================
   NATIVE LIGHTBOX (SMOOTH TRANSITIONS)
   ============================================================ */

.lb {
  position: fixed;
  inset: 0;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  overflow: hidden;
}
.lb.open {
  opacity: 1;
  pointer-events: all;
}

body.lb-active {
  overflow: hidden !important;
}

body.lb-active .topbar,
body.lb-active .sidebar,
body.lb-active .mobile-nav,
body.lb-active .selection-pill,
body.lb-active .pd,
body.lb-active .ext-mgr {
  display: none !important;
}



.lb-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92); /* Deeper dim for focus */
  backdrop-filter: blur(40px) saturate(150%); /* More blur for 'dead space' fill */
  -webkit-backdrop-filter: blur(40px) saturate(150%);
  cursor: zoom-out;
}

.lb-bloom {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 70vw; height: 70vh; /* Larger bloom */
  opacity: 0.6;
  filter: blur(150px) saturate(250%);
  z-index: 1;
  pointer-events: none;
  animation: bloomPulse 6s ease-in-out infinite;
}

.lb-bloom img, .lb-bloom video {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

@keyframes bloomPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.4; }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.6; }
}

.lb-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 50px; /* Safety gutter to prevent overflow */
  z-index: 10;
  pointer-events: none;
}

.lb-content img,
.lb-content video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: all;
  border-radius: 4px;
  box-shadow: 0 60px 180px rgba(0,0,0,0.95), 0 0 0 1px rgba(255,255,255,0.08);
  animation: lb-zoom-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Each slide */
.lb-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  flex-shrink: 0;
  padding: 0 40px;
  box-sizing: border-box;

  /* Smooth crossfade */
  opacity: 0;
  transform: scale(0.98);
  transition:
    opacity 0.45s ease,
    transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);

  will-change: transform, opacity;
}

/* Active slide */
.lb-panel.active {
  opacity: 1;
  transform: scale(1);
  z-index: 2;
}

/* Outgoing slide (optional helper class from JS) */
.lb-panel.prev {
  opacity: 0;
  transform: scale(1.02);
  z-index: 1;
}

/* Media (image/video) */
.lb-media {
  max-width: 100%;
  max-height: 92vh;
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  background: #000;

  /* IMPORTANT: no animation here */
  display: block;
}

.lb-panel video.lb-media {
  background: transparent;
}

/* Close button */
.lb-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  backdrop-filter: blur(8px);
}
.lb-close:hover {
  background: rgba(255,255,255,0.22);
  transform: scale(1.1);
}

/* Navigation buttons */
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  backdrop-filter: blur(8px);
}
.lb-nav:hover {
  background: rgba(255,255,255,0.22);
  transform: translateY(-50%) scale(1.08);
}
.lb-prev { left: 16px; }
.lb-next { right: 16px; }

/* Info text */
.lb-info {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255,255,255,0.8);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  backdrop-filter: blur(8px);
  white-space: nowrap;
  pointer-events: none;
}

/* Loading spinner */
.lb-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lb-spin 0.7s linear infinite;
}
@keyframes lb-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   TOASTS
   ============================================================ */
#toasts {
  position: fixed;
  bottom: 80px; right: 16px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  animation: slide-in .25s ease;
  max-width: 300px;
}
.toast.ok   { border-color: rgba(53, 212, 123, .4); color: var(--ok); }
.toast.err  { border-color: rgba(255, 87, 87, .4);  color: var(--err); }
.filter-wrap {
  display: flex;
  align-items: center;
}

select.pill {
  height: var(--std-h);
  border: 1px solid var(--border-bright);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 30px;
  padding: 0 32px 0 16px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}

select.pill:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
}

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}


/* ============================================================
   SKELETON LOADER
   ============================================================ */
.sk {
  background: linear-gradient(90deg, var(--panel) 25%, var(--border) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: sh 1.4s infinite;
  border-radius: var(--rs);
}
@keyframes sh {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ============================================================
   GALLERY PAGE  (gallery.html)
   ============================================================ */
header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex; align-items: center; gap: 14px;
  backdrop-filter: blur(12px);
}

.h-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  color: var(--muted); font-size: 12px;
  transition: border-color .15s, color .15s;
}
.h-back:hover { border-color: var(--accent); color: var(--text); }

.h-logo { font-size: 17px; font-weight: 700; letter-spacing: -.4px; }
.h-sub  { color: var(--muted); font-size: 13px; font-weight: 400; }
.h-ct   { margin-left: auto; font-size: 12px; color: var(--muted); }

.h-mode { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; color: var(--muted); font-size: 12px; }
.h-mode:hover { border-color: var(--accent); color: var(--text); }

/* Masonry grid */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: var(--row-h);
  gap: var(--gap);
  padding: 20px 28px 60px;
  max-width: 1600px;
  margin: 0 auto;
}

@media (max-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width:  720px) { .grid { grid-template-columns: repeat(2, 1fr); --row-h: 150px; padding: 12px; } }
@media (max-width:  440px) { .grid { grid-template-columns: 1fr; } }

/* Gallery card — uses .card token from auth section; override layout props */
.grid .card {
  position: relative;
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--border);
  animation: fadeUp .55s cubic-bezier(.22, 1, .36, 1) both;
  animation-delay: calc(var(--i, 0) * 60ms);
  transition: transform .28s cubic-bezier(.34, 1.3, .64, 1), box-shadow .28s, border-color .2s;
  /* reset auth-card padding/width */
  padding: 0; width: auto; box-shadow: none;
}
.grid .card:hover {
  transform: translateY(-6px) scale(1.015);
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  border-color: rgba(79, 142, 255, .5);
  z-index: 2;
}

.card.wide { grid-column: span 2; }
.card.tall { grid-row: span 2; }
@media (max-width: 440px) { .card.wide, .card.tall { grid-column: span 1; grid-row: span 1; } }

.card-media { width: 100%; height: 100%; object-fit: cover; transition: transform .5s; }
.grid .card:hover .card-media { transform: scale(1.06); }

.card-grad {
  position: absolute; inset: 0;
  background: linear-gradient(0deg, rgba(0,0,0,.75) 0%, rgba(0,0,0,.10) 40%, transparent 65%);
  pointer-events: none;
}

/* Play button */
.play-ring { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; transition: opacity .2s cubic-bezier(.34, 1.5, .64, 1); pointer-events: none; }
.play-btn {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  transition: transform .2s cubic-bezier(.34, 1.5, .64, 1);
  pointer-events: auto;
}
.grid .card:hover .play-ring { opacity: 0; transform: scale(0.9); }
.grid .card:hover .play-btn { transform: scale(1.12); }
.play-btn svg { width: 18px; height: 18px; fill: #080b11; margin-left: 3px; }

/* Badges (reuse .bp / .bv / .bd) */
.badge {
  position: absolute;
  top: 10px; right: 10px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 9px; font-weight: 700;
  letter-spacing: .6px; text-transform: uppercase;
  backdrop-filter: blur(8px);
}

/* Card caption */
.card-caption {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 32px 14px 14px;
  transform: translateY(8px); opacity: 0;
  transition: transform .3s, opacity .3s;
}
.grid .card:hover .card-caption { transform: none; opacity: 1; }

.card-title { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub   { font-size: 10px; color: rgba(255,255,255,.6); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


/* ============================================================
   LIGHTBOX
   ============================================================ */
.lb {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 5, 10, .93);
  backdrop-filter: blur(14px);
  opacity: 0; pointer-events: none;
  transition: opacity .28s;
}
.lb.open { opacity: 1; pointer-events: all; }

.lb-wrap {
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
  max-width: 92vw;
  transform: scale(.88); opacity: 0;
  transition: transform .35s cubic-bezier(.34, 1.4, .64, 1), opacity .3s;
}
.lb.open .lb-wrap { transform: scale(1); opacity: 1; }

.lb-box { border-radius: 16px; overflow: hidden; box-shadow: 0 40px 120px rgba(0,0,0,.8); }
.lb-box img,
.lb-box video {
  max-width: min(96vw, 1000px);
  max-height: 78vh;
  display: block;
  border-radius: 16px;
  object-fit: contain;
}

.lb-cap  { text-align: center; max-width: min(96vw, 800px); }
.lb-title{ font-size: 16px; font-weight: 600; color: #fff; line-height: 1.4; }
.lb-sub  { font-size: 12px; color: var(--muted); margin-top: 5px; }
.lb-full {
  font-size: 13px; color: rgba(220,224,240,.85);
  margin-top: 10px; line-height: 1.7;
  max-height: 90px; overflow-y: auto;
  white-space: pre-wrap;
  background: rgba(255,255,255,.05);
  border-radius: 8px; padding: 10px 14px; text-align: left;
}

.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px;
  transition: background .2s;
  backdrop-filter: blur(8px);
}
.lb-nav:hover { background: rgba(255,255,255,.18); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }

.lb-close {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 100;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 50%;
  font-size: 18px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.lb-close:hover { 
  background: rgba(255, 69, 58, 0.8); 
  transform: rotate(90deg) scale(1.1); 
  border-color: transparent;
}

.lb-cnt {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%);
  font-size: 12px; color: rgba(255,255,255,.45);
}


/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  0% { opacity: 0; transform: translateY(16px) scale(.98); }
  100% { opacity: 1; transform: none; }
}

.m-logs {
  background: rgba(0,0,0,.3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 10px;
  color: var(--muted);
}
.m-logs div { border-bottom: 1px solid rgba(255,255,255,.03); padding: 2px 0; }
/* ── True Preview (Hover) ───────────────────────── */
.true-preview {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.8);
  border-radius: 12px;
  overflow: hidden;
  display: none;
  width: 450px;
  max-width: 80vw;
  max-height: 80vh;
  animation: peekIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, opacity;
}

.true-preview img, 
.true-preview video {
  width: 100%;
  height: auto;
  display: block;
}

@keyframes peekIn {
  0% { transform: scale(0.9) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes badgePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); filter: brightness(1.5); box-shadow: 0 0 15px var(--ok); }
  100% { transform: scale(1); }
}

.ch-unread.pulse {
  animation: badgePulse 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mc.kb-focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 10;
}

/* ============================================================
   MOBILE LAYOUT & NAVIGATION
   ============================================================ */
.mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  body.app-shell { overflow: hidden; }
  .ws {
    display: flex; /* Override grid */
    flex-direction: column;
    height: calc(100vh - 52px - 64px); 
    overflow: hidden;
  }
  
  .gutter { display: none !important; }
  
  /* Panes act as full screen views */
  .sidebar, .main, .pd {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important;
    height: 100%;
    z-index: 1;
    opacity: 0;
    pointer-events: none;
    transform: translateY(15px) scale(0.98);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: var(--bg);
  }

  
  /* When a mobile pane is active */
  .sidebar.m-active, .main.m-active, .pd.m-active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    z-index: 10;
  }

  .sidebar-pane {
    height: 100%;
  }

  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(15, 18, 25, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1500;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .m-nav-item {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

  .m-nav-icon {
    font-size: 22px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.3s;
    filter: drop-shadow(0 0 0 rgba(0, 122, 255, 0));
  }
  
  .m-nav-item.active .m-nav-icon {
    transform: scale(1.15) translateY(-2px);
    filter: drop-shadow(0 4px 8px rgba(0, 122, 255, 0.4));
  }

  .topbar-hints { display: none; }
  
  .bb {
    bottom: 80px; /* above mobile nav */
    width: calc(100% - 32px);
    z-index: 1600;
  }
  .sf {
    bottom: 88px;
    width: calc(100% - 32px);
    z-index: 1600;
  }

  .toolbar .t1 {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
  .toolbar .t1::-webkit-scrollbar { display: none; }
  
  .search-wrap { width: auto; flex-grow: 1; }
  .zoom-wrap { display: none; }
  .pills { flex-shrink: 0; }
  
  .media-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    display: grid !important; /* Ensure grid on mobile */
    gap: 12px !important;
    padding: 12px 12px 100px !important;
    --row-h: 180px !important;
  }
  
  .pd { width: 100%; border-left: none; }
  #sbar-txt { max-width: 140px; }
}

#load-more:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--accent);
}

/* ============================================================
   COMMAND PALETTE
   ============================================================ */
.cp-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 20, 0.8);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  z-index: 5000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.cp-overlay.active { display: flex; }

.cp-box {
  background: var(--surface);
  width: 640px;
  max-width: 90vw;
  border-radius: 16px;
  border: 1px solid var(--border-bright);
  box-shadow: 0 40px 100px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.1);
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.cp-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 24px;
  color: var(--text);
  font-size: 18px;
  font-weight: 500;
  outline: none;
  width: 100%;
}

.cp-results {
  max-height: 480px;
  overflow-y: auto;
  padding: 8px;
}

.cp-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s;
  margin-bottom: 2px;
}
.cp-item:hover, .cp-item.active {
  background: var(--adim);
  transform: translateX(4px);
}
.cp-item-icon { font-size: 18px; opacity: 0.8; }
.cp-item-text { flex: 1; font-weight: 500; font-size: 14px; }
.cp-item-type { 
  font-size: 10px; 
  font-weight: 700;
  text-transform: uppercase; 
  color: var(--muted); 
  letter-spacing: 0.8px; 
  background: rgba(255,255,255,0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

@keyframes slideDown {
  from { transform: translateY(-20px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

