 /* ============================================
   HUNTERSTAR UX 2.0 — LUXURY CRIMSON
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg-deep: #050505;
  --bg-surface: #0a0a0c;
  --bg-glass: rgba(10, 10, 12, 0.7);
  --border-red: rgba(176, 0, 32, 0.2);
  --border-red-glow: rgba(176, 0, 32, 0.5);
  --border-light: rgba(255, 255, 255, 0.12);
  --text-main: #ffffff;
  --text-muted: #a0a0a0;
  --crimson: #B00020;
  --crimson-dark: #8B0000;
  --crimson-glow: rgba(176, 0, 32, 0.3);
  --shadow-crimson: 0 8px 32px rgba(176, 0, 32, 0.15);
  --green: #2dd55b;

  /* Overlay tints used for hover/resting fills, chips, progress tracks.
     These must be redefined per-theme so subtle fills stay subtle in
     BOTH themes instead of hardcoding white-on-dark everywhere. */
  --overlay-1: rgba(255, 255, 255, 0.03);
  --overlay-2: rgba(255, 255, 255, 0.05);
  --overlay-3: rgba(255, 255, 255, 0.1);
  --overlay-4: rgba(255, 255, 255, 0.22);
  --dot-private: rgba(255, 255, 255, 0.35);
  --icon-glow: rgba(255, 255, 255, 0.2);

  /* "Recessed" surfaces that were hardcoded near-black — these need to
     invert to a light tint in the light theme instead of staying dark. */
  --surface-sunken: rgba(10, 10, 12, 0.4);
  --header-glass: rgba(5, 5, 5, 0.8);
  --nav-glass: rgba(10, 10, 12, 0.9);
  --media-bg: rgba(0, 0, 0, 0.3);
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-deep) radial-gradient(circle at top right, rgba(139, 0, 0, 0.05), transparent 50%);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Use dynamic viewport height so mobile browser chrome / Telegram header
     don't push the bottom nav or content out of view. Falls back to 100vh. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

/* Scrollbars */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--overlay-3); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--crimson); }

