:root {
  --bg: #f3f4f6;
  --chrome: #f9fafb;
  --surface: #ffffff;
  --text: #1b1f27;
  --muted: #646b78;
  --faint: #9aa1ad;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-soft: #e8f2fc;
  --select: #cce4f7;
  --select-line: #99c9ef;
  --hover: #eef3f9;
  --danger: #c42b1c;
  --danger-soft: #fdecea;
  --ok: #107c10;
  --ok-soft: #e6f4e6;
  --folder: #f0b429;
  --radius: 6px;
  --shadow: 0 8px 28px rgba(16, 24, 40, 0.16), 0 2px 6px rgba(16, 24, 40, 0.08);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 .75rem; }
b, strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.lead { margin: 0 0 1rem; max-width: 70ch; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.i { width: 18px; height: 18px; flex: none; vertical-align: middle; }

/* ---------- controls ---------- */
input[type=text], input[type=search], input[type=password], input[type=email], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-bottom-color: #a9b0bb;
  border-radius: var(--radius); padding: 6px 10px; min-width: 0; min-height: 32px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
button:focus-visible, a:focus-visible, .item:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; padding: 6px 14px; min-height: 32px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--chrome); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 13px; }
.btn .i { width: 16px; height: 16px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius); border: 0; background: transparent;
  color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); text-decoration: none; }
.icon-btn[aria-pressed=true] { background: var(--select); }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* ---------- messages ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.msg { padding: 9px 12px; border-radius: var(--radius); margin-bottom: 6px; background: var(--accent-soft); border: 1px solid #c7ddf3; }
.msg.error { background: var(--danger-soft); border-color: #f4c2bc; color: var(--danger); }
.msg.success { background: var(--ok-soft); border-color: #bfe0bf; color: var(--ok); }

/* ---------- login (non-explorer pages) ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 20px; }
.login-card {
  max-width: 380px; margin: 12vh auto 0; background: var(--surface); padding: 32px;
  border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow);
}
.login-card h1 { text-align: center; }
.login-card label { display: block; margin-bottom: 14px; color: var(--muted); }
.login-card input { display: block; width: 100%; margin-top: 4px; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* ---------- explorer window ---------- */
.explorer-body { overflow: hidden; }
.app {
  height: 100vh; height: 100dvh;
  display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--surface);
}

.titlebar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  background: var(--chrome); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); }
.brand-icon { width: 22px; height: 22px; color: var(--accent); }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip form { margin: 0; }
.who { color: var(--muted); }
.tree-toggle { display: none; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 13px;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11.5px; }

.commandbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 10px; min-height: 48px;
  background: var(--chrome); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none;
}
.cmd {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font: inherit; color: var(--text); background: transparent; border: 1px solid transparent;
  border-radius: var(--radius); padding: 6px 10px; cursor: pointer;
}
.cmd:hover:not(:disabled) { background: var(--hover); text-decoration: none; }
.cmd:disabled { color: var(--faint); cursor: default; }
.cmd.primary { background: var(--accent); color: #fff; }
.cmd.primary:hover { background: var(--accent-hover); }
.cmd.danger:not(:disabled) { color: var(--danger); }
.commandbar:not(:has(*)) { display: none; }
.cmd-sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 6px; flex: none; }
.cmd-spacer { flex: 1; }
.cmd-note { color: var(--muted); padding: 0 6px; }
.cmd-form { display: flex; gap: 6px; margin: 0 6px 0 0; }
.cmd-form input { width: 240px; }
.view-toggle { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

.addressbar {
  display: flex; align-items: center; gap: 4px; padding: 6px 10px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.crumbs {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; overflow: hidden;
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 4px 10px; min-height: 32px; margin-left: 4px;
}
.crumbs a, .crumbs .crumb-current { display: inline-flex; align-items: center; gap: 6px; padding: 1px 6px; border-radius: 4px; white-space: nowrap; color: var(--text); }
.crumbs a:hover { background: var(--hover); text-decoration: none; }
.crumbs .crumb-current { font-weight: 600; }
.crumbs .sep { color: var(--faint); }
.searchbox {
  display: flex; align-items: center; gap: 6px; width: 260px; margin: 0 0 0 6px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--muted); background: var(--surface);
}
.searchbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.searchbox input { border: 0; box-shadow: none !important; padding: 4px 0; width: 100%; background: transparent; }

.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 0; }

