/* ── App Layout Structure ──────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  transition: transform .3s ease, width .3s ease;
  z-index: 10;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  position: fixed;
  height: 100%;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 22px;
}
.logo-glyph { flex-shrink: 0; }
.logo-text { display: flex; flex-direction: column; }
.logo-main {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.2px;
}
.logo-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: .5px;
  text-transform: uppercase;
}

/* Sidebar nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s ease;
  text-align: left;
  width: 100%;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-muted);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(129,140,248,.2);
}
.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 8px 12px 4px;
}

.nav-item-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.nav-item-wrap .nav-item {
  flex: 1;
}

.nav-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
  border: 1px solid var(--border);
}

.nav-external-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s ease;
  flex-shrink: 0;
}
.nav-external-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--accent);
}

/* ── Embedded Service View Styles ── */
.embedded-view-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  background: #090d16;
  position: relative;
  overflow: hidden;
}

.embedded-view-wrap.hidden {
  display: none !important;
}

.embedded-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.embedded-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.embedded-service-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-muted);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(129, 140, 248, 0.3);
}

.embedded-service-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.embedded-service-url {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

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

.embedded-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: all .15s ease;
}

.embedded-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}

.embedded-btn.highlight {
  background: var(--accent-muted);
  color: var(--accent);
  border-color: rgba(129, 140, 248, 0.4);
}
.embedded-btn.highlight:hover {
  background: var(--accent);
  color: #fff;
}

.embedded-btn.close {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}
.embedded-btn.close:hover {
  background: rgba(239, 68, 68, 0.25);
}

.embedded-frame-box {
  flex: 1;
  width: 100%;
  height: calc(100% - 49px);
  position: relative;
}

.embedded-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #0f172a;
}

/* Sidebar stats */
.sidebar-stats {
  margin: 16px 12px 0;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-val { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

/* Sidebar Backdrop for Mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 45;
}
.sidebar-backdrop.active {
  display: block;
}

.sidebar-close-btn {
  display: none;
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
.sidebar-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Main Wrap ────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 5;
}

.sidebar-toggle {
  width: 34px; height: 34px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all .18s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-toggle svg { width: 18px; height: 18px; }

/* Search */
.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0 14px;
  max-width: 480px;
  transition: border-color .18s, box-shadow .18s;
}
.search-wrap:focus-within {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-icon-svg { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  padding: 9px 0;
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-kbd {
  font-size: 10px;
  padding: 2px 5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

/* Topbar actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.view-btn, .icon-btn {
  width: 34px; height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all .18s;
}
.view-btn svg, .icon-btn svg { width: 16px; height: 16px; }
.view-btn:hover, .icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.view-btn.active {
  background: var(--accent-muted);
  border-color: rgba(129,140,248,.3);
  color: var(--accent);
}

/* ── Breadcrumb ───────────────────────────────────────────── */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 22px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 44px;
}

.crumb {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: all .15s;
  position: relative;
}
.crumb:not(:last-child)::after {
  content: '/';
  position: absolute;
  right: -8px;
  color: var(--text-muted);
  opacity: .5;
}
.crumb:hover { background: var(--bg-hover); color: var(--text-primary); }
.crumb.active { color: var(--text-primary); font-weight: 600; cursor: default; }
.crumb.active:hover { background: transparent; }
.crumb-icon { width: 13px; height: 13px; opacity: .7; }

/* ── Gallery Area ─────────────────────────────────────────── */
.gallery-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
  user-select: none;
  -webkit-user-select: none;
}
.gallery-area::-webkit-scrollbar { width: 6px; }
.gallery-area::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

/* Section headings inside gallery */
.gallery-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.gallery-section-title:not(:first-child) { margin-top: 28px; }

/* ── Grid View ────────────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.gallery-grid.list-view {
  grid-template-columns: 1fr;
  gap: 4px;
}

/* Mobile Floating Action Button (FAB) */
.fab-group {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 999;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.fab-move-btn, .fab-upload-btn {
  display: flex;
  color: #fff;
  border: none;
  border-radius: 30px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}
.fab-move-btn {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  box-shadow: 0 4px 16px rgba(2, 132, 199, .5);
}
.fab-upload-btn {
  background: linear-gradient(135deg, var(--accent-dim), #4f46e5);
  box-shadow: 0 6px 20px rgba(99,102,241,.5);
}
.fab-move-btn:active, .fab-upload-btn:active {
  transform: scale(0.95);
}

/* ── Responsive Layout ────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }

  .sidebar {
    position: fixed;
    height: 100%;
    left: 0;
    top: 0;
    transform: translateX(calc(-1 * var(--sidebar-w)));
    transition: transform .28s ease;
    z-index: 50;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-close-btn {
    display: block;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }

  .search-kbd { display: none; }

  .topbar {
    padding: 0 10px;
    gap: 8px;
  }
  .search-wrap {
    min-width: 0;
    max-width: 220px;
    padding: 0 8px;
  }
  .search-input {
    font-size: 12px;
  }
  .fab-group {
    display: flex;
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .topbar-actions .upload-btn span,
  .topbar-actions .move-btn span {
    display: none;
  }
  .topbar-actions .upload-btn,
  .topbar-actions .move-btn {
    padding: 7px 9px;
  }
}

/* Global scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
