*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f4;
  --bg-active: #e8f0fe;
  --border: #e0e0e0;
  --border-light: #eeeeee;
  --text: #202124;
  --text-secondary: #5f6368;
  --text-dim: #80868b;
  --accent: #1a73e8;
  --accent-hover: #1765cc;
  --accent-soft: rgba(26,115,232,0.08);
  --green: #34a853;
  --red: #d93025;
  --yellow: #f9ab00;
  --radius: 8px;
  --sidebar-width: 256px;
  --topbar-height: 64px;
  --shadow-sm: 0 1px 2px rgba(60,64,67,0.1);
  --shadow-md: 0 1px 3px rgba(60,64,67,0.15), 0 4px 8px rgba(60,64,67,0.1);
  --shadow-lg: 0 2px 6px rgba(60,64,67,0.15), 0 8px 24px rgba(60,64,67,0.15);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
  touch-action: pan-x pan-y;
  position: fixed;
  width: 100%;
  -webkit-font-smoothing: antialiased;
}

/* iOS: prevent long-press from triggering Safari's share/copy sheet */
.file-item, .grid-tile, .file-checkbox, .drive-item {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* iOS safe-area insets for PWA mode */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-height) + env(safe-area-inset-top)); }
  .upload-progress { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .toast-container { padding-bottom: env(safe-area-inset-bottom); }
  .ai-input-area { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

button, a, label, input { touch-action: manipulation; font-family: inherit; }

/* ---- Layout ---- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- Top Bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 4px;
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  min-width: 0;
}

.topbar-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-logo svg { display: block; }

.topbar-title {
  font-size: 22px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: 8px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.nav-btn:hover { background: var(--bg-hover); }
.nav-btn:active { background: var(--border); }
.nav-btn:disabled { opacity: 0.3; pointer-events: none; }
.nav-btn svg { display: block; }

.topbar-location {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  overflow: hidden;
}

.location-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

/* ---- Body layout ---- */
.body-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 200;
  padding: 8px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border-light);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px 6px;
}

.drive-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-radius: 0 20px 20px 0;
  cursor: pointer;
  margin-right: 12px;
  transition: background 0.12s;
}

.drive-item:hover { background: var(--bg-hover); }
.drive-item.active { background: var(--accent-soft); color: var(--accent); border-left: 3px solid var(--accent); padding-left: 13px; }
.drive-item.active .drive-icon svg { color: var(--accent); }

.drive-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.drive-info { flex: 1; min-width: 0; }

.drive-info-name {
  font-size: 14px;
  font-weight: 500;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drive-info-detail {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 1px;
}

.drive-eject {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.drive-item:hover .drive-eject { opacity: 1; }
.drive-eject:hover { background: var(--bg-hover); color: var(--text); }

.drive-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.drive-item.disconnected .drive-dot { background: var(--text-dim); }
.drive-item.disconnected .drive-eject { display: none; }

.logout-item { margin-top: auto; }
.logout-item .drive-info-name { color: var(--text-dim); font-weight: 400; }
.logout-item:hover .drive-info-name { color: var(--text); }

.drive-bar {
  height: 3px;
  background: var(--border-light);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.drive-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.sidebar-divider { height: 1px; background: var(--border-light); margin: 8px 0; }

.no-drives {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

/* ---- Path Bar ---- */
.path-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 20px;
  min-height: 36px;
}

.path-bar a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.path-bar a:hover { background: var(--bg-hover); color: var(--text); }
.path-bar a.current { color: var(--text); font-weight: 500; }
.path-bar .sep { color: var(--text-dim); font-size: 12px; }

/* ---- File Area ---- */
.file-area {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 20px;
}

/* ---- File Grid ---- */
.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 16px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.1s;
  min-height: 48px;
}

.file-item:hover { background: var(--bg-hover); }
.file-item:active { background: var(--border); }

.file-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-item-icon svg { display: block; }
.file-item-icon.folder svg { color: var(--text-secondary); }

.file-item-info {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 1px;
}

.file-item-size {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}

.file-item-date {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 80px;
  flex-shrink: 0;
}

.file-item-action {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 50%;
  font-size: 18px;
}
.file-item-action:hover { background: var(--bg-hover); color: var(--text); }

/* ---- File Toolbar ---- */
.file-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  flex-wrap: wrap;
}

.filter-chips {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.12s;
}
.filter-chip:hover { background: var(--bg-hover); }
.filter-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.sort-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.sort-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
}
.sort-btn:hover { background: var(--bg-hover); color: var(--text); }
.sort-btn.active { color: var(--accent); }
.sort-btn svg { display: inline-block; vertical-align: middle; }

