:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efede8; --ink: #1c1c1e; --muted: #6b6a67; --line: #e4e1da;
  --accent: #0d7a6f; --accent-ink: #ffffff; --accent-soft: #e0f1ee; --danger: #c4382f; --danger-soft: #fbe8e6;
  --folder: #e0a12a; --shadow: 0 12px 32px rgba(30, 28, 24, .14); --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121314; --surface: #1b1c1e; --surface-2: #26272a; --ink: #ececea; --muted: #9a9995; --line: #2e2f32;
    --accent: #3cc4b2; --accent-ink: #06201d; --accent-soft: #15332f; --danger: #ff7468; --danger-soft: #3a1d1a;
    --folder: #e8b146; --shadow: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
body.noscroll { overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.i { display: inline-grid; place-items: center; flex: none; }
.i svg { width: 18px; height: 18px; display: block; }
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }
.err:empty { display: none; }
.fatal { padding: 32px; text-align: center; color: var(--danger); }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; white-space: nowrap;
  transition: background .15s, filter .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.wide { width: 100%; height: 44px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 9px; border: 0; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-spacer { width: 36px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 6px 0 0; font-size: 22px; }
.auth-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--accent); font-size: 17px; }
.brand .i svg { width: 22px; height: 22px; }
label { display: grid; gap: 6px; font-size: 14px; }
label > span { color: var(--muted); }
input[type=text], input[type=password], input[type=search], input:not([type]), select {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.check { display: flex; align-items: flex-start; gap: 10px; color: var(--ink); cursor: pointer; }
label.check > span { color: var(--ink); }
label.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); }

