:root {
  --bg: #ffffff;
  --bg-2: #f8f9fa;
  --bg-3: #f1f3f4;
  --hover: #e8f0fe;
  --selected: #c2dbff;
  --text: #202124;
  --muted: #5f6368;
  --border: #dadce0;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --danger: #d93025;
  --shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  --radius: 12px;
  --topbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1f;
    --bg-2: #2b2b2b;
    --bg-3: #333;
    --hover: #2c3a52;
    --selected: #37507a;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #3c4043;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Google Sans", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 8px; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 24px; padding: 0 20px; height: 40px;
  cursor: pointer; background: var(--bg-3); display: inline-flex; align-items: center; gap: 8px; font-weight: 500;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 6px 0; }
.icon-btn {
  background: none; border: 0; border-radius: 50%; width: 40px; height: 40px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--bg-2); }
.auth-card {
  width: 100%; max-width: 420px; background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 36px 32px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; font-weight: 500; margin: 0; }
.auth-step h2 { font-size: 24px; font-weight: 400; margin: 24px 0 6px; }
.auth-step p { margin: 0 0 20px; }
.field { display: block; margin-bottom: 8px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; height: 48px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.field input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.otp-input { letter-spacing: 10px; font-size: 24px !important; text-align: center; }
.auth-step .btn { width: 100%; justify-content: center; margin-top: 4px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; }

/* ---------- Drive layout ---------- */
.drive { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 16px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.brand.small span { font-size: 20px; color: var(--muted); }
.menu-btn { display: none; }
.search {
  flex: 1; max-width: 720px; height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 8px 0 16px;
  background: var(--bg-3); border-radius: 24px; margin: 0 auto;
}
.search:focus-within { background: var(--bg); box-shadow: var(--shadow); }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 16px; color: var(--text); outline: 0; min-width: 0; }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { width: 32px; height: 32px; }
.user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-grid; place-items: center; font-weight: 500; text-transform: uppercase;
}

.gdrive-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px;
  background: var(--hover); border-bottom: 1px solid var(--border); font-size: 14px;
}
.gdrive-banner .btn { height: 32px; padding: 0 16px; }

.body { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 256px; flex: none; padding: 12px 8px 12px 12px; display: flex; flex-direction: column; gap: 12px; }
.new-wrap { position: relative; }
.btn.new {
  background: var(--bg); border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.15); height: 56px; padding: 0 24px 0 18px; border-radius: 16px; font-size: 15px;
}
.btn.new svg { width: 24px; height: 24px; color: var(--text); }
.menu {
  position: absolute; z-index: 30; min-width: 200px; background: var(--bg); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 0;
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 16px; cursor: pointer; font-size: 14px;
}
.menu button:hover { background: var(--bg-3); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
#menu-new { top: 60px; left: 0; }
.nav-item {
  display: flex; align-items: center; gap: 14px; padding: 9px 12px 9px 20px; border-radius: 0 20px 20px 0; color: var(--text);
}
.nav-item svg { color: var(--muted); }
.nav-item.active { background: var(--hover); color: var(--primary); font-weight: 500; }
.nav-item.active svg { color: var(--primary); }
.storage { margin-top: auto; padding: 8px 20px; font-size: 13px; color: var(--muted); }
.storage-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
#storage-fill { height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.scrim { display: none; }

.content {
  flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative;
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px 0 0 0; margin-left: 4px; overflow: hidden;
}
.toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 8px 20px; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 4px; }
.selection-actions { display: flex; align-items: center; gap: 2px; padding-right: 8px; margin-right: 6px; border-right: 1px solid var(--border); }
#selection-count { color: var(--muted); margin-right: 6px; white-space: nowrap; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; font-size: 18px; min-width: 0; }
.breadcrumb a, .breadcrumb span.current { padding: 4px 8px; border-radius: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.breadcrumb a:hover { background: var(--bg-3); }
.breadcrumb .sep { color: var(--muted); font-size: 14px; }
.breadcrumb .drop-target { background: var(--hover); outline: 2px dashed var(--primary); }

.files { flex: 1; overflow: auto; padding: 4px 20px 90px; }
.files.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; align-content: start; }
.files.list { display: flex; flex-direction: column; }
.file {
  cursor: default; user-select: none; -webkit-user-select: none; border-radius: var(--radius); position: relative; -webkit-tap-highlight-color: transparent;
}
.grid .file { background: var(--bg-2); padding: 12px; display: flex; flex-direction: column; gap: 10px; border: 1px solid transparent; }
.grid .file .thumb { height: 120px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.grid .file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.grid .file .thumb svg { width: 56px; height: 56px; }
.grid .file .name { display: flex; align-items: center; gap: 8px; font-weight: 500; min-width: 0; }
.grid .file .name svg { width: 20px; height: 20px; flex: none; }
.grid .file .meta { display: none; }
.grid .file .more { position: absolute; top: 6px; right: 6px; opacity: 0; }
.grid .file:hover .more, .grid .file.selected .more { opacity: 1; }
.list .file { display: grid; grid-template-columns: 1fr 140px 90px 40px; align-items: center; gap: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); border-radius: 0; }
.list .file .thumb { display: none; }
.list .file .name { display: flex; align-items: center; gap: 14px; min-width: 0; font-weight: 500; }
.list .file .name svg { width: 22px; height: 22px; flex: none; }
.list .file .meta { color: var(--muted); font-size: 13px; white-space: nowrap; display: contents; }
.file .name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file:hover { background: var(--bg-3); }
.file.selected { background: var(--selected) !important; border-color: transparent; }
.file.drop-target { outline: 2px dashed var(--primary); background: var(--hover); }
.file.dragging { opacity: .5; }
.list-head { display: grid; grid-template-columns: 1fr 140px 90px 40px; gap: 12px; padding: 8px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); }
.files.grid .list-head { display: none; }