/* Section header (like Google Drive "Files" label) */
.section-header {
  display: flex;
  align-items: center;
  padding: 12px 16px 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* ---- Context Menu ---- */
.context-menu {
  position: fixed;
  background: var(--bg-card);
  border-radius: 4px;
  padding: 8px 0;
  min-width: 200px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  display: none;
}
.context-menu.visible { display: block; }
.context-menu-item {
  padding: 8px 24px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: var(--red); }
.context-menu-divider { height: 1px; background: var(--border-light); margin: 4px 0; }

/* ---- Bottom Sheet ---- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 900;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.sheet-overlay.visible { display: flex; }

.sheet {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  padding-bottom: env(safe-area-inset-bottom, 12px);
  animation: sheetUp 0.2s ease-out;
}

.sheet-handle {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 8px auto 4px;
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-header {
  padding: 12px 20px 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border-light);
}

.sheet-header .file-item-icon { width: 40px; height: 40px; }

.sheet-file-info { flex: 1; min-width: 0; }
.sheet-file-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-file-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.sheet-actions { padding: 4px 0; }

.sheet-action {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sheet-action:active { background: var(--bg-hover); }
.sheet-action.danger { color: var(--red); }
.sheet-action-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.sheet-action.danger .sheet-action-icon { color: var(--red); }

/* ---- Upload ---- */
.upload-overlay {
  position: fixed; inset: 0;
  background: rgba(26,115,232,0.08);
  border: 3px dashed var(--accent);
  display: none; align-items: center; justify-content: center;
  z-index: 500;
  margin: 4px;
  border-radius: 12px;
}
.upload-overlay.visible { display: flex; }
.upload-box { text-align: center; padding: 40px; }
.upload-box h2 { color: var(--accent); margin-bottom: 4px; font-size: 16px; font-weight: 500; }
.upload-box p { color: var(--text-dim); font-size: 13px; }

/* ---- Progress ---- */
.upload-progress {
  position: fixed; bottom: 16px; right: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 280px; max-width: calc(100vw - 32px);
  z-index: 600; display: none;
  box-shadow: var(--shadow-lg);
}
.upload-progress.visible { display: block; }
.progress-text { font-size: 13px; margin-bottom: 8px; color: var(--text); }
.progress-bar { height: 4px; background: var(--bg-hover); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.2s; width: 0%; }

/* ---- Toast ---- */
.toast-container {
  position: fixed; bottom: 16px; left: 16px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: calc(100vw - 32px);
}

.toast {
  background: #323232;
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 14px;
  color: #fff;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease-out;
  max-width: 400px;
}

@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---- Empty State ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  gap: 16px;
  padding: 20px;
}
.empty-icon { opacity: 0.4; color: var(--text-dim); }
.empty-text { font-size: 14px; color: var(--text-secondary); }

