:root {
  --primary: #6C63FF;
  --primary-light: #8B83FF;
  --primary-dark: #4A42D4;
  --grad-a: #6C63FF;
  --grad-b: #4A90D9;
  --sidebar-bg: #0D1117;
  --sidebar-hover: #161B22;
  --sidebar-active: #1F2937;
  --sidebar-text: #8B949E;
  --sidebar-text-active: #FFFFFF;
  --background: #F6F8FA;
  --surface: #FFFFFF;
  --surface-variant: #F0F2F5;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --border: #E5E7EB;
  --border-light: #F0F0F0;
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --info: #3B82F6;
  --sidebar-width: 260px;
  --radius: 10px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 8px;
}

.logo-badge {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-badge svg { width: 22px; height: 22px; }

.sidebar-title { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-title .title-main { color: #FFF; font-size: 16px; font-weight: 700; }
.sidebar-title .title-sub { color: var(--primary); font-size: 12px; font-weight: 500; }

.new-button {
  margin: 8px 20px 16px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  border: none; border-radius: var(--radius);
  color: #FFF; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  transition: filter 0.2s;
}
.new-button:hover { filter: brightness(1.08); }
.new-button svg { width: 20px; height: 20px; }

.nav { display: flex; flex-direction: column; padding: 0 12px; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border: none; background: transparent; border-radius: 8px;
  color: var(--sidebar-text); font-size: 14px; font-weight: 400;
  cursor: pointer; text-align: left; width: 100%;
  transition: background 0.2s;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-active); font-weight: 500; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-spacer { flex: 1; }

.storage-indicator { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.storage-label { font-size: 11px; font-weight: 600; letter-spacing: 0.5px; color: var(--sidebar-text); }
.storage-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.storage-row svg { width: 16px; height: 16px; }
.storage-bar { height: 4px; background: var(--sidebar-hover); border-radius: 2px; overflow: hidden; }
.storage-bar > div { height: 100%; background: var(--primary); border-radius: 2px; transition: width 0.4s; }

.sidebar-divider { height: 1px; background: var(--sidebar-hover); }

.nav-bottom { padding-bottom: 12px; }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
#page-title { font-size: 20px; font-weight: 600; color: var(--text-primary); }

.topbar-right { display: flex; align-items: center; }

.conn-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  background: var(--surface-variant); color: var(--text-secondary);
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-tertiary); }
.conn-connected .conn-dot { background: var(--success); }
.conn-connected { color: var(--success); background: rgba(16,185,129,0.12); }
.conn-connecting .conn-dot { background: var(--warning); animation: pulse 1s infinite; }
.conn-connecting { color: var(--warning); background: rgba(245,158,11,0.12); }
.conn-disconnected { color: var(--error); background: rgba(239,68,68,0.12); }
.conn-disconnected .conn-dot { background: var(--error); }

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

#content { flex: 1; overflow-y: auto; }

.mobile-only { display: none; }

.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; cursor: pointer; color: var(--text-secondary);
  font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-variant); }

/* ---------- Toolbar (My Drive) ---------- */
.toolbar {
  padding: 16px 24px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.toolbar-title-row { display: flex; align-items: center; gap: 8px; }
.toolbar-title-row h2 { font-size: 20px; font-weight: 600; color: var(--text-primary); }

.crumbs { display: flex; align-items: center; font-size: 13px; color: var(--text-tertiary); flex-wrap: wrap; }
.crumb-btn {
  background: none; border: none; color: var(--info); cursor: pointer; font-size: 13px; padding: 2px;
}
.crumb-btn:hover { text-decoration: underline; }
.crumb-sep { margin: 0 4px; }

.toolbar-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.search-box {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-variant); border-radius: var(--radius);
  padding: 0 16px;
}
.search-box svg { width: 20px; height: 20px; color: var(--text-tertiary); flex-shrink: 0; }
.search-box input {
  border: none; background: transparent; outline: none;
  padding: 12px 0; font-size: 14px; flex: 1; color: var(--text-primary); width: 100%;
}
.search-box .clear-btn {
  background: none; border: none; cursor: pointer; color: var(--text-tertiary); font-size: 16px; padding: 4px;
}
.search-box .clear-btn:hover { color: var(--text-primary); }

