:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171717;
  background: #f5f5f5;
  font-synthesis: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
a { color: inherit; }
button, .button, .small-button {
  appearance: none;
  border: 1px solid #1e1e1e;
  background: #1e1e1e;
  color: #fff;
  border-radius: 7px;
  padding: .62rem .9rem;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover, .small-button:hover { opacity: .82; }
.secondary, .small-button { background: #fff; color: #222; border-color: #d0d0d0; }
.danger { color: #a51d1d; }
.muted { color: #747474; }
.topbar {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 1.25rem max(1rem, calc((100vw - 1180px) / 2));
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { font-size: 1.25rem; margin: 0; }
.topbar p { margin: .2rem 0 0; color: #777; font-size: .9rem; }
.top-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.top-actions form { margin: 0; }
.manager { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: .22rem; align-items: center; margin-bottom: 1rem; font-size: .95rem; }
.breadcrumbs a { text-decoration: none; font-weight: 650; }
.upload-panel, .file-list, .toolbar {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
}
.upload-panel { padding: 1rem; margin-bottom: 1rem; }
.dropzone {
  border: 2px dashed #bbb;
  border-radius: 9px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  transition: background .15s, border-color .15s;
}
.dropzone.dragging { background: #f0f0f0; border-color: #222; }
.dropzone span { color: #777; font-size: .9rem; }
.upload-buttons { display: flex; gap: .55rem; margin-top: .65rem; flex-wrap: wrap; justify-content: center; }
.upload-status { margin-top: .75rem; padding: .75rem; border-radius: 7px; background: #f1f1f1; display: flex; gap: .55rem; flex-wrap: wrap; }
.toolbar { margin-bottom: 1rem; padding: .75rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.file-list { overflow: hidden; }
.file-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto auto;
  gap: .8rem;
  align-items: center;
  min-height: 64px;
  padding: .65rem .8rem;
  border-bottom: 1px solid #eee;
}
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: #fafafa; }
.file-row.parent-row { text-decoration: none; min-height: 48px; }
.file-row.unsupported { opacity: .6; }
.file-main { min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.file-name { font-weight: 650; text-decoration: none; overflow-wrap: anywhere; }
.meta { color: #808080; font-size: .78rem; }
.row-links, .row-actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.small-button { padding: .38rem .58rem; font-size: .8rem; }
.empty { padding: 3rem 1rem; text-align: center; color: #777; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid #ddd; border-radius: 12px; padding: 2rem; box-shadow: 0 12px 45px #0000000d; }
.login-card h1 { margin: 0; }
.login-card .muted { margin-top: .25rem; }
.stack { display: grid; gap: 1rem; margin: 1.5rem 0; }
.stack label { display: grid; gap: .35rem; font-size: .85rem; font-weight: 650; }
.stack input { width: 100%; padding: .7rem .75rem; border: 1px solid #bbb; border-radius: 7px; font: inherit; }
.notice { padding: .75rem; border-radius: 7px; margin-top: 1rem; }
.notice.error { background: #fff0f0; color: #8d1a1a; }
.subtle-link { color: #666; font-size: .85rem; }
@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .file-row { grid-template-columns: 1.2rem minmax(0, 1fr) auto; }
  .row-links { justify-content: flex-end; }
  .row-actions { grid-column: 2 / -1; justify-content: flex-start; }
}

/* Compact manager navigation and backup controls. */
.manager-tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: .85rem;
  border-bottom: 1px solid #d8d8d8;
}
.manager-tabs a {
  padding: .48rem .72rem;
  text-decoration: none;
  color: #666;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: .9rem;
  font-weight: 650;
}
.manager-tabs a.active { color: #171717; border-bottom-color: #171717; }
.toolbar-group { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.select-all { display: inline-flex; align-items: center; gap: .42rem; font-size: .86rem; font-weight: 650; cursor: pointer; }
.backup-name-field {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  font-size: .8rem;
  color: #666;
}
.backup-name-field input {
  width: min(19rem, 38vw);
  min-width: 13rem;
  padding: .48rem .58rem;
  border: 1px solid #cfcfcf;
  border-radius: 7px;
  background: #fff;
  color: #222;
  font: inherit;
}
.backup-name-field input:focus {
  outline: 2px solid #222;
  outline-offset: 1px;
}

.select-all input, .row-select input { width: 1rem; height: 1rem; margin: 0; cursor: pointer; }
.row-select { display: grid; place-items: center; }
.selection-spacer { width: 1rem; }
.compact-status { margin: -.35rem 0 1rem; }
.backup-summary { align-items: baseline; }
.backup-list .backup-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto;
  gap: .65rem;
  align-items: center;
  min-height: 52px;
  padding: .55rem .72rem;
  border-bottom: 1px solid #eee;
}
.backup-list .backup-row:last-child { border-bottom: 0; }
.backup-list .backup-row:hover { background: #fafafa; }
.backup-filename { color: #999; font-size: .72rem; overflow-wrap: anywhere; }

/* Tighten the regular file manager without making the controls cramped. */
.file-row {
  grid-template-columns: 1rem 1.25rem minmax(0, 1fr) auto auto;
  gap: .62rem;
  min-height: 50px;
  padding: .5rem .72rem;
}
.file-row.parent-row { min-height: 42px; }
.toolbar { padding: .62rem .72rem; margin-bottom: .85rem; }
.upload-panel { padding: .8rem; margin-bottom: .85rem; }
.dropzone { min-height: 150px; padding: 1.15rem; }
.small-button { padding: .32rem .5rem; }

@media (max-width: 760px) {
  .file-row { grid-template-columns: 1rem 1.2rem minmax(0, 1fr) auto; }
  .file-row .row-actions { grid-column: 3 / -1; }
  .backup-list .backup-row { grid-template-columns: 1.2rem minmax(0, 1fr); }
  .backup-list .backup-row .row-actions { grid-column: 2; justify-content: flex-start; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .backup-name-field { width: 100%; }
  .backup-name-field input { width: 100%; min-width: 0; }
}

/* Directory-backup workflow and private trash. */
.breadcrumb-separator { color: #aaa; user-select: none; }
.sort-control {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: #666;
  font-size: .8rem;
}
.sort-control select {
  padding: .42rem .5rem;
  border: 1px solid #cfcfcf;
  border-radius: 7px;
  background: #fff;
  color: #222;
  font: inherit;
}
.directory-name { font-weight: 700; }

/* Checkboxes were removed: icon, name/meta, open links, item actions. */
.file-row {
  grid-template-columns: 1.25rem minmax(0, 1fr) auto auto;
}
.file-row.parent-row {
  grid-template-columns: 1.25rem minmax(0, 1fr) auto auto;
}

.backup-list .backup-row {
  grid-template-columns: 1.1rem 1.25rem minmax(0, 1fr) auto;
}
.disclosure-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: #555;
  padding: 0;
  width: 1.1rem;
  min-width: 1.1rem;
  height: 1.6rem;
  border-radius: 4px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.disclosure-button:hover { background: #eee; opacity: 1; }
.backup-contents {
  grid-column: 3 / -1;
  border-top: 1px solid #eee;
  padding: .45rem 0 .25rem;
  min-width: 0;
}
.backup-contents-list {
  max-height: 24rem;
  overflow: auto;
  font: .75rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #555;
}
.backup-content-item {
  padding: .08rem .35rem .08rem calc(.35rem + (var(--depth) * .65rem));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.backup-content-item:hover { background: #f5f5f5; }
.backup-contents-note { padding: .35rem; color: #888; font-size: .75rem; }

.trash-list .trash-row {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
  gap: .62rem;
  align-items: center;
  padding: .55rem .72rem;
  border-bottom: 1px solid #eee;
}
.trash-list .trash-row:last-child { border-bottom: 0; }
.trash-list .trash-row:hover { background: #fafafa; }
.restore-conflict {
  grid-column: 2 / -1;
  display: flex;
  gap: .55rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: .55rem .65rem;
  border-radius: 7px;
  background: #fff5e6;
  color: #674500;
  font-size: .82rem;
}
.conflict-actions { display: flex; flex-wrap: wrap; gap: .35rem; }

@media (max-width: 760px) {
  .file-row { grid-template-columns: 1.2rem minmax(0, 1fr) auto; }
  .file-row .row-actions { grid-column: 2 / -1; }
  .backup-list .backup-row { grid-template-columns: 1rem 1.2rem minmax(0, 1fr); }
  .backup-list .backup-row .row-actions { grid-column: 3; justify-content: flex-start; }
  .backup-contents { grid-column: 2 / -1; }
  .trash-list .trash-row { grid-template-columns: 1.2rem minmax(0, 1fr); }
  .trash-list .trash-row .row-actions { grid-column: 2; justify-content: flex-start; }
  .restore-conflict { grid-column: 2; }
}

/* Light/dark theme. The default stays light unless theme.js follows the
   system preference or the user has stored an explicit override. */
:root { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

html[data-theme="dark"] {
  background: #151515;
}
html[data-theme="dark"] body,
html[data-theme="dark"] :root {
  color: #e7e7e7;
  background: #151515;
}
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .upload-panel,
html[data-theme="dark"] .file-list,
html[data-theme="dark"] .toolbar,
html[data-theme="dark"] .login-card {
  background: #1d1d1d;
  border-color: #353535;
}
html[data-theme="dark"] .topbar { border-bottom-color: #353535; }
html[data-theme="dark"] .topbar p,
html[data-theme="dark"] .muted,
html[data-theme="dark"] .dropzone span,
html[data-theme="dark"] .meta,
html[data-theme="dark"] .subtle-link,
html[data-theme="dark"] .manager-tabs a,
html[data-theme="dark"] .backup-name-field,
html[data-theme="dark"] .sort-control {
  color: #a7a7a7;
}
html[data-theme="dark"] .manager-tabs { border-bottom-color: #383838; }
html[data-theme="dark"] .manager-tabs a.active {
  color: #f1f1f1;
  border-bottom-color: #f1f1f1;
}
html[data-theme="dark"] .secondary,
html[data-theme="dark"] .small-button {
  background: #292929;
  color: #ededed;
  border-color: #484848;
}
html[data-theme="dark"] button:not(.secondary):not(.small-button):not(.disclosure-button),
html[data-theme="dark"] .button:not(.secondary) {
  background: #eeeeee;
  color: #171717;
  border-color: #eeeeee;
}
html[data-theme="dark"] .danger { color: #ff8c8c; }
html[data-theme="dark"] .dropzone { border-color: #565656; }
html[data-theme="dark"] .dropzone.dragging {
  background: #272727;
  border-color: #d8d8d8;
}
html[data-theme="dark"] .upload-status {
  background: #282828;
  color: #e2e2e2;
}
html[data-theme="dark"] .file-row,
html[data-theme="dark"] .backup-list .backup-row,
html[data-theme="dark"] .trash-list .trash-row {
  border-bottom-color: #323232;
}
html[data-theme="dark"] .file-row:hover,
html[data-theme="dark"] .backup-list .backup-row:hover,
html[data-theme="dark"] .trash-list .trash-row:hover {
  background: #242424;
}
html[data-theme="dark"] .empty { color: #a7a7a7; }
html[data-theme="dark"] .stack input,
html[data-theme="dark"] .backup-name-field input,
html[data-theme="dark"] .sort-control select {
  background: #242424;
  color: #ededed;
  border-color: #4b4b4b;
}
html[data-theme="dark"] .stack input:focus,
html[data-theme="dark"] .backup-name-field input:focus,
html[data-theme="dark"] .sort-control select:focus {
  outline-color: #dedede;
}
html[data-theme="dark"] .notice.error {
  background: #3a1f1f;
  color: #ffadad;
}
html[data-theme="dark"] .breadcrumb-separator { color: #777; }
html[data-theme="dark"] .disclosure-button { color: #bbb; }
html[data-theme="dark"] .disclosure-button:hover { background: #303030; }
html[data-theme="dark"] .backup-contents { border-top-color: #323232; }
html[data-theme="dark"] .backup-contents-list { color: #bebebe; }
html[data-theme="dark"] .backup-content-item:hover { background: #282828; }
html[data-theme="dark"] .backup-contents-note,
html[data-theme="dark"] .backup-filename { color: #8f8f8f; }
html[data-theme="dark"] .restore-conflict {
  background: #3a2f1b;
  color: #ffd88a;
}
html[data-theme="dark"] .login-card { box-shadow: 0 12px 45px #00000055; }

.theme-login-row {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: center;
}
.theme-login-row .small-button { flex: 0 0 auto; }
.login-preferences { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }


/* Keep all file-row controls in one evenly spaced action group. */
.file-row {
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
}
.file-row.parent-row {
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
}
.row-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: .35rem;
}
.row-controls .row-links,
.row-controls .row-actions {
  display: contents;
}

@media (max-width: 760px) {
  .file-row { grid-template-columns: 1.2rem minmax(0, 1fr) auto; }
  .file-row .row-controls {
    grid-column: 2 / -1;
    justify-content: flex-start;
  }
}


/* Dotfiles stay in the server-side listing and backups; this only controls
   whether their rows are visible in the Files view. */
html:not([data-show-hidden="1"]) .file-row.hidden-entry {
  display: none;
}
html[data-show-hidden="1"] .hidden-files-empty {
  display: none;
}


/* v3: precise file-row grid.  One icon, one filename/meta block, one control
   group. Earlier CSS targeted the PHP manager's retired selection checkbox. */
.file-list .file-row {
  display: grid;
  grid-template-columns: 1.35rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .7rem;
  min-height: 62px;
  padding: .68rem .85rem;
}
.file-list .file-row .icon { text-align: center; color: #707070; }
.file-list .file-row .file-main { min-width: 0; align-items: flex-start; }
.file-list .file-row .file-name { text-align: left; overflow-wrap: anywhere; }
.file-list .file-row .row-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .4rem; min-width: 0; }
.file-list .file-row .row-links, .file-list .file-row .row-actions { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; justify-content: flex-end; }
.file-list .file-row.parent-row .file-name { font-weight: 650; }
.backup-list .backup-row { grid-template-columns: 1.1rem 1.25rem minmax(0,1fr) auto; }
.backup-list .backup-row .row-actions { align-self: center; }
.backup-list .backup-contents { grid-column: 3 / -1; }
@media (max-width: 900px) {
  .file-list .file-row { grid-template-columns: 1.35rem minmax(0,1fr); gap: .45rem .7rem; }
  .file-list .file-row .row-controls { grid-column: 2; justify-content: flex-start; }
  .file-list .file-row .row-links, .file-list .file-row .row-actions { justify-content: flex-start; }
  .backup-list .backup-row { grid-template-columns: 1.1rem 1.25rem minmax(0, 1fr); }
  .backup-list .backup-row .row-actions { grid-column: 3; justify-content: flex-start; }
  .backup-list .backup-contents { grid-column: 2 / -1; }
}
@media (max-width: 500px) {
  .file-list .file-row { padding: .6rem .65rem; }
  .file-list .file-row .row-controls { gap: .3rem; }
  .file-list .file-row .row-actions { gap: .25rem; }
  .small-button { padding: .4rem .55rem; min-height: 2rem; }
}
html[data-theme="dark"] .file-list .file-row .icon { color: #a9a9a9; }

/* Self-service accounts and one-time invitations. */
.account-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,360px),1fr)); align-items: start; gap: 1rem; }
.account-panel { border: 1px solid #ddd; border-radius: 10px; padding: 1.25rem; min-width: 0; background: #fff; }
.account-panel h2 { font-size: 1.1rem; margin: 0 0 .7rem; }
.account-panel h3 { font-size: .9rem; margin: 1.25rem 0 .5rem; }
.account-panel .stack { margin-bottom: 0; }
.account-panel p, .enroll-card p { line-height: 1.5; }
.invite-link { margin-top: 1rem; display: grid; gap: .4rem; }
.invite-link label { font-weight: 650; font-size: .9rem; }
.invite-link input { font: inherit; width: 100%; min-width: 0; padding: .6rem; border: 1px solid #bbb; border-radius: 7px; }
.account-list { padding-left: 1.25rem; }
.account-list li { margin-bottom: .35rem; }
.enroll-card { width: min(540px,100%); }
.enroll-card h2 { font-size: 1.1rem; }
.totp-secret { display: flex; gap: .6rem; align-items: center; padding: .75rem; border: 1px dashed #bbb; border-radius: 7px; overflow-wrap: anywhere; }
.totp-secret code { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.recovery-codes { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .5rem; padding: .7rem 1rem; border: 1px solid #bbb; border-radius: 7px; list-style: none; }
.recovery-codes code { font-size: .8rem; overflow-wrap: anywhere; }
html[data-theme="dark"] .account-panel { background: #222; border-color: #383838; }
html[data-theme="dark"] .invite-link input { background: #252525; border-color: #505050; color: #eee; }
html[data-theme="dark"] .totp-secret, html[data-theme="dark"] .recovery-codes { border-color: #555; }
@media (max-width:500px) { .recovery-codes { grid-template-columns: 1fr; } }

.revoke-form { margin-top: .75rem; }
