:root {
  --bg: #f7f7f8; --panel: #ffffff; --line: #e4e4e7; --text: #18181b; --muted: #71717a;
  --accent: #2563eb; --accent-text: #fff; --hover: #f1f1f3; --sel: #e8efff; --danger: #dc2626;
  --folder: #e0a526; --shadow: 0 8px 30px rgba(0,0,0,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --panel: #18181b; --line: #2a2a2e; --text: #ececee; --muted: #9a9aa3;
    --accent: #4f8bff; --hover: #222226; --sel: #1d2a45; --danger: #f05252; --folder: #e8b13d;
    --shadow: 0 8px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.i { width: 18px; height: 18px; flex: none; vertical-align: middle; }
.i.big { width: 56px; height: 56px; color: var(--muted); }
.logo { color: var(--accent); width: 22px; height: 22px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--hover); }

/* login */
body.login { display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 36px; max-width: 380px; text-align: center; box-shadow: var(--shadow); margin: 16px; }
.login-card h1 { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 8px; font-size: 22px; }
.login-card p { color: var(--muted); }
.error { color: var(--danger) !important; }

/* shell */
.top { height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 190px; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--bg); color: var(--muted); }
.search input { flex: 1; border: 0; background: transparent; color: var(--text); font: inherit; padding: 7px 0; outline: none; min-width: 0; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.user img { width: 28px; height: 28px; border-radius: 50%; }
.user form { margin: 0; }
.menu-btn { display: none; }
.layout { display: flex; height: calc(100% - 52px); }
aside { width: 250px; flex: none; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 8px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
nav a, .conn-name { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--text); text-decoration: none; cursor: pointer; overflow: hidden; }
nav a span, .conn-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav a:hover, .conn-name:hover { background: var(--hover); }
nav a.active { background: var(--sel); color: var(--accent); font-weight: 500; }
.conn-name { font-weight: 600; }
.conn-name .icon-btn { margin-left: auto; width: 26px; height: 26px; opacity: .6; }
.conn-buckets a { padding-left: 24px; }
.conn-err { padding: 4px 8px 4px 24px; color: var(--danger); font-size: 12px; }
#star-list a .i { color: var(--folder); }
main { flex: 1; overflow: auto; min-width: 0; display: flex; flex-direction: column; }

.empty { margin: auto; text-align: center; max-width: 420px; padding: 24px; }
.empty p { color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 18px; flex-wrap: wrap; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 15px; flex: 1; min-width: 200px; }
.crumbs a { color: var(--text); text-decoration: none; padding: 3px 6px; border-radius: 5px; cursor: pointer; }
.crumbs a:hover { background: var(--hover); }
.crumbs a:last-child { font-weight: 600; }
.crumbs .sep { color: var(--muted); }
.crumbs > .muted { padding: 3px 6px; }
.tools { display: flex; gap: 6px; align-items: center; }
.selbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0 18px 8px; padding: 6px 10px; background: var(--sel); border-radius: 8px; }
.selbar span { font-weight: 500; margin-right: 6px; }

.listing { padding: 0 18px; }
table.files { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.files th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.files td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.files tr:last-child td { border-bottom: 0; }
.files tbody tr { cursor: default; }
.files tbody tr:hover { background: var(--hover); }
.files tbody tr.sel { background: var(--sel); }
.files .c-check { width: 34px; }
.files .c-size, .files .c-date { color: var(--muted); width: 1%; }
.files .c-size { text-align: right; }
.files .c-name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
.files .c-act { width: 1%; }
.name { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; max-width: 100%; }
.name span { overflow: hidden; text-overflow: ellipsis; }
.name:hover span { text-decoration: underline; }
.name .i { color: var(--muted); }
.name .i.folder, .card .i.folder { color: var(--folder); }
.path { color: var(--muted); font-size: 12px; margin-left: 4px; }
.row-act { visibility: hidden; display: inline-flex; }
tr:hover .row-act, tr.sel .row-act { visibility: visible; }
.row-act .icon-btn { width: 28px; height: 28px; }
.starred { color: var(--folder) !important; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.card:hover { border-color: var(--muted); }
.card.sel { outline: 2px solid var(--accent); }
.card .thumb { height: 110px; display: grid; place-items: center; background: var(--hover); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb .i { width: 44px; height: 44px; color: var(--muted); }
.card .label { padding: 7px 9px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .label small { display: block; color: var(--muted); font-size: 11px; }
.card input { position: absolute; top: 8px; left: 8px; }

.list-foot { display: flex; align-items: center; gap: 12px; padding: 12px 18px 24px; color: var(--muted); font-size: 13px; }
.placeholder { padding: 48px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: 10px; }

/* drop + uploads + toasts */
.drop { position: fixed; inset: 0; background: rgba(37,99,235,.12); border: 3px dashed var(--accent); display: grid; place-items: center; z-index: 50; pointer-events: none; }
.drop div { background: var(--panel); padding: 14px 22px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; }
.uploads { position: fixed; right: 16px; bottom: 16px; width: 340px; max-height: 50vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 40; }
.uploads-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
#uploads-list { overflow-y: auto; }
.up { padding: 7px 12px; font-size: 12px; border-bottom: 1px solid var(--line); }
.up .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up .bar { height: 4px; background: var(--hover); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.up .bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up.done .bar div { background: #16a34a; }
.up.err { color: var(--danger); }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dlg.small { width: min(420px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h3 { margin: 0 0 4px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.dlg label small { font-size: 12px; }
.dlg input, .dlg select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
.dlg input:focus, .dlg select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg .actions { display: flex; gap: 8px; margin-top: 6px; }
.msg { margin: 0; min-height: 1.2em; font-size: 13px; }
.msg.ok { color: #16a34a; } .msg.bad { color: var(--danger); }
.cors-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.cors-row span { flex-basis: 100%; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }

/* preview */
.preview { position: fixed; inset: 0; background: #0e0e10; z-index: 60; display: flex; flex-direction: column; color: #eee; }
.preview-head { display: flex; align-items: center; gap: 4px; padding: 8px 12px; }
.preview-head .icon-btn { color: #eee; }
.preview-head .icon-btn:hover { background: rgba(255,255,255,.1); }
#pv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { flex: 1; display: grid; place-items: center; overflow: auto; padding: 0 64px 24px; min-height: 0; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.preview-body pre { align-self: stretch; justify-self: stretch; margin: 0; padding: 16px; background: #1b1b1f; border-radius: 8px; overflow: auto;
  font: 13px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; color: #e4e4e7; }
.preview-body .none { text-align: center; color: #aaa; }
.pv-nav { position: absolute; top: 50%; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; display: grid; place-items: center; }
.pv-nav:hover { background: rgba(255,255,255,.2); }
.pv-nav.prev { left: 10px; } .pv-nav.next { right: 10px; }

@media (max-width: 760px) {
  .brand span, .user-email, .search kbd, .hide-sm { display: none; }
  .brand { min-width: 0; }
  .menu-btn { display: inline-flex; }
  aside { position: fixed; top: 52px; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  aside.open { transform: none; }
  .toolbar, .listing, .list-foot { padding-left: 16px; padding-right: 16px; }
  .selbar { margin: 0 16px 8px; }
  .files .c-date { display: none; }
  .tools .btn { padding: 6px 8px; }
  #btn-upload-dir { display: none; }
  .preview-body { padding: 0 8px 16px; }
  .pv-nav { display: none; }
  .uploads { left: 16px; right: 16px; width: auto; }
}