.empty { position: absolute; inset: 60px 0 0; display: grid; place-content: center; text-align: center; color: var(--muted); pointer-events: none; }
.empty p { margin: 6px 0; }
.empty #empty-text { font-size: 18px; color: var(--text); }
.loading { position: absolute; inset: 56px 0 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 60%, transparent); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.drop-hint {
  position: absolute; inset: 8px; border: 3px dashed var(--primary); border-radius: 16px; background: color-mix(in srgb, var(--primary) 8%, transparent);
  display: none; place-items: center; font-size: 22px; color: var(--primary); z-index: 20; pointer-events: none;
}
.content.drag-over .drop-hint { display: grid; }

/* ---------- Upload panel ---------- */
.upload-panel {
  position: fixed; right: 16px; bottom: 16px; width: min(360px, calc(100vw - 32px)); background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); z-index: 40; overflow: hidden;
}
.upload-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 16px; background: var(--bg-3); font-weight: 500; }
.upload-panel ul { list-style: none; margin: 0; padding: 4px 0; max-height: 240px; overflow: auto; }
.upload-panel li { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 13px; }
.upload-panel li span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-panel li progress { width: 90px; height: 6px; }
.upload-panel li.done { color: var(--muted); }
.upload-panel li.err { color: var(--danger); }

/* ---------- Dialogs ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 24px; background: var(--bg); color: var(--text); box-shadow: var(--shadow);
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin: 0 0 16px; font-size: 20px; font-weight: 400; }
dialog input[type=text] {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 15px; background: var(--bg); color: var(--text);
}
dialog input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.folder-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.folder-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.folder-list li:hover { background: var(--bg-3); }
.folder-list li.disabled { opacity: .45; cursor: default; }
.folder-list li svg { color: var(--muted); }
.folder-list .none { color: var(--muted); cursor: default; }
#move-breadcrumb { font-size: 14px; }

dialog.preview { width: min(1100px, calc(100vw - 24px)); height: min(90vh, 900px); padding: 0; display: flex; flex-direction: column; }
dialog.preview:not([open]) { display: none; }
.preview-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.preview-head > span { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-head > div { display: flex; align-items: center; gap: 6px; flex: none; }
.preview-body { flex: 1; min-height: 0; display: grid; place-items: center; background: var(--bg-2); overflow: auto; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; }
.preview-body pre { width: 100%; height: 100%; margin: 0; padding: 20px; overflow: auto; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.preview-body .noprev { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: #323232; color: #fff; padding: 12px 20px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; animation: fade .2s; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .topbar { gap: 8px; padding: 0 8px; }
  .menu-btn { display: inline-flex; }
  .brand.small span { display: none; }
  .search { height: 40px; }
  .user .btn { display: none; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; background: var(--bg); width: 280px; padding-top: 16px;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.open { opacity: 1; pointer-events: auto; }
  .content { margin: 0; border: 0; border-radius: 0; }
  .toolbar { padding: 6px 8px 6px 12px; }
  .breadcrumb { font-size: 16px; }
  .files { padding: 4px 12px 90px; }
  .files.grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .grid .file .thumb { height: 90px; }
  .grid .file .more { opacity: 1; }
  .list .file, .list-head { grid-template-columns: 1fr 70px 40px; }
  .list .file .meta .date, .list-head .date { display: none; }
  dialog.preview { width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; border-radius: 0; }
}
