:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --border: #e3e0d9;
  --text: #1c1b19;
  --muted: #74716a;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefc;
  --danger: #d13d34;
  --danger-soft: #fbe9e7;
  --folder: #e0a526;
  --tg: #2aabee;
  --shadow: 0 1px 2px rgba(20, 18, 14, .06), 0 8px 24px rgba(20, 18, 14, .08);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #262624;
    --border: #2f2f2c;
    --text: #edece8;
    --muted: #96938b;
    --accent: #5b8ff0;
    --accent-ink: #0d1424;
    --accent-soft: #1d2a42;
    --danger: #ef6b62;
    --danger-soft: #3a1f1d;
    --folder: #e8b443;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
svg { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .row-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 14px; }
.btn-tg { background: var(--tg); color: #fff; height: 48px; padding: 0 22px; font-size: 16px; border-radius: 12px; width: 100%; }
.btn-tg:hover { filter: brightness(1.05); }
.btn-tg[aria-disabled="true"] { opacity: .6; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- boot / spinner ---------- */
.boot, .list-loading { display: grid; place-items: center; min-height: 40vh; }
.boot { min-height: 100vh; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 36px 28px 28px; box-shadow: var(--shadow);
}
.logo-mark {
  width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.logo-mark svg { width: 36px; height: 36px; }
.login h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.login-card > p { margin: 4px 0 26px; }
.login-status { min-height: 1.45em; margin: 14px 0 0; font-size: 14px; }

/* ---------- app shell ---------- */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand svg { color: var(--accent); width: 26px; height: 26px; }
.user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 14px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 17px; font-weight: 650; min-width: 0; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 4px 6px; border-radius: 7px; }
.crumbs a:hover { background: var(--surface-2); color: var(--text); }
.crumbs .current { padding: 4px 6px; color: var(--text); overflow-wrap: anywhere; }
.crumbs .sep { color: var(--border); }

.actions { display: flex; align-items: center; gap: 8px; }
.search {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; }
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; width: 160px; }

/* ---------- listing ---------- */
.listing { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-head, .row {
  display: grid; grid-template-columns: minmax(0, 1fr) 100px 150px 84px; align-items: center; gap: 12px;
}
.list-head { padding: 10px 8px 10px 16px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .04em; }
.list { list-style: none; margin: 0; padding: 0; }
.row { padding: 0 8px 0 16px; min-height: 52px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row-main { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px 0; color: var(--text); text-decoration: none; border-radius: 6px; cursor: default; }
a.row-main { cursor: pointer; }
.row-text { min-width: 0; display: grid; }
.row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: none; font-size: 12.5px; color: var(--muted); }
.col-size, .col-date { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.ficon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.ficon svg { width: 19px; height: 19px; }
.ficon.folder { background: transparent; color: var(--folder); }
.ficon.folder svg { width: 30px; height: 30px; }
.ficon.image { color: #3a9a5b; } .ficon.video { color: #b04cc9; } .ficon.audio { color: #e0663a; }
.ficon.archive { color: #8a7a52; } .ficon.doc { color: var(--accent); }

.empty { text-align: center; padding: 56px 16px 64px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; opacity: .7; }
.empty p { margin: 6px 0 0; }
.empty strong { color: var(--text); }

/* ---------- dropzone ---------- */
.dropzone {
  position: fixed; inset: 0; z-index: 50; padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px);
  display: grid;
}
.dropzone-inner {
  border: 2.5px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
  display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--accent); font-size: 17px; text-align: center; pointer-events: none;
}
.dropzone-inner svg { width: 52px; height: 52px; }
.dropzone-inner p { margin: 0; color: var(--text); }

/* ---------- uploads panel ---------- */
.uploads {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40; width: 360px; max-height: 50vh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.uploads header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; }
.up { padding: 8px 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.up-status { font-size: 12.5px; color: var(--muted); grid-column: 1; font-variant-numeric: tabular-nums; }
.up-status.err { color: var(--danger); }
.up .icon-btn { grid-row: 1 / span 3; grid-column: 2; width: 30px; height: 30px; }
.bar { grid-column: 1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up.done .bar i { background: #3a9a5b; }
.up.failed .bar i { background: var(--danger); }

/* ---------- dialogs & toasts ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: min(400px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 10, 8, .35); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog p { margin: 0 0 4px; overflow-wrap: anywhere; }
.dialog input {
  width: 100%; height: 42px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; outline: 0;
}
.dialog input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .list-head { display: none; }
  .row { grid-template-columns: minmax(0, 1fr) auto; padding: 0 4px 0 12px; }
  .col-size, .col-date { display: none; }
  .row-meta { display: block; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .actions { width: 100%; }
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; }
  .actions .btn span { display: none; }
  .actions .btn { width: 42px; padding: 0; }
  .uploads { left: 12px; right: 12px; width: auto; }
}