/* ===== COMMAND PALETTE ===== */
.cmd-palette-overlay {
  position: fixed; inset: 0; z-index: 2000; /* Raised z-index so it's above mobile nav */
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: 15vh;
  opacity: 1;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), backdrop-filter 0.2s ease;
}
.cmd-palette-overlay[hidden] {
  display: none !important;
}
.cmd-palette {
  width: calc(100% - 32px); max-width: 600px;
  background: var(--bg-surface);
  border: 1px solid var(--border-red);
  border-radius: 12px;
  box-shadow: var(--shadow-crimson), 0 20px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  transform: scale(1) translateY(0);
  animation: cmdPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cmdPop {
  0% { opacity: 0; transform: scale(0.96) translateY(-10px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.cmd-search {
  display: flex; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  gap: 12px; color: var(--text-muted);
}
.cmd-search input {
  background: none; border: none; outline: none;
  color: var(--text-main); font-size: 16px; font-family: inherit;
  width: 100%;
}
.cmd-results { max-height: 300px; overflow-y: auto; padding: 8px; }
.cmd-item {
  padding: 12px 16px; border-radius: 6px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: background 0.1s;
}
.cmd-item:hover, .cmd-item.active { background: rgba(176, 0, 32, 0.1); color: var(--text-main); }
.cmd-item span { font-size: 16px; display: flex; align-items: center; }

/* ===== APP LAYOUT ===== */
.app-container { display: flex; width: 100%; height: 100%; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px; background: var(--bg-surface);
  border-right: 1px solid var(--border-light);
  display: flex; flex-direction: column;
  flex-shrink: 0; padding: 24px 16px; gap: 32px;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; letter-spacing: 0.1em;
  padding: 0 8px;
}
.sidebar-storage {
  padding: 16px; background: var(--overlay-1);
  border: 1px solid var(--border-light); border-radius: 8px;
}
.storage-text {
  display: flex; justify-content: space-between; font-size: 11px;
  font-family: 'JetBrains Mono', monospace; color: var(--text-muted); margin-bottom: 8px;
}
.storage-bar {
  height: 4px; background: var(--overlay-3); border-radius: 2px; overflow: hidden;
}
.storage-fill {
  height: 100%; background: linear-gradient(90deg, var(--crimson-dark), var(--crimson));
  box-shadow: 0 0 8px var(--crimson-glow);
}
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  color: var(--text-muted); font-size: 14px; border-radius: 6px; transition: all 0.2s;
}
.nav-item:hover { background: var(--overlay-1); color: var(--text-main); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(176, 0, 32, 0.15), transparent);
  color: var(--text-main); border-left: 2px solid var(--crimson);
}
.nav-item span:first-child { 
  font-size: 18px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  flex-shrink: 0; 
  width: 24px; 
}
.nav-item span:last-child {
  white-space: nowrap;
}

/* ===== ICONS ===== */
.svg-icon {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  vertical-align: middle;
  object-fit: contain;
  flex-shrink: 0;
}
.m-svg-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  vertical-align: middle;
  object-fit: contain;
  flex-shrink: 0;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.topbar {
  min-height: 70px; 
  height: auto;
  border-bottom: 1px solid var(--border-light);
  display: flex; 
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  /* Respect the notch / Telegram header so the search bar is never clipped */
  padding-top: max(16px, env(safe-area-inset-top));
  gap: 16px;
  background: var(--header-glass); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-row-top {
  flex: 1;
  justify-content: flex-start;
}
.search-bar {
  display: flex; align-items: center; gap: 12px; color: var(--text-muted);
  background: var(--overlay-1); border: 1px solid var(--border-light);
  padding: 8px 16px; border-radius: 6px; 
  flex: 1 1 auto; /* Grows and shrinks properly */
  min-width: 0; /* allow shrinking below content width on small screens */
  max-width: 350px; 
  transition: border 0.2s;
}
.search-bar:focus-within { border-color: var(--border-red-glow); }
.search-bar input { background: none; border: none; outline: none; color: var(--text-main); width: 100%; min-width: 0; }
.topbar-actions { 
  display: flex; 
  gap: 8px;
  justify-content: flex-start;
}
.topbar-btn { 
  font-size: 18px; 
  padding: 8px; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
}
.topbar-btn:hover { background: var(--overlay-2); }

/* Header quick theme-toggle: swap emoji by active theme, no extra icon assets needed */
.theme-toggle-btn .theme-icon-sun,
.theme-toggle-btn .theme-icon-moon {
  display: none; font-size: 18px; line-height: 1;
}
html.light .theme-toggle-btn .theme-icon-sun { display: inline-block; }
html.dark .theme-toggle-btn .theme-icon-moon { display: inline-block; }

.dashboard-scroll {
  flex: 1; overflow-y: auto; padding: 32px; display: flex; flex-direction: column; gap: 32px;
}

/* ===== WIDGETS ===== */
.widgets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.widget {
  background: var(--bg-glass); backdrop-filter: blur(20px);
  border: 1px solid var(--border-red); border-radius: 12px;
  padding: 20px; display: flex; flex-direction: column; gap: 8px;
  transition: transform 0.2s, border-color 0.2s;
}
.widget:hover { transform: translateY(-2px); border-color: var(--border-red-glow); }
.w-label { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-muted); letter-spacing: 0.05em; }
.w-val { font-size: 24px; font-weight: 500; font-family: 'Space Grotesk', sans-serif; }

/* ===== UPLOAD SECTION ===== */
.upload-section { margin-top: 16px; }
.pro-dropzone {
  background: var(--surface-sunken); border: 1px dashed var(--border-light);
  border-radius: 16px; padding: 48px; text-align: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative; overflow: hidden;
}
.pro-dropzone.dragover {
  border-color: var(--crimson); border-style: solid;
  background: rgba(176, 0, 32, 0.05); box-shadow: inset 0 0 60px rgba(176, 0, 32, 0.1);
}
.dz-icon-large { font-size: 40px; margin-bottom: 16px; display: block; transition: transform 0.3s; }
.pro-dropzone.dragover .dz-icon-large { transform: scale(1.1) translateY(-5px); }
.dz-content h3 { font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 500; margin-bottom: 8px; }
.dz-content p { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
#browse-btn { color: var(--text-main); font-weight: 500; text-decoration: underline; text-underline-offset: 4px; }
.dz-limit { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-muted); padding: 4px 8px; background: var(--overlay-2); border-radius: 4px; }

/* Queue */
.dz-queue { text-align: left; width: 100%; max-width: 500px; margin: 0 auto; }
.queue-item { margin-bottom: 16px; }
.q-header { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.q-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; margin-top: 8px; }
.q-bar-track { height: 4px; background: var(--overlay-3); border-radius: 2px; overflow: hidden; }
.q-bar-fill { height: 100%; background: var(--crimson); width: 0%; transition: width 0.2s; }

.q-cancel-btn { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 0 4px; transition: color 0.2s; }
.q-cancel-btn:hover { color: #ff4a4a; }
.q-cancelled .q-bar-fill { background: #ff4a4a !important; width: 100% !important; }
.q-cancelled .q-cancel-btn { display: none; }

/* Success */
.dz-success { animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.success-icon { font-size: 48px; display: block; margin-bottom: 16px; }
.success-file { font-size: 18px; font-weight: 500; margin: 8px 0; }
.success-id { font-family: 'JetBrains Mono', monospace; color: var(--crimson); background: rgba(176,0,32,0.1); padding: 4px 12px; border-radius: 4px; display: inline-block; margin-bottom: 24px; }
.success-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.success-actions button {
  padding: 10px 20px; border-radius: 6px; font-size: 13px; font-weight: 500;
  background: var(--overlay-2); transition: background 0.2s;
}
.success-actions button:hover { background: var(--overlay-3); }
#btn-make-public { background: linear-gradient(135deg, var(--crimson-dark), var(--crimson)); }
#btn-make-public:hover { box-shadow: 0 0 16px var(--crimson-glow); }

/* ===== FILE LIST & ACTIVITY ===== */
.content-split { display: grid; grid-template-columns: 2fr 1fr; gap: 32px; }
.content-split h3 { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 500; margin-bottom: 16px; }

.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-glass); border: 1px solid var(--border-light);
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.file-row:hover { background: var(--overlay-1); border-color: var(--border-red); transform: translateY(-1px); }
.f-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.f-icon { font-size: 20px; }
.f-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-meta { display: flex; gap: 24px; color: var(--text-muted); font-size: 12px; font-family: 'JetBrains Mono', monospace; }
.f-actions { display: flex; gap: 8px; opacity: 0; transition: opacity 0.2s; }
.file-row:hover .f-actions { opacity: 1; }
.f-btn { padding: 4px 8px; border-radius: 4px; font-size: 12px; background: var(--overlay-3); }
.f-btn:hover { background: var(--overlay-4); }

.empty-state { text-align: center; padding: 48px 24px; background: var(--bg-glass); border: 1px dashed var(--border-light); border-radius: 12px; color: var(--text-muted); }
.empty-icon { font-size: 32px; margin-bottom: 12px; display: block; }
.empty-btn { margin-top: 16px; padding: 8px 16px; background: var(--crimson); border-radius: 6px; color: white; font-size: 13px; }

/* Activity */
.activity-list { display: flex; flex-direction: column; gap: 12px; }
.act-item { display: flex; gap: 12px; font-size: 13px; color: var(--text-muted); align-items: flex-start; }
.act-icon { color: var(--text-main); }
.act-time { font-family: 'JetBrains Mono', monospace; font-size: 10px; margin-top: 4px; display: block; opacity: 0.5; }

/* ===== DETAILS PANEL ===== */
.details-panel {
  width: 320px; background: var(--bg-surface); border-left: 1px solid var(--border-light);
  display: flex; flex-direction: column; flex-shrink: 0;
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: absolute; right: 0; top: 0; bottom: 0; z-index: 100; box-shadow: -10px 0 30px rgba(0,0,0,0.5);
}
.details-panel.open { transform: translateX(0); }
/* Only dock the panel inline (pushing content) on wide screens.
   On smaller desktops/tablets it slides over the content so the file
   list never gets crushed into an unusable narrow column. */
@media (min-width: 1200px) {
  .details-panel.open { position: relative; box-shadow: none; }
}
.dp-header { padding: 24px; border-bottom: 1px solid var(--border-light); }
.dp-close { position: absolute; right: 16px; top: 16px; font-size: 18px; color: var(--text-muted); }
.dp-header h3 { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 500; margin-bottom: 4px; word-break: break-all; padding-right: 20px;}
.dp-header p { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--crimson); }

.dp-media-preview {
  width: 100%; max-height: 220px; background: var(--media-bg);
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; border-bottom: 1px solid var(--border-light);
}
.dp-media-preview img, .dp-media-preview video {
  max-width: 100%; max-height: 220px; object-fit: contain;
}
.dp-media-preview audio { width: 85%; margin: 24px 0; outline: none; }

.dp-body { padding: 24px; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.dp-row { display: flex; justify-content: space-between; font-size: 12px; }
.dp-row span:first-child { color: var(--text-muted); }
.dp-row span:last-child { font-family: 'JetBrains Mono', monospace; text-align: right; word-break: break-all; max-width: 60%; }
.dp-actions { padding: 24px; border-top: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 8px; }
.dp-btn { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--overlay-1); border-radius: 6px; font-size: 13px; transition: background 0.2s; }
.dp-btn:hover { background: var(--overlay-3); }
.dp-danger { color: #ff4a4a; }
.dp-danger:hover { background: rgba(255, 74, 74, 0.1); }

/* ===== TOASTS ===== */
.toast-container {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 3000; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.toast {
  background: var(--bg-surface); border: 1px solid var(--border-light);
  color: var(--text-main); font-size: 13px; padding: 12px 20px;
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(12px) scale(0.95);
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-error { border-color: var(--crimson); color: #ff9a9a; }

/* ===== VIEWS (Folders / Favorites / Trash / Analytics) ===== */
.view-head { margin-bottom: 8px; }
.view-head h2 { font-family: 'Space Grotesk', sans-serif; font-size: 24px; font-weight: 600; }
.view-head p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* Always show row actions in dedicated views (no hover on touch) */
.always-actions .f-actions { opacity: 1; }
.f-star { opacity: 0.4; filter: grayscale(0.6); transition: opacity 0.2s, filter 0.2s; }
.f-star.is-fav { opacity: 1; filter: none; background: rgba(245, 197, 24, 0.15); }
.f-btn-danger { color: #ff6a6a; }
.f-btn-danger:hover { background: rgba(255, 74, 74, 0.18); }

/* Folders */
.folder-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px;
}
.folder-card {
  background: var(--bg-glass); border: 1px solid var(--border-red); border-radius: 12px;
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
  cursor: pointer; transition: transform 0.2s, border-color 0.2s;
  text-align: left;
}
.folder-card:hover { transform: translateY(-2px); border-color: var(--border-red-glow); }
.folder-card-icon { font-size: 30px; }
.folder-card-name { font-family: 'Space Grotesk', sans-serif; font-size: 15px; font-weight: 500; }
.folder-card-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-muted); }

/* Drag and Drop classes */
.folder-card.drag-over {
  border-color: var(--crimson);
  background: rgba(176, 0, 32, 0.1);
  transform: scale(1.02);
}
.file-row[draggable="true"] {
  cursor: grab;
}
.file-row[draggable="true"]:active {
  cursor: grabbing;
}
.file-row.dragging {
  opacity: 0.5;
  background: var(--overlay-2);
  border-color: var(--crimson);
}

.folder-back {
  color: var(--text-muted); font-size: 13px; margin-bottom: 16px;
  padding: 6px 12px; border-radius: 6px; background: var(--overlay-1); align-self: flex-start;
}
.folder-back:hover { color: var(--text-main); background: var(--overlay-3); }
.folder-detail h3 { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 500; margin-bottom: 16px; }

/* Analytics */
.storage-hero {
  background: var(--bg-glass); border: 1px solid var(--border-red); border-radius: 16px;
  padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
.storage-hero-info { display: flex; flex-direction: column; gap: 4px; }
.storage-hero-val { font-family: 'Space Grotesk', sans-serif; font-size: 34px; font-weight: 600; }
.storage-hero-sub { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-muted); }
.storage-hero-bar { height: 8px; background: var(--overlay-3); border-radius: 4px; overflow: hidden; }
.storage-hero-fill {
  height: 100%; background: linear-gradient(90deg, var(--crimson-dark), var(--crimson));
  box-shadow: 0 0 12px var(--crimson-glow); border-radius: 4px; transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
}
.analytics-split { grid-template-columns: 1fr 1fr; align-items: start; }
.chart-card {
  background: var(--bg-glass); border: 1px solid var(--border-light); border-radius: 12px; padding: 24px;
}
.chart-card h3 { font-family: 'Space Grotesk', sans-serif; font-size: 15px; font-weight: 500; margin-bottom: 20px; }
.bar-chart { display: flex; flex-direction: column; gap: 16px; }
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-label { display: flex; justify-content: space-between; font-size: 12px; }
.bar-label span:last-child { font-family: 'JetBrains Mono', monospace; color: var(--text-muted); }
.bar-track { height: 8px; background: var(--overlay-3); border-radius: 4px; overflow: hidden; }
.bar-fill {
  height: 100%; background: linear-gradient(90deg, var(--crimson-dark), var(--crimson));
  border-radius: 4px; transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
}
.split-chart { display: flex; flex-direction: column; gap: 16px; }
.split-track { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--overlay-3); }
.split-seg-public { background: var(--crimson); }
.split-seg-private { background: var(--overlay-4); }
.split-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-row .count { margin-left: auto; font-family: 'JetBrains Mono', monospace; color: var(--text-muted); }

/* ===== SETTINGS VIEW ===== */
.settings-section { display: flex; flex-direction: column; gap: 24px; max-width: 600px; }
.settings-card {
  background: var(--bg-glass); border: 1px solid var(--border-light);
  border-radius: 12px; display: flex; flex-direction: column;
}
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px; border-bottom: 1px solid var(--border-light);
}
.settings-row:last-child { border-bottom: none; }
.settings-row h3 { font-family: 'Space Grotesk', sans-serif; font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.settings-row p { font-size: 13px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }

/* ===== AI CHAT VIEW ===== */
.aichat-view {
  flex: 1; display: flex; min-height: 0; overflow: hidden;
}
.aichat-layout { display: flex; width: 100%; height: 100%; min-height: 0; }

/* -- Conversation rail -- */
.aichat-rail {
  width: 260px; flex-shrink: 0; background: var(--bg-surface);
  border-right: 1px solid var(--border-light);
  display: flex; flex-direction: column; gap: 16px;
  padding: 20px 14px; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.aichat-new-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  background: linear-gradient(135deg, var(--crimson-dark), var(--crimson));
  color: #fff; transition: box-shadow 0.2s, transform 0.2s;
}
.aichat-new-btn:hover { box-shadow: 0 0 16px var(--crimson-glow); transform: translateY(-1px); }
.aichat-history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.aichat-history-empty { color: var(--text-muted); font-size: 12px; padding: 10px 12px; font-family: 'JetBrains Mono', monospace; }
.aichat-hist-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer;
  transition: all 0.15s; position: relative;
}
.aichat-hist-item span.aichat-hist-label {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.aichat-hist-item:hover { background: var(--overlay-1); color: var(--text-main); }
.aichat-hist-item.active {
  background: linear-gradient(90deg, rgba(176, 0, 32, 0.15), transparent);
  color: var(--text-main); border-left: 2px solid var(--crimson); padding-left: 10px;
}
.aichat-hist-del {
  opacity: 0; flex-shrink: 0; font-size: 13px; padding: 2px 4px; border-radius: 4px; color: var(--text-muted);
}
.aichat-hist-item:hover .aichat-hist-del { opacity: 1; }
.aichat-hist-del:hover { color: #ff4a4a; background: var(--overlay-2); }

/* -- Main conversation column -- */
.aichat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.aichat-topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  border-bottom: 1px solid var(--border-light); flex-shrink: 0;
}
.aichat-rail-toggle { display: none; font-size: 18px; padding: 6px; border-radius: 6px; }
.aichat-rail-toggle:hover { background: var(--overlay-2); }
.aichat-title {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: 'Space Grotesk', sans-serif; font-size: 15px; font-weight: 500;
}
.aichat-model-select {
  padding: 6px 10px; background: var(--bg-surface); color: var(--text-main);
  border: 1px solid var(--border-light); border-radius: 6px; font-size: 12px;
  font-family: 'JetBrains Mono', monospace; outline: none; cursor: pointer; flex-shrink: 0;
}
.aichat-model-select:focus { border-color: var(--crimson); }

.aichat-messages { flex: 1; overflow-y: auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 20px; }

.aichat-empty { margin: auto; text-align: center; max-width: 460px; padding: 24px; }
.aichat-empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%; font-size: 26px; margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(176,0,32,0.18), rgba(176,0,32,0.04));
  color: var(--crimson); box-shadow: var(--shadow-crimson);
}
.aichat-empty h2 { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.aichat-empty p { color: var(--text-muted); font-size: 13px; }
.aichat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.aichat-suggestion-chip {
  padding: 9px 16px; background: var(--bg-glass); border: 1px solid var(--border-light);
  border-radius: 20px; font-size: 12.5px; color: var(--text-main); transition: all 0.2s;
}
.aichat-suggestion-chip:hover { border-color: var(--border-red-glow); background: rgba(176,0,32,0.06); }

.aichat-msg { display: flex; gap: 10px; max-width: 720px; width: 100%; margin: 0 auto; align-items: flex-start; }
.aichat-msg.user { flex-direction: row-reverse; }
.aichat-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px; margin-top: 2px;
}
.aichat-msg.assistant .aichat-avatar { background: rgba(176,0,32,0.15); color: var(--crimson); }
.aichat-msg.user .aichat-avatar { background: var(--overlay-3); color: var(--text-main); }
.aichat-bubble {
  padding: 11px 15px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  max-width: 78%; white-space: pre-wrap; word-break: break-word;
}
.aichat-msg.assistant .aichat-bubble { background: var(--bg-glass); border: 1px solid var(--border-light); color: var(--text-main); border-top-left-radius: 4px; }
.aichat-msg.user .aichat-bubble { background: linear-gradient(135deg, var(--crimson-dark), var(--crimson)); color: #fff; border-top-right-radius: 4px; }
.aichat-msg.thinking .aichat-bubble { color: var(--text-muted); display: flex; gap: 4px; align-items: center; }
.aichat-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: aichatBlink 1.2s infinite ease-in-out; }
.aichat-dot:nth-child(2) { animation-delay: 0.2s; }
.aichat-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aichatBlink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.aichat-composer { padding: 12px 24px 20px; flex-shrink: 0; }

/* ── Composer action bar (Image / Audio buttons) ──────────────── */
.aichat-composer-actions {
  max-width: 720px; margin: 0 auto 8px;
  display: flex; gap: 8px;
}
.aichat-action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border-light); background: var(--bg-surface);
  color: var(--text-secondary); transition: all 0.2s; cursor: pointer;
}
.aichat-action-btn:hover {
  border-color: var(--crimson); color: var(--crimson);
  box-shadow: 0 0 8px var(--crimson-glow);
}
.aichat-action-btn i { font-size: 14px; }