.action-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-secondary); font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background 0.2s;
}
.action-chip:hover { background: var(--surface-variant); }
.action-chip svg { width: 18px; height: 18px; }
.action-chip.primary { background: var(--primary); border-color: var(--primary); color: #FFF; }
.action-chip.primary:hover { filter: brightness(1.08); }
.action-chip.danger:hover { border-color: var(--error); color: var(--error); }
.action-chip:disabled { opacity: 0.5; cursor: not-allowed; }

.view-toggle {
  display: flex; background: var(--surface-variant); border-radius: 8px; padding: 2px;
}
.view-toggle button {
  border: none; background: transparent; border-radius: 6px;
  padding: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.view-toggle button svg { width: 18px; height: 18px; color: var(--text-tertiary); }
.view-toggle button.active { background: var(--surface); box-shadow: var(--shadow); }
.view-toggle button.active svg { color: var(--primary); }

/* ---------- List view ---------- */
.list-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border-light);
}
.list-header span { font-size: 12px; font-weight: 600; color: var(--text-tertiary); }
.col-name { flex: 3; }
.col-owner { flex: 1; }
.col-modified { flex: 2; }
.col-size { flex: 1; }
.col-menu { width: 40px; flex-shrink: 0; }

.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px;
  border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
  margin: 0 8px;
}
.file-row:hover { background: var(--surface-variant); }

.file-icon {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.file-icon svg { width: 20px; height: 20px; }

.fname-cell { display: flex; align-items: center; min-width: 0; }
.fname-cell .fname { font-size: 14px; font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star-icon { width: 16px; height: 16px; margin-left: 6px; color: var(--warning); flex-shrink: 0; }

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

.menu-btn {
  background: none; border: none; cursor: pointer; color: var(--text-tertiary);
  padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
.menu-btn:hover { background: var(--surface-variant); color: var(--text-primary); }
.menu-btn svg { width: 18px; height: 18px; }

/* ---------- Grid view ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 24px;
}
.grid-item {
  background: var(--surface);
  border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  padding: 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: box-shadow 0.2s, border-color 0.2s;
  text-align: center; position: relative;
}
.grid-item:hover { box-shadow: var(--shadow); border-color: var(--border); }
.grid-item .file-icon { width: 48px; height: 48px; }
.grid-item .file-icon svg { width: 24px; height: 24px; }
.grid-item .gname { font-size: 13px; font-weight: 500; color: var(--text-primary); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-item .gsub { font-size: 11px; color: var(--text-tertiary); }
.grid-item .gmenu {
  position: absolute; top: 6px; right: 6px;
  background: none; border: none; cursor: pointer; color: var(--text-tertiary);
  padding: 4px; border-radius: 6px; display: none;
}
.grid-item:hover .gmenu { display: flex; }
.grid-item .gmenu:hover { background: var(--surface-variant); }
.grid-item .gmenu svg { width: 16px; height: 16px; }
.grid-item .gstar { position: absolute; top: 6px; left: 6px; }

/* ---------- Empty / loading / error ---------- */
.state-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; gap: 12px; text-align: center;
}
.state-wrap svg { width: 64px; height: 64px; color: rgba(156,163,175,0.5); }
.state-wrap h3 { font-size: 16px; font-weight: 500; color: var(--text-secondary); }
.state-wrap p { font-size: 13px; color: var(--text-tertiary); }

.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 24px 0; padding: 12px 16px;
  background: rgba(239,68,68,0.08); border: 1px solid var(--error);
  color: var(--error); border-radius: var(--radius);
  font-size: 13px;
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; }
.error-banner pre { margin-top: 4px; font-size: 12px; white-space: pre-wrap; overflow: auto; max-height: 100px; }
.error-banner .dismiss { margin-left: auto; background: none; border: none; color: var(--error); cursor: pointer; font-size: 16px; padding: 0 4px; }

.notice-banner {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 24px 0; padding: 12px 16px;
  background: rgba(59,130,246,0.08); border: 1px solid var(--info);
  color: var(--info); border-radius: var(--radius); font-size: 13px;
}
.notice-banner svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; padding: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow);
}
.card h3 { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 12px; }