/* sidebar */
.sidebar {
  overflow-y: auto; padding: 8px 6px 16px; background: var(--chrome); border-right: 1px solid var(--line);
}
.side-link, .tree-link {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: var(--radius);
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.side-link:hover, .tree-link:hover { background: var(--hover); text-decoration: none; }
.side-link.active, .tree-link.current { background: var(--select); }
.side-link .i { color: var(--muted); }
.side-group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.side-heading { margin: 0 8px 4px; font-size: 12px; color: var(--muted); }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 16px; }
.tree li { min-width: 0; }
.tree summary { display: flex; align-items: center; list-style: none; cursor: pointer; border-radius: var(--radius); }
.tree summary::-webkit-details-marker { display: none; }
.tree li > .tree-link, .tree summary .tree-link { flex: 1; }
.tree li:not(:has(> details)) { display: flex; align-items: center; }
.twisty { display: inline-flex; width: 18px; height: 18px; flex: none; align-items: center; justify-content: center; color: var(--muted); }
.twisty .i { width: 12px; height: 12px; transition: transform .12s; }
details[open] > summary .twisty .i { transform: rotate(90deg); }
.folder-ico { color: var(--folder); }
.tree-link span { overflow: hidden; text-overflow: ellipsis; }

/* main area */
.main { overflow: auto; padding: 12px 16px 24px; position: relative; min-height: 0; }
.statusbar {
  display: flex; justify-content: space-between; gap: 12px; padding: 4px 14px;
  font-size: 12.5px; color: var(--muted); background: var(--chrome); border-top: 1px solid var(--line);
}