.aichat-input-wrap {
  max-width: 720px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-surface); border: 1px solid var(--border-light);
  border-radius: 16px; padding: 10px 10px 10px 16px; transition: border-color 0.2s;
}
.aichat-input-wrap:focus-within { border-color: var(--border-red-glow); }
#aichat-input {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text-main); font-family: inherit; font-size: 14px; line-height: 1.5;
  max-height: 160px; padding: 4px 0;
}
#aichat-input::placeholder { color: var(--text-muted); }
.aichat-send-btn {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: var(--crimson); color: #fff; transition: all 0.2s;
}
.aichat-send-btn:hover:not(:disabled) { box-shadow: 0 0 12px var(--crimson-glow); }
.aichat-send-btn:disabled { background: var(--overlay-3); color: var(--text-muted); cursor: not-allowed; }
.aichat-disclaimer {
  text-align: center; font-size: 10.5px; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace; margin-top: 10px; max-width: 720px; margin-inline: auto;
}

/* ── Generated image in chat bubble ──────────────────────────── */
.aichat-gen-image {
  max-width: 100%; max-height: 400px; border-radius: 10px;
  display: block; object-fit: contain; margin: 4px 0;
}

/* ── Audio player in chat bubble ─────────────────────────────── */
.aichat-audio-wrap {
  display: flex; flex-direction: column; gap: 6px;
}
.aichat-audio-player {
  width: 100%; max-width: 340px; height: 54px;
  border-radius: 8px; accent-color: var(--crimson);
  overflow: hidden;
}
.aichat-audio-label {
  font-size: 11px; color: var(--text-muted); font-style: italic;
}