.storage-card { display: flex; align-items: center; gap: 20px; }
.gauge-wrap { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.gauge-wrap svg { transform: rotate(-90deg); }
.gauge-bg { stroke: var(--surface-variant); }
.gauge-fill { stroke: url(#gaugeGrad); transition: stroke-dashoffset 0.6s ease; }
.gauge-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.gauge-center .pct { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.gauge-center .lbl { font-size: 11px; color: var(--text-tertiary); }

.storage-rows { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.storage-row-item { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; }
.storage-row-item .lbl { font-size: 13px; color: var(--text-secondary); }
.storage-row-item .bar { height: 6px; background: var(--surface-variant); border-radius: 3px; overflow: hidden; }
.storage-row-item .bar > div { height: 100%; border-radius: 3px; }
.storage-row-item .val { font-size: 12px; color: var(--text-tertiary); text-align: right; min-width: 56px; }

.quick-access { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 0 24px 24px; }
.quick-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; cursor: pointer; transition: box-shadow 0.2s;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
}
.quick-card:hover { box-shadow: var(--shadow); }
.quick-card .qicon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.quick-card .qicon svg { width: 24px; height: 24px; }
.quick-card .qname { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.quick-card .qcount { font-size: 12px; color: var(--text-tertiary); }

.panel-title { font-size: 16px; font-weight: 600; color: var(--text-primary); padding: 24px 24px 12px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; padding: 24px; }
.setting-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border-light); }
.setting-row:last-child { border-bottom: none; }
.setting-row .sicon { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-variant); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.setting-row .sicon svg { width: 20px; height: 20px; color: var(--primary); }
.setting-row .sbody { flex: 1; display: flex; flex-direction: column; }
.setting-row .sname { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.setting-row .sdesc { font-size: 12px; color: var(--text-tertiary); }
.setting-row .sval { font-size: 13px; color: var(--text-secondary); }

.input-group { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.input-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.3px; }
.input-group input, .input-group select {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px; font-size: 14px; color: var(--text-primary); outline: none; width: 100%;
}
.input-group input:focus { border-color: var(--primary); }
.input-group .hint { font-size: 12px; color: var(--text-tertiary); }

.btn-group { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* Debug panel */
.debug-log {
  background: #0D1117; color: #C9D1D9;
  border-radius: 8px; padding: 12px;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
  height: 260px; overflow-y: auto; line-height: 1.6;
}
.debug-log .log-line { white-space: pre-wrap; word-break: break-word; }
.debug-log .log-method { color: #79C0FF; font-weight: 600; }
.debug-log .log-status-ok { color: #7EE787; }
.debug-log .log-status-err { color: #FF7B72; }
.debug-log .log-dim { color: #8B949E; }
.debug-log .log-noise { display: none; }
.debug-log .log-info { color: #79C0FF; }
.debug-log .log-download { color: #D2A8FF; }
.debug-log .log-warn { color: #F59E0B; }
.debug-log .log-err { color: #FF7B72; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(13,17,23,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--surface); border-radius: 16px;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  animation: slideUp 0.2s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 8px; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-tertiary); padding: 4px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 8px 24px 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 24px 20px; }

.btn {
  border: none; border-radius: var(--radius); cursor: pointer;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  transition: filter 0.15s;
}
.btn-primary { background: var(--primary); color: #FFF; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--error); color: #FFF; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-outline { background: var(--surface); border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--surface-variant); }
.btn.text-btn { background: none; color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Upload item */
.upload-item { padding: 10px 0; border-bottom: 1px solid var(--border-light); }
.upload-item:last-child { border-bottom: none; }
.upload-item .urow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.upload-item .uname { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .ustatus { font-size: 12px; flex-shrink: 0; }
.upbar { height: 6px; background: var(--upload-bg, #E5E7EB); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.upbar > div { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.2s; }
.up-done { color: var(--success); }
.up-error { color: var(--error); }
.up-active { color: var(--info); }
.up-detail { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info);
  border-radius: 8px; padding: 12px 16px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 380px; animation: slideUp 0.2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }
.toast .t-title { font-weight: 600; color: var(--text-primary); }
.toast .t-body { color: var(--text-secondary); margin-top: 2px; word-break: break-word; }

/* ---------- Context menu ---------- */
.ctx-menu {
  position: fixed; z-index: 150; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 6px; animation: fadeIn 0.1s ease;
}
.ctx-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text-primary);
}
.ctx-item:hover { background: var(--surface-variant); }
.ctx-item svg { width: 18px; height: 18px; color: var(--text-secondary); }
.ctx-item.danger { color: var(--error); }
.ctx-item.danger svg { color: var(--error); }
.ctx-item.disabled { opacity: 0.4; cursor: not-allowed; }
.ctx-item.disabled:hover { background: transparent; }
.ctx-divider { height: 1px; background: var(--border-light); margin: 6px 0; }

/* Folder picker (move) */
.folder-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.folder-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13px;
}
.folder-row:hover { background: var(--surface-variant); }
.folder-row svg { width: 20px; height: 20px; color: var(--folder, #6C63FF); }
.folder-row.root { font-weight: 500; color: var(--text-primary); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #sidebar { position: fixed; z-index: 80; height: 100vh; transform: translateX(-100%); transition: transform 0.25s; box-shadow: 0 0 30px rgba(0,0,0,0.3); }
  #sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .col-owner { display: none; }
  .col-modified { display: none; }
}

@media print { .debug-log { height: auto; } }