/* Шапка */
.top {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.top .usage { margin-left: auto; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 16px 20px 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 2px; flex: 1 1 260px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.crumb { border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; font-size: 18px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.crumb:hover { background: var(--surface-2); color: var(--ink); }
.crumb.cur, .crumbs > .crumb:only-child { color: var(--ink); }
.sep { color: var(--line); font-size: 18px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search { position: relative; display: block; }
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { height: 38px; width: 200px; padding-left: 36px; background: var(--surface); }

.selbar {
  position: sticky; top: 57px; z-index: 15; margin: 0 20px 8px; padding: 6px 8px 6px 16px; border-radius: 12px;
  background: var(--accent-soft); display: flex; align-items: center; gap: 12px; font-weight: 600;
}
.sel-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.sel-actions .btn { height: 34px; }

/* Список файлов */
.list { padding: 0 20px 120px; }
.row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 110px 170px 40px; align-items: center; gap: 8px;
  padding: 0 8px; min-height: 52px; border-bottom: 1px solid var(--line);
}
.row:not(.head):hover { background: var(--surface); }
.row.sel, .row.sel:hover { background: var(--accent-soft); }
.row.head { min-height: 40px; position: sticky; top: 57px; background: var(--bg); z-index: 5; }
.th { border: 0; background: transparent; text-align: left; color: var(--muted); font-size: 13px; padding: 4px 0; }
.th.on { color: var(--ink); font-weight: 600; }
.cb { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.name { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; text-align: left; padding: 8px 0; min-width: 0; }
.nm { display: grid; min-width: 0; }
.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .nm .sub { display: none; }
.c-size, .c-date { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.more { opacity: .55; }
.row:hover .more, .tile:hover .more, .more:focus-visible { opacity: 1; }
.nothing { padding: 40px; text-align: center; color: var(--muted); }

/* Иконки файлов */
.folder { color: var(--folder); display: inline-grid; flex: none; }
.folder svg { width: 30px; height: 30px; }
.folder.big svg { width: 64px; height: 64px; }
.ficon {
  --c: #8a8a8a; position: relative; flex: none; width: 26px; height: 32px; border-radius: 4px; background: var(--c);
  clip-path: polygon(0 0, 68% 0, 100% 26%, 100% 100%, 0 100%); display: flex; align-items: flex-end; justify-content: center; margin: 0 2px;
}
.ficon::after { content: ""; position: absolute; top: 0; right: 0; width: 32%; height: 26%; background: rgba(255, 255, 255, .35); border-bottom-left-radius: 3px; }
.ficon > span { color: #fff; font-size: 7.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; padding-bottom: 4px; line-height: 1; }
.ficon.big { width: 60px; height: 74px; border-radius: 8px; }
.ficon.big > span { font-size: 13px; padding-bottom: 10px; }
.k-image { --c: #3a86c8; } .k-video { --c: #8456cf; } .k-audio { --c: #d0567f; } .k-pdf { --c: #d24a3c; }
.k-text { --c: #6b7785; } .k-archive { --c: #b07a2a; } .k-doc { --c: #2f6fd1; } .k-sheet { --c: #2e8b57; } .k-slides { --c: #d9772b; }

/* Плитка */
.list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding-top: 8px; }
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumb { display: grid; place-items: center; width: 100%; aspect-ratio: 1 / 1; border: 0; padding: 0; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tname { display: grid; padding: 8px 10px 10px; min-width: 0; }
.tile .cb { position: absolute; top: 8px; left: 8px; opacity: 0; }
.tile:hover .cb, .tile .cb:checked, .tile.sel .cb { opacity: 1; }
.tile .more { position: absolute; top: 4px; right: 4px; background: var(--surface); opacity: 0; }

.empty { text-align: center; padding: 70px 20px; color: var(--ink); }
.empty .i svg { width: 44px; height: 44px; color: var(--accent); }
.empty p { margin: 8px 0 0; }
.empty p:first-of-type { font-size: 18px; font-weight: 600; margin-top: 14px; }

/* Меню */
.menu {
  position: fixed; z-index: 100; min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item .i { color: var(--muted); }
.menu-item.danger, .menu-item.danger .i { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* Диалоги */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(15, 15, 14, .45); display: grid; place-items: center; padding: 16px; }
.modal-box {
  width: 100%; max-width: 440px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
.modal-box.wide { max-width: 620px; }
.m-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 4px 22px; }
.m-head h2 { margin: 0; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-body { padding: 10px 22px 18px; overflow-y: auto; display: grid; gap: 14px; }
.m-body p { margin: 0; }
.m-form { display: grid; gap: 14px; }
.m-form p { margin: 0; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.copyrow { display: flex; gap: 8px; }
.copyrow input { flex: 1; min-width: 0; font-size: 13.5px; }
.tbl { display: grid; }
.trow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.trow.dim { opacity: .55; }
.tmain { flex: 1; min-width: 0; display: grid; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }

/* Загрузки */
.uploads {
  position: fixed; right: 20px; bottom: 20px; z-index: 60; width: 380px; max-height: 50vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.up-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.up-list { overflow-y: auto; }
.up-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px 9px 16px; border-bottom: 1px solid var(--line); }
.up-row:last-child { border-bottom: 0; }
.up-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.up-main .t { font-size: 13.5px; }
.track { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.st { font-size: 12px; color: var(--muted); }
.up-row.ok .st { color: var(--accent); }
.up-row.fail .st { color: var(--danger); }
.up-row.fail .bar { background: var(--danger); }

.drop {
  position: fixed; inset: 10px; z-index: 70; border: 3px dashed var(--accent); border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); display: grid; place-items: center; pointer-events: none;
}
.drop > div { display: flex; flex-direction: column; align-items: center; gap: 12px; font-size: 20px; font-weight: 600; color: var(--accent); }
.drop .i svg { width: 48px; height: 48px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 120; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

/* Просмотрщик */
.viewer { position: fixed; inset: 0; z-index: 90; background: #0e0e0f; color: #eee; display: flex; flex-direction: column; }
.v-top { display: flex; align-items: center; gap: 6px; padding: 10px 12px 10px 20px; }
.v-title { flex: 1; min-width: 0; }
#vName { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-meta { font-size: 12.5px; color: #aaa; }
.viewer .icon-btn { color: #ddd; }
.viewer .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.v-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 64px 20px; }
.v-body img, .v-body video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.v-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.v-text {
  width: 100%; max-width: 980px; height: 100%; margin: 0; overflow: auto; padding: 20px; border-radius: 8px;
  background: #1c1d1f; color: #e6e6e6; font: 13px/1.55 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.v-card { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; color: #ccc; }
.v-card audio { width: min(420px, 80vw); }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .1); color: #fff; display: grid; place-items: center;
}
.v-nav:hover { background: rgba(255, 255, 255, .2); }
.v-nav.prev { left: 10px; } .v-nav.next { right: 10px; }
.v-nav .i svg { width: 24px; height: 24px; }

/* Телефоны */
@media (max-width: 760px) {
  .top { padding: 8px 12px; gap: 10px; }
  .top .usage { font-size: 12px; text-align: right; }
  .top .lbl { display: none; }
  .toolbar { padding: 10px 12px 6px; }
  .crumbs { flex-basis: 100%; }
  .actions { width: 100%; }
  .actions .lbl { display: none; }
  .actions .btn { padding: 0 11px; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .selbar { margin: 0 12px 8px; top: 53px; }
  .sel-actions .lbl { display: none; }
  .list { padding: 0 8px 120px; }
  .row { grid-template-columns: 28px minmax(0, 1fr) 36px; padding: 0 6px; }
  .row .c-size, .row .c-date, .row.head { display: none; }
  .row .nm .sub { display: block; }
  .more { opacity: 1; }
  .list.grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; padding: 8px 12px 120px; }
  .tile .more, .tile .cb { opacity: 1; }
  .uploads { right: 8px; left: 8px; bottom: 8px; width: auto; }
  .v-body { padding: 0 0 12px; }
  .v-nav { display: none; }
  .modal { align-items: end; padding: 0; }
  .modal-box, .modal-box.wide { max-width: none; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
@media (hover: none) { .more, .tile .more, .tile .cb { opacity: 1; } }

/* Лимит места */
.top .usage { display: flex; align-items: center; gap: 10px; }
.qbar { width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; flex: none; }
.qbar > span { display: block; height: 100%; background: var(--accent); }
.qbar.full > span { background: var(--danger); }
input[type=number] { height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); width: 100%; }
@media (max-width: 760px) { .qbar { width: 50px; } }