@media (max-width: 900px) {
  .aichat-rail-toggle { display: flex; align-items: center; justify-content: center; }
  .aichat-rail {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 60;
    transform: translateX(-100%); box-shadow: 10px 0 30px rgba(0,0,0,0.4);
  }
  .aichat-rail.open { transform: translateX(0); }
  .aichat-layout { position: relative; }
}
@media (max-width: 768px) {
  .aichat-messages { padding: 24px 16px 24px; }
  .aichat-composer { padding: 10px 16px 96px; }
  .aichat-topbar { padding: 12px 16px; }
  .m-nav-icon-font {
    font-size: 24px; opacity: 0.5; display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .m-nav-item.active .m-nav-icon-font, .m-nav-item:hover .m-nav-icon-font {
    opacity: 1; color: var(--crimson); transform: translateY(-2px) scale(1.05);
    filter: drop-shadow(0 4px 12px rgba(176, 0, 32, 0.5));
  }
}

/* ===== MOBILE ===== */
.mobile-nav { display: none; }
@media (max-width: 900px) {
  .widgets { grid-template-columns: repeat(2, 1fr); }
  .content-split { grid-template-columns: 1fr; }
  .topbar { padding-left: 20px; padding-right: 20px; }
  .dashboard-scroll { padding: 24px; gap: 24px; }
  .pro-dropzone { padding: 32px 24px; }
}
@media (max-width: 768px) {
  body { flex-direction: column; }
  .sidebar { display: none; }
  .topbar { 
    flex-direction: column; 
    padding-left: 16px; 
    padding-right: 16px; 
    padding-bottom: 12px; 
    align-items: stretch;
  }
  .topbar-row {
    width: 100%;
  }
  .topbar-row-top {
    justify-content: space-between;
  }
  .topbar-actions {
    justify-content: space-between;
  }
  .topbar .search-bar {
    max-width: none;
    flex: 1;
  }
  /* Leave room for the floating bottom nav + the device's home indicator */
  .dashboard-scroll {
    padding: 16px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    gap: 20px;
  }
  .pro-dropzone { padding: 28px 16px; border-radius: 12px; }
  .dz-content h3 { font-size: 18px; }
  
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    height: 68px; 
    background: var(--nav-glass); backdrop-filter: blur(20px); border-top: 1px solid var(--border-light);
    justify-content: space-evenly; align-items: center; padding: 0; padding-bottom: env(safe-area-inset-bottom);
    transition: transform 0.3s cubic-bezier(0.3, 1, 0.3, 1);
  }
  .mobile-nav.nav-hidden {
    transform: translateY(120px);
  }
  .m-nav-item { 
    display: flex; align-items: center; justify-content: center; flex: 1;
    height: 100%; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .m-nav-item img {
    opacity: 0.5;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .m-nav-item.active img, .m-nav-item:hover img {
    opacity: 1;
    transform: translateY(-2px) scale(1.05);
    filter: drop-shadow(0 4px 12px rgba(176, 0, 32, 0.5));
  }
  .upload-btn { display: flex; align-items: center; justify-content: center; transform: translateY(-20px); z-index: 101; }
  .upload-btn img { 
    width: 72px !important; height: 72px !important; min-width: 72px !important; min-height: 72px !important; 
    opacity: 1 !important; filter: drop-shadow(0 12px 24px var(--icon-glow)) !important; transform: none !important; 
  }
  .upload-btn:hover img, .upload-btn.active img { transform: scale(1.1) translateY(-2px) !important; filter: drop-shadow(0 12px 24px rgba(176, 0, 32, 0.8)) !important; }
  
  .details-panel { position: fixed; width: 100%; max-width: none; z-index: 150; }
}
@media (max-width: 420px) {
  /* Keep stats as a compact 2-up grid instead of a tall single column
     so the upload area stays reachable without long scrolling. */
  .widgets { gap: 12px; }
  .widget { padding: 16px; }
  .w-val { font-size: 20px; }
  .f-meta { display: none; } /* Hide metadata on very small screens to prevent row overlap */
}

/* Settings Dropdown */
.theme-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  margin-top: 10px;
  cursor: pointer;
  outline: none;
}
.theme-select:focus {
  border-color: var(--crimson);
}
.theme-select option {
  background: var(--bg-deep);
  color: var(--text-main);
}

html.light {
  --bg-deep: #f9f9fb;
  --bg-surface: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --border-red: rgba(176, 0, 32, 0.12);
  --border-red-glow: rgba(176, 0, 32, 0.25);
  --border-light: rgba(0, 0, 0, 0.08);
  --text-main: #111827;
  --text-muted: #6b7280;
  --crimson: #d32f2f;
  --crimson-dark: #b71c1c;
  --crimson-glow: rgba(211, 47, 47, 0.15);
  --shadow-crimson: 0 8px 30px rgba(0, 0, 0, 0.06);
  --green: #10b981;

  /* Light-theme equivalents of the overlay/surface tints above */
  --overlay-1: rgba(0, 0, 0, 0.035);
  --overlay-2: rgba(0, 0, 0, 0.045);
  --overlay-3: rgba(0, 0, 0, 0.07);
  --overlay-4: rgba(0, 0, 0, 0.14);
  --dot-private: rgba(0, 0, 0, 0.22);
  --icon-glow: rgba(0, 0, 0, 0.15);

  --surface-sunken: rgba(0, 0, 0, 0.035);
  --header-glass: rgba(255, 255, 255, 0.85);
  --nav-glass: rgba(255, 255, 255, 0.9);
  --media-bg: rgba(0, 0, 0, 0.045);
}

html.light body {
  background: var(--bg-deep) radial-gradient(circle at top right, rgba(176, 0, 32, 0.03), transparent 60%);
}

html.light .cmd-palette, html.light .settings-card, html.light .chart-card, html.light .details-panel, html.light .toast {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-light);
}

html.light .file-item:hover, html.light .folder-item:hover {
  background: rgba(0, 0, 0, 0.02);
  box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}

html.light .svg-icon, html.light .m-svg-icon {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.05));
}
html.light .m-nav-item.active, html.light .nav-item.active {
  background: rgba(211, 47, 47, 0.08);
  color: var(--crimson);
  border-right-color: var(--crimson);
}
html.light .nav-item.active .svg-icon {
  filter: none;
  stroke: var(--crimson);
  fill: var(--crimson);
}
html.light .file-icon, html.light .folder-card-icon, html.light .empty-icon, html.light .dz-icon-large {
  color: var(--crimson);
  font-size: 24px;
}
html.light .empty-icon { font-size: 48px; opacity: 0.5; }
html.light .dz-icon-large { font-size: 48px; opacity: 0.8; }
