:root {
  color-scheme: light;
  --page: #f7f8fc;
  --surface: #fff;
  --surface-soft: #fafbfe;
  --border: #e8ebf3;
  --border-strong: #dce1ec;
  --text: #20263a;
  --muted: #7c8498;
  --muted-dark: #59637b;
  --accent: #4f6fe8;
  --accent-hover: #405dcc;
  --accent-soft: #edf1ff;
  --danger: #c83e4d;
  --danger-soft: #fff0f1;
  --radius: 14px;
  --shadow: 0 5px 24px rgba(37, 49, 91, .045);
}

* { box-sizing: border-box; }
html { min-width: 0; min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid rgba(79, 111, 232, .3);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Main file browser */
.topbar {
  height: 78px;
  padding: 0 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 13px;
  background: linear-gradient(145deg, #6483f1, #4866dc);
  box-shadow: 0 5px 12px rgba(79, 111, 232, .22);
}
.brand-mark svg { width: 27px; height: 27px; }
.brand-copy { display: grid; gap: 3px; }
.brand-copy strong { font-size: 15px; letter-spacing: -.02em; }
.brand-copy span { color: var(--muted); font-size: 12px; }
.account { display: flex; align-items: center; gap: 10px; }
.account-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #4764d5;
  background: #e9edff;
  font-size: 14px;
  font-weight: 700;
}
.account-name { color: var(--muted-dark); font-size: 13px; font-weight: 600; }
.account .btn { margin-left: 8px; }
.workspace {
  width: min(1440px, 100%);
  min-height: calc(100vh - 78px);
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  margin: 0 auto;
}
.sidebar {
  min-height: calc(100vh - 78px);
  padding: 34px 18px 24px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.sidebar-label, .eyebrow {
  margin: 0;
  color: #939aae;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .13em;
}
.sidebar-label { padding: 0 12px; }
.nav-item {
  height: 44px;
  margin-top: 13px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 9px;
  color: var(--muted-dark);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.nav-item.active { color: var(--accent); background: var(--accent-soft); }
.nav-item svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar-card {
  margin-top: 42px;
  padding: 17px 15px 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.sidebar-card-icon {
  width: 30px;
  height: 30px;
  margin-bottom: 13px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 19px;
  font-weight: 700;
}
.sidebar-card strong { font-size: 12px; }
.sidebar-card p {
  margin: 7px 0 13px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.sidebar-upload {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--muted-dark);
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
}
.sidebar-upload:hover { color: var(--accent); border-color: #bfcaff; }
.sidebar-footnote {
  margin: auto 8px 0;
  padding-top: 28px;
  color: #9a9fb0;
  font-size: 11px;
  line-height: 1.55;
}
.main-content { min-width: 0; padding: 44px 48px 64px; }
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 30px;
}
.eyebrow { margin-bottom: 9px; }
.page-heading h1 {
  margin: 0;
  font-size: clamp(25px, 3vw, 32px);
  letter-spacing: -.045em;
  line-height: 1.2;
}
.page-subtitle { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.primary-actions { display: flex; flex-shrink: 0; gap: 9px; }
.btn {
  min-height: 39px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { color: #fff; background: var(--accent); box-shadow: 0 3px 8px rgba(79, 111, 232, .18); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { border-color: var(--border-strong); color: var(--muted-dark); background: var(--surface); }
.btn-secondary:hover, .btn-quiet:hover { border-color: #c8d0e0; background: var(--surface-soft); }
.btn-quiet {
  min-height: 34px;
  padding: 0 11px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}
.btn-quiet:hover { color: var(--text); }
.primary-actions .btn > span:first-child { font-size: 17px; line-height: 1; }
.upload-glyph { font-size: 17px; line-height: 1; }
.file-browser {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.browser-toolbar {
  min-height: 69px;
  padding: 13px 21px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
.breadcrumb .crumb {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breadcrumb button.crumb {
  padding: 4px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.breadcrumb button.crumb:hover { color: var(--accent); }
.breadcrumb .crumb.active { color: var(--text); font-weight: 650; }
.breadcrumb .sep { color: #b4bac9; font-size: 12px; }
.search-box {
  width: 226px;
  height: 35px;
  flex-shrink: 0;
  padding: 0 9px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}
.search-box:focus-within { border-color: #aebcff; background: #fff; }
.search-box svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: #9299aa;
  stroke-width: 1.7;
  stroke-linecap: round;
}
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 11px; }
.search-box input::placeholder { color: #9a9fb0; }
.search-box kbd {
  min-width: 17px;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: #9a9fb0;
  background: #fff;
  text-align: center;
  font-family: inherit;
  font-size: 10px;
}
.folder-summary {
  min-height: 49px;
  padding: 0 21px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.path { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 12px; font-weight: 650; }
#currentPathLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#countLabel { color: #9a9fb0; font-size: 11px; font-weight: 500; white-space: nowrap; }
.list-hint { color: #a0a5b3; font-size: 10px; }
.file-list-shell { position: relative; min-height: 244px; }
.file-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.file-table th {
  height: 38px;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: #9299aa;
  background: #fbfcfe;
  text-align: left;
  font-size: 10px;
  font-weight: 650;
}
.file-table th:first-child, .file-table td:first-child { padding-left: 21px; }
.file-table th:nth-child(1) { width: auto; }
.file-table th:nth-child(2) { width: 128px; }
.file-table th:nth-child(3) { width: 175px; }
.file-table th.actions-col, .file-table td.actions-col { width: 57px; padding-right: 15px; text-align: center; }
.file-table td {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid #f0f2f7;
  color: var(--muted-dark);
  font-size: 12px;
}
.file-table tbody tr:last-child td { border-bottom: 0; }
.file-table tbody tr:hover { background: #fbfcff; }
.name-cell { min-width: 0; display: flex; align-items: center; gap: 11px; }
.name-cell .icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #f4f6fb;
  font-size: 17px;
}
.name-cell .fname {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name-cell .fname.clickable { cursor: pointer; }
.name-cell .fname.clickable:hover { color: var(--accent); }
.size-cell, .date-cell { color: var(--muted); white-space: nowrap; }
.row-menu {
  width: 29px;
  height: 29px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #9097a8;
  background: transparent;
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
}
.row-menu:hover { border-color: var(--border); color: var(--text); background: #fff; }
.empty-state { padding: 32px 18px 40px; text-align: center; }
.empty-illustration { width: 96px; height: 80px; margin: 0 auto 15px; }
.empty-illustration svg { display: block; width: 100%; height: 100%; }
.empty-state h2 { margin: 0; font-size: 14px; letter-spacing: -.015em; }
.empty-state p { margin: 7px 0 16px; color: var(--muted); font-size: 11px; }
.empty-upload { min-height: 34px; font-size: 11px; }
.drop-hint {
  position: absolute;
  z-index: 4;
  inset: 8px;
  display: grid;
  place-items: center;
  border: 2px dashed #7f98f4;
  border-radius: 11px;
  color: #3e5fd0;
  background: rgba(239, 243, 255, .96);
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}
.progress-track { height: 3px; overflow: hidden; background: #edf0f7; }
.progress-fill { width: 0; height: 100%; background: var(--accent); transition: width .1s linear; }
.status-message { margin: 0; padding: 11px 20px; color: var(--muted-dark); font-size: 12px; }
.status-message.error { color: var(--danger); background: var(--danger-soft); }
.context-menu {
  position: fixed;
  z-index: 100;
  min-width: 174px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(34, 43, 73, .16);
}
.context-menu button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted-dark);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}
.context-menu button:hover { background: var(--surface-soft); }
.context-menu button.danger { color: var(--danger); }
.context-menu button.danger:hover { background: var(--danger-soft); }
.modal-overlay {
  position: fixed;
  z-index: 200;
  inset: 0;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(27, 34, 55, .36);
  backdrop-filter: blur(2px);
}
.modal {
  width: min(400px, 100%);
  padding: 23px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(24, 31, 52, .2);
}
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal input {
  width: 100%;
  height: 41px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}
.modal input:focus { border-color: #9bafff; outline: 3px solid rgba(79, 111, 232, .12); }
.modal-error { margin: 8px 0 0; color: var(--danger); font-size: 12px; }
.modal-actions { margin-top: 19px; display: flex; justify-content: flex-end; gap: 8px; }

/* Login and registration */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
  background:
    radial-gradient(ellipse at 14% 17%, rgba(122, 147, 245, .12), transparent 31%),
    radial-gradient(ellipse at 87% 87%, rgba(161, 178, 255, .13), transparent 29%),
    var(--page);
}
.auth-card {
  width: min(408px, 100%);
  padding: 34px 36px 29px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(37, 49, 91, .09);
}
.auth-brand-mark { width: 48px; height: 48px; margin: 0 auto 18px; }
.auth-brand-mark svg { width: 30px; height: 30px; }
.auth-card h1 { margin: 0; text-align: center; font-size: 22px; letter-spacing: -.035em; }
.auth-subtitle { margin: 7px 0 25px; color: var(--muted); text-align: center; font-size: 13px; }
.auth-form label { display: block; margin: 15px 0 6px; color: var(--muted-dark); font-size: 11px; font-weight: 650; }
.auth-form input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  font-size: 13px;
}
.auth-form input:focus { border-color: #9bafff; outline: 3px solid rgba(79, 111, 232, .12); }
.auth-submit { width: 100%; min-height: 43px; margin-top: 22px; font-size: 13px; }
.flash-messages { display: grid; gap: 8px; }
.flash-message { padding: 10px 12px; border-radius: 8px; font-size: 12px; }
.flash-message.error { color: var(--danger); background: var(--danger-soft); }
.flash-message.ok { color: #26764b; background: #ebf8f0; }
.auth-switch { margin: 21px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.auth-switch a { color: var(--accent); font-weight: 650; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

@media (max-width: 1050px) {
  .main-content { padding: 38px 30px 54px; }
  .workspace { grid-template-columns: 215px minmax(0, 1fr); }
  .file-table th:nth-child(3) { width: 145px; }
}
@media (max-width: 760px) {
  .topbar { height: 68px; padding: 0 20px; }
  .workspace { min-height: calc(100vh - 68px); display: block; }
  .sidebar { min-height: auto; padding: 13px 20px 0; border-right: 0; }
  .sidebar-label, .sidebar-card, .sidebar-footnote { display: none; }
  .nav-item { width: fit-content; height: 36px; margin: 0; padding: 0 10px; }
  .main-content { padding: 28px 20px 42px; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 20px; }
  .primary-actions { width: 100%; }
  .primary-actions .btn { flex: 1; }
  .browser-toolbar { align-items: stretch; flex-direction: column; padding: 12px 16px; }
  .search-box { width: 100%; }
}
@media (max-width: 520px) {
  .topbar { padding: 0 15px; }
  .brand { gap: 9px; }
  .brand-mark { width: 37px; height: 37px; }
  .brand-copy strong { font-size: 13px; }
  .brand-copy span { font-size: 10px; }
  .account { gap: 7px; }
  .account-avatar { width: 30px; height: 30px; }
  .account-name { display: none; }
  .account .btn { margin-left: 0; }
  .main-content { padding: 26px 13px 35px; }
  .page-heading h1 { font-size: 26px; }
  .page-subtitle { max-width: 300px; line-height: 1.5; }
  .btn { padding: 0 10px; font-size: 11px; }
  .file-browser { border-radius: 11px; }
  .folder-summary { padding: 0 14px; }
  .list-hint { display: none; }
  .file-table th { padding: 0 8px; font-size: 9px; }
  .file-table th:first-child, .file-table td:first-child { padding-left: 12px; }
  .file-table th:nth-child(2) { width: 68px; }
  .file-table th:nth-child(3) { width: 57px; }
  .file-table th.actions-col, .file-table td.actions-col { width: 39px; padding-right: 7px; }
  .file-table td { height: 53px; padding: 0 8px; font-size: 10px; }
  .date-cell { overflow: hidden; text-overflow: ellipsis; }
  .name-cell { gap: 7px; }
  .name-cell .icon { width: 27px; height: 27px; font-size: 14px; }
  .name-cell .fname { font-size: 10px; }
  .row-menu { width: 25px; }
  .auth-card { padding: 30px 24px 25px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

/* Экран входа: скрываем приложение, пока нет сессии */
body.gate .topbar,
body.gate .workspace,
body.gate .context-menu,
body.gate .modal-overlay,
body.gate #statusMessage { display: none !important; }
#authGate.auth-page { position: fixed; inset: 0; z-index: 60; overflow: auto; }
#authGate[hidden] { display: none; }
#authGate .flash-message { margin-bottom: 10px; }
