/* Панель «Общий диск». Светлая и тёмная тема — по системной настройке,
   принудительно: ?theme=dark или ?theme=light. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-hover: #eef1f6;
  --bg-active: #e3e9f6;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1b1f27;
  --text-soft: #6b7280;
  --text-faint: #9aa1ad;
  --accent: #3b6ef5;
  --accent-soft: #e8eefe;
  --danger: #d9534f;
  --ok: #2e9e5b;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(16, 24, 40, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --bg-soft: #1c1f26;
    --bg-hover: #232730;
    --bg-active: #2b3242;
    --border: #2a2e37;
    --border-strong: #3a404c;
    --text: #e8eaef;
    --text-soft: #9aa1ad;
    --text-faint: #6b7280;
    --accent: #6b93ff;
    --accent-soft: #1f2a44;
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="light"] {
  --bg: #ffffff; --bg-soft: #f6f7f9; --bg-hover: #eef1f6; --bg-active: #e3e9f6;
  --border: #e3e6eb; --border-strong: #cfd4dc; --text: #1b1f27; --text-soft: #6b7280;
  --text-faint: #9aa1ad; --accent: #3b6ef5; --accent-soft: #e8eefe;
}

:root[data-theme="dark"] {
  --bg: #16181d; --bg-soft: #1c1f26; --bg-hover: #232730; --bg-active: #2b3242;
  --border: #2a2e37; --border-strong: #3a404c; --text: #e8eaef; --text-soft: #9aa1ad;
  --text-faint: #6b7280; --accent: #6b93ff; --accent-soft: #1f2a44;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display:flex/grid у наших блоков. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 12px;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
button:hover { background: var(--bg-hover); }
button:active { background: var(--bg-active); }
button:disabled { opacity: .5; cursor: default; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }

button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--bg-hover); }

input[type="text"], input[type="search"], input[type="password"], select {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ── каркас ─────────────────────────────────────────────────────── */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex: none;
  min-height: 52px;
}

.topbar h1 {
  font-size: 15px;
  font-weight: 650;
  margin: 0;
  white-space: nowrap;
  letter-spacing: -.01em;
}

.spacer { flex: 1; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
  flex: 0 1 auto;
}
.crumbs button {
  border: 0; background: transparent; padding: 3px 6px; border-radius: 6px;
  color: var(--text-soft); white-space: nowrap; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis;
}
.crumbs button:hover { background: var(--bg-hover); color: var(--text); }
.crumbs .sep { color: var(--text-faint); }
.crumbs .cur { color: var(--text); font-weight: 600; padding: 3px 6px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cols {
  display: flex;
  gap: 10px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex: none;
}
.cols .size, .row .size { width: 88px; text-align: right; flex: none; }
.cols .date, .row .date { width: 132px; flex: none; }
.cols .size, .cols .date { cursor: pointer; user-select: none; }
.cols .size:hover, .cols .date:hover { color: var(--text); }

.main { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.list { flex: 1; overflow-y: auto; }

/* ── строки ─────────────────────────────────────────────────────── */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.row:hover { background: var(--bg-hover); }
.row.dir { cursor: pointer; }
.row .name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; }
.row .acts { display: flex; gap: 2px; opacity: 0; flex: none; }
.row:hover .acts { opacity: 1; }
.row .acts button { padding: 3px 7px; font-size: 13px; border-radius: 6px; }

.icon {
  width: 20px; height: 20px;
  flex: none;
  display: grid; place-items: center;
  font-size: 15px; line-height: 1;
}

.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── состояния ──────────────────────────────────────────────────── */

.empty, .loading, .error {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--text-soft);
  padding: 48px 20px;
}
.error { color: var(--danger); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── тосты ──────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 120;
  max-width: min(520px, 92vw);
}
.toast {
  background: #23262e;
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: pop .18s ease-out;
  word-break: break-word;
}
.toast.err { background: var(--danger); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ── модалки ────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 18, 24, .48);
  display: grid; place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px;
  width: min(420px, 94vw);
}
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal .field { margin-bottom: 10px; }

.preview { width: min(860px, 96vw); max-height: 88vh; display: flex; flex-direction: column; }
.preview pre {
  overflow: auto;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 12px;
  font-size: 12.5px;
  margin: 0;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.preview img { max-width: 100%; max-height: 64vh; object-fit: contain; display: block; margin: 0 auto; }
.preview iframe { width: 100%; height: 64vh; border: 0; border-radius: 8px; background: var(--bg-soft); }

/* ── вход ───────────────────────────────────────────────────────── */

.login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
  z-index: 150;
  padding: 20px;
}
.login-card {
  width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 12px;
}
.login-card .logo {
  font-size: 30px; line-height: 1;
}
.login-card h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.login-card p { margin: 0; color: var(--text-soft); font-size: 13px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; }
.login-card button { padding: 9px 12px; }

/* ── загрузка ───────────────────────────────────────────────────── */

.drop-hint {
  position: absolute; inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid; place-content: center;
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
  z-index: 50;
}

.uploads {
  position: fixed;
  right: 16px; bottom: 16px;
  width: min(320px, 88vw);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  z-index: 110;
  display: none;
}
.uploads.on { display: block; }
.uploads .item { margin: 6px 0; font-size: 12.5px; }
.uploads .bar {
  height: 4px; border-radius: 3px; background: var(--border);
  overflow: hidden; margin-top: 4px;
}
.uploads .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .12s; }

/* ── узкие экраны ───────────────────────────────────────────────── */

@media (max-width: 760px) {
  .topbar { gap: 6px; padding: 8px 10px; flex-wrap: nowrap; }
  .topbar h1, #q, #btn-refresh, .user-name { display: none; }
  .topbar button { padding: 6px 9px; }
  .cols { display: none; }
  .row { padding: 11px 12px; }
  .row .size, .row .date { display: none; }
  .row .acts { opacity: 1; }
  .crumbs { flex: 1; }
  .toasts { left: 10px; right: 10px; transform: none; }
  .toast { text-align: center; }
  .modal { width: 94vw; padding: 14px; }
}