/* ---------- items: list view ---------- */
.explorer { min-height: 100%; position: relative; }
.items { user-select: none; -webkit-user-select: none; }
.items-head, .item {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 150px 140px 90px; align-items: center; gap: 8px;
}
.items-head {
  padding: 6px 10px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line);
  position: sticky; top: -12px; background: var(--surface); z-index: 1;
}
.item {
  padding: 4px 10px; border: 1px solid transparent; border-radius: 4px; cursor: default; outline: none;
}
.item:hover { background: var(--hover); }
.item.selected { background: var(--select); border-color: var(--select-line); }
.item.cut { opacity: .5; }
.item-check { opacity: 0; }
.item:hover .item-check, .item.selected .item-check, .items:has(.selected) .item-check { opacity: 1; }
.item-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-name:hover { text-decoration: none; }
.c-date, .c-type, .c-size { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-size { text-align: right; }
.item .item-icon { grid-column: 2; grid-row: 1; }
.item .item-name { grid-column: 2; grid-row: 1; padding-left: 30px; }

.item-icon { position: relative; display: inline-flex; width: 22px; height: 22px; color: #8a94a6; }
.item-icon .i { width: 100%; height: 100%; }
.item-icon .ext { display: none; }
.item-icon.sm { width: 20px; height: 20px; }
.kind-folder { color: var(--folder); }
.kind-pdf { color: #d13438; }
.kind-sheet { color: #107c41; }
.kind-doc { color: #185abd; }
.kind-slides { color: #c43e1c; }
.kind-image { color: #8764b8; }
.kind-archive { color: #8a6a4f; }
.kind-video { color: #c239b3; }

/* ---------- items: large icons view ---------- */
.view-grid .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; align-content: start; }
.view-grid .items-head { display: none; }
.view-grid .item {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 12px 6px 10px; position: relative;
}
.view-grid .item-check { position: absolute; top: 6px; left: 6px; }
.view-grid .item-icon { width: 64px; height: 64px; }
.view-grid .item-icon .ext {
  display: block; position: absolute; left: 0; right: 0; bottom: 12px; text-align: center;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.view-grid .item-name {
  padding: 0; white-space: normal; word-break: break-word; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 13px; line-height: 1.3;
}
.view-grid .c-date, .view-grid .c-type, .view-grid .c-size { display: none; }

/* empty states */
.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-icon { width: 72px; height: 72px; color: var(--line-strong); }
.empty-title { font-size: 16px; color: var(--text); margin: 12px 0 4px; }

/* drag and drop + uploads */
.drop-overlay {
  display: none; position: absolute; inset: -4px; z-index: 5; border: 2px dashed var(--accent);
  border-radius: 10px; background: rgba(232, 242, 252, .92); align-items: center; justify-content: center;
  color: var(--accent); text-align: center; font-size: 15px;
}
.drop-overlay .i { width: 44px; height: 44px; }
.explorer.dragging .drop-overlay { display: flex; }
.upload-panel {
  position: fixed; right: 16px; bottom: 40px; width: min(420px, calc(100vw - 32px)); z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.upload-panel header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.uploads { list-style: none; margin: 0; padding: 6px 14px 10px; max-height: 260px; overflow: auto; }
.uploads li { display: grid; grid-template-columns: minmax(0, 1fr) 110px 90px; gap: 10px; align-items: center; padding: 5px 0; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads progress { width: 100%; height: 6px; accent-color: var(--accent); }
.up-status { font-size: 12.5px; color: var(--muted); text-align: right; }
.uploads .done .up-status { color: var(--ok); }
.uploads .failed .up-status { color: var(--danger); grid-column: 2 / -1; text-align: left; }

/* ---------- dialogs ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px 18px; width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow); color: var(--text);
}
.dialog::backdrop { background: rgba(15, 23, 42, .32); }
.dialog h2 { font-size: 17px; margin-bottom: 14px; }
.dialog p { margin: 0 0 12px; }
.dialog .field input { width: 100%; }
.error-list { margin: 0 0 12px; padding-left: 18px; color: var(--danger); }
.choice-list { display: grid; gap: 6px; margin: 4px 0 14px; }
.choice {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.choice .i { margin-top: 2px; color: var(--accent); }
.choice span { display: flex; flex-direction: column; gap: 2px; }

/* ---------- forms and admin pages ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span:first-child { font-size: 13px; color: var(--muted); }
.field-error { color: var(--danger); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset.field { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
fieldset.field legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.form { max-width: 760px; }
.panel.narrow { max-width: 420px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }

.grid-table { width: 100%; border-collapse: collapse; }
.grid-table th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--chrome); }
.grid-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table tbody tr:hover { background: #fafbfc; }
.grid-table tr.is-muted td { color: var(--faint); }
.col-act { width: 1%; white-space: nowrap; text-align: right; }
.actions { white-space: nowrap; }
.actions > * { display: inline-flex; vertical-align: middle; margin: 0 0 0 6px; }
.name-cell { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.person { display: flex; align-items: center; gap: 10px; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; margin: 1px 2px 1px 0;
  background: var(--accent-soft); color: #0b4f8a; border: 1px solid #c7ddf3;
}
.badge-mgmt { background: #f1ecfb; color: #5b2d9e; border-color: #ddd0f3; }
.badge-admin { background: #fff4ce; color: #7a5300; border-color: #f2df9a; }
.status { font-size: 13px; }
.status.ok { color: var(--ok); }
.status.off { color: var(--danger); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.card:hover { border-color: var(--accent); text-decoration: none; background: #fbfdff; }
.card-icon { display: inline-flex; width: 40px; height: 40px; border-radius: 10px; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.card-icon.mgmt { background: #f1ecfb; color: #5b2d9e; }
.card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.card-chevron { color: var(--faint); }
.member-list { display: grid; gap: 2px; max-height: 420px; overflow: auto; margin-bottom: 4px; }
.member { padding: 6px 8px; border-radius: var(--radius); }
.member:hover { background: var(--hover); }

/* ---------- small screens ---------- */
.sidebar-backdrop { display: none; }
@media (max-width: 760px) {
  .tree-toggle { display: inline-flex; }
  .who { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(290px, 85vw); z-index: 30;
    transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(15, 23, 42, .3); }
  .cmd span { display: none; }
  .cmd { padding: 7px 9px; }
  .cmd-form input { width: 150px; }
  .cmd-form .cmd span { display: none; }
  .searchbox { width: 40%; }
  .addressbar #nav-back { display: none; }
  .items-head, .item { grid-template-columns: 28px minmax(0, 1fr) 80px; }
  .c-date, .c-type { display: none; }
  .view-grid .items { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .item-check { opacity: 1; }
  .main { padding: 10px; }
  .form-grid, .two-col { grid-template-columns: minmax(0, 1fr); }
  .grid-table th:nth-child(2):not(:last-child), .grid-table td:nth-child(2):not(:last-child) { display: none; }
}