/* ---- Welcome Page ---- */
.welcome-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 24px;
  gap: 32px;
  overflow-y: auto;
}
.welcome-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.welcome-title {
  font-size: 28px;
  font-weight: 400;
  color: var(--text);
  margin-top: 8px;
}
.welcome-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 320px;
  line-height: 1.5;
}
.welcome-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 720px;
}
.welcome-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  width: 220px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.welcome-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.welcome-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.welcome-card-text { min-width: 0; }
.welcome-card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}
.welcome-card-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}
.welcome-status {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

@media (max-width: 768px) {
  .welcome-cards { flex-direction: column; align-items: stretch; }
  .welcome-card { width: auto; }
  .welcome-title { font-size: 22px; }
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center;
  z-index: 800; padding: 20px;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 24px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.modal h3 { color: var(--text); margin-bottom: 16px; font-size: 16px; font-weight: 500; }
.modal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 16px;
}
.modal-chip {
  height: 28px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
.modal-chip:hover { background: var(--bg-hover); color: var(--text); }
.modal-chip:active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.modal input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 20px;
}
.modal input:focus { border-color: var(--accent); border-width: 2px; padding: 9px 11px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.btn {
  padding: 8px 24px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.25px;
}
.btn:hover { background: var(--accent-soft); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

/* ---- Preview ---- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1100;
  display: none;
  flex-direction: column;
}
.preview-overlay.visible { display: flex; }

.preview-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.5);
}

.preview-close, .preview-download {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.preview-close:hover, .preview-download:hover { background: rgba(255,255,255,0.1); }

.preview-filename {
  flex: 1;
  font-size: 14px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
}

.preview-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.preview-body video, .preview-body audio {
  max-width: 100%;
  max-height: 100%;
  outline: none;
}
.preview-body audio { width: min(420px, 90vw); }
.audio-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  color: #fff;
}
.audio-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 28px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  min-width: min(360px, 90vw);
}
.audio-cover svg { width: 96px; height: 96px; }
.audio-name {
  font-size: 14px;
  color: #fff;
  text-align: center;
  word-break: break-word;
  max-width: 320px;
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 4px;
  background: #fff;
}

.preview-actions {
  display: flex;
  gap: 8px;
  margin-right: 8px;
}
.preview-action {
  height: 32px;
  padding: 0 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.preview-action:hover { background: rgba(255,255,255,0.12); }
.preview-action.primary {
  background: var(--accent);
  border-color: var(--accent);
}
.preview-action.primary:hover { background: var(--accent-hover); }
.preview-action:disabled { opacity: 0.4; cursor: not-allowed; }

.text-loading {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
}
.text-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border-radius: 14px;
  font-size: 12px;
  z-index: 10;
}
.preview-body { position: relative; }
.text-view, .text-edit {
  width: min(880px, 96%);
  max-height: calc(100% - 16px);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 24px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
  border: none;
  box-shadow: var(--shadow-md);
}
.text-view {
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.text-edit {
  resize: none;
  height: calc(100% - 16px);
  tab-size: 2;
  -webkit-text-size-adjust: 100%;
}
.text-edit:focus { box-shadow: var(--shadow-lg); }

.preview-body pre.text-view {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

.preview-body pre {
  width: 100%;
  max-height: 100%;
  overflow: auto;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 20px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 2;
}

.preview-unsupported {
  color: rgba(255,255,255,0.6);
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
}

.preview-unsupported .preview-unsupported-icon {
  margin-bottom: 16px;
  opacity: 0.4;
}

/* ======= MOBILE ======= */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.visible { display: block; }

  .topbar { height: 56px; padding: 0 4px; }
  .topbar-brand { display: none; }
  .menu-toggle { display: flex !important; }

  .path-bar { display: none; }

  .file-area { padding: 0 4px 20px; }

  .file-item { padding: 8px 12px; gap: 12px; }
  .file-item-size { display: none; }
  .file-item-date { display: none; }

  .file-toolbar { padding: 6px 8px; }
  .sort-btns { display: none; }
  .filter-chip { padding: 5px 12px; font-size: 11px; }

  .drive-eject { opacity: 1; }

  .context-menu { display: none !important; }
}

/* ======= DESKTOP ======= */
@media (min-width: 769px) {
  .menu-toggle { display: none !important; }
}

/* ======= AI PANEL ======= */
.ai-toggle {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
  margin-left: 4px;
}
.ai-toggle:hover { background: var(--accent); color: #fff; }

.ai-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 400px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-lg);
}
.ai-panel.open { transform: translateX(0); }

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.ai-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.ai-welcome h3 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  margin: 12px 0 6px;
}
.ai-welcome p {
  font-size: 13px;
  line-height: 1.5;
}

.ai-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.ai {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}

.ai-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.ai-action-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 12px;
}
.ai-action-card .ai-action-info {
  flex: 1;
  min-width: 0;
}
.ai-action-card .ai-action-type {
  font-weight: 500;
  color: var(--text);
  text-transform: capitalize;
}
.ai-action-card .ai-action-detail {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-action-status {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.ai-action-status.running { color: var(--accent); }
.ai-action-status.done { color: var(--green); }
.ai-action-status.failed { color: var(--red); }

.ai-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.ai-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: aiBounce 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aiBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.ai-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.ai-input-area input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.ai-input-area input:focus { border-color: var(--accent); }
.ai-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ai-send:hover { background: var(--accent-hover); }

@media (max-width: 768px) {
  .ai-panel { width: 100%; }
}

/* ============================================================
   New: Search, Selection, Thumbnails, Grid, Upload progress
   ============================================================ */

/* ---- Topbar search ---- */
.topbar-search {
  flex: 1 1 320px;
  min-width: 0;
  max-width: 480px;
  margin: 0 12px;
  position: relative;
  display: flex;
  align-items: center;
}
.topbar-search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
}
.topbar-search input {
  width: 100%;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--bg);
  padding: 0 38px 0 38px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: background 0.12s, border-color 0.12s;
  font-family: inherit;
}
.topbar-search input:hover { background: var(--bg-hover); }
.topbar-search input:focus { background: var(--bg-card); border-color: var(--border); box-shadow: var(--shadow-sm); }
.topbar-search input::-webkit-search-decoration,
.topbar-search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.topbar-search-clear {
  position: absolute;
  right: 6px;
  width: 26px; height: 26px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.topbar-search input:not(:placeholder-shown) ~ .topbar-search-clear { display: flex; }
.topbar-search-clear:hover { background: var(--bg-hover); color: var(--text); }

@media (max-width: 768px) {
  .topbar-search {
    order: 99;
    flex: 1 1 100%;
    margin: 0 0 8px 0;
    padding: 0 8px;
  }
  .topbar { flex-wrap: wrap; height: auto; padding-bottom: 8px; row-gap: 4px; }
  .topbar-location { order: 50; }
}

/* ---- File checkbox ---- */
.file-checkbox {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
  transition: opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s;
  opacity: 0;
}
.file-item:hover .file-checkbox,
.file-item.selected .file-checkbox,
.grid-tile:hover .file-checkbox,
.grid-tile.selected .file-checkbox { opacity: 1; }
.file-checkbox.checked,
.file-item.selected .file-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.file-checkbox:hover { border-color: var(--accent); }
.file-item.selected { background: var(--accent-soft); }
.file-item.selected:hover { background: rgba(26,115,232,0.14); }
.file-checkbox.grid {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(255,255,255,0.92);
  z-index: 2;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

@media (hover: none) {
  .file-checkbox { opacity: 1; }
}

/* ---- Selection bar ---- */
.selection-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 8;
}
.selection-bar.visible { display: flex; }
.sb-count {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  margin-right: 8px;
}
.sb-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
}
.sb-btn:hover { background: var(--bg-hover); }
.sb-btn.danger { color: var(--red); border-color: rgba(217,48,37,0.3); }
.sb-btn.danger:hover { background: rgba(217,48,37,0.08); }
.sb-btn.ghost {
  background: transparent;
  border: none;
  width: 32px;
  padding: 0;
  justify-content: center;
}
.sb-btn.ghost:hover { background: rgba(0,0,0,0.05); }

/* ---- Thumbnails ---- */
.file-item-icon.thumb {
  background: var(--bg-hover);
  overflow: hidden;
  border-radius: 4px;
  position: relative;
}
.file-item-icon.thumb .thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}
.file-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: relative;
  z-index: 1;
}
.grid-tile-thumb { position: relative; }
.grid-tile-thumb .thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}
.grid-tile-thumb .thumb-fallback svg { width: 56px; height: 56px; }
.grid-tile-thumb img { position: relative; z-index: 1; }

/* ---- Grid view ---- */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px 12px;
  list-style: none;
}
.grid-tile {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.grid-tile:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
.grid-tile.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.grid-tile-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.grid-tile-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.grid-tile-icon {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.grid-tile-icon svg { width: 56px; height: 56px; }
.grid-tile-icon.folder svg { color: var(--text-secondary); }
.grid-tile-name {
  font-size: 12px;
  color: var(--text);
  padding: 8px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--border-light);
}

@media (max-width: 480px) {
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 8px; }
  .grid-tile-icon svg { width: 40px; height: 40px; }
  .grid-tile-name { font-size: 11px; padding: 6px 8px; }
}

/* ---- Upload progress: cancel button ---- */
.upload-progress { padding-bottom: 14px; }
.progress-cancel {
  display: none;
  margin-top: 10px;
  padding: 6px 14px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.progress-cancel:hover { background: var(--bg-hover); color: var(--text); }

/* ---- AI cards ---- */
.ai-action-status {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}
.ai-action-card.queued .ai-action-status,
.ai-action-card.pending .ai-action-status { color: var(--text-dim); }
.ai-action-card.skipped { opacity: 0.6; }
.ai-action-card.skipped .ai-action-status { color: var(--text-dim); }

/* ---- File toolbar ---- */
.file-toolbar {
  background: var(--bg);
  margin-bottom: 4px;
}

