/* SecureFileHub */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #646b78;
  --accent: #3b5bdb;
  --accent-hover: #2f4bc4;
  --accent-soft: #e8edff;
  --on-accent: #ffffff;
  --danger: #d6336c;
  --danger-soft: #fdebf1;
  --success: #2b8a3e;
  --warning: #e67700;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
  --shadow-lg: 0 20px 40px -12px rgb(16 24 40 / .25);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa1ae;
    --accent: #748ffc;
    --accent-hover: #91a7ff;
    --accent-soft: #1e2540;
    --on-accent: #0f1115;
    --danger: #f06595;
    --danger-soft: #3a1a26;
    --success: #69db7c;
    --warning: #ffa94d;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / .7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa1ae;
  --accent: #748ffc;
  --accent-hover: #91a7ff;
  --accent-soft: #1e2540;
  --on-accent: #0f1115;
  --danger: #f06595;
  --danger-soft: #3a1a26;
  --success: #69db7c;
  --warning: #ffa94d;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / .7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.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;
}

.icon { width: 1.1em; height: 1.1em; flex: none; fill: currentColor; vertical-align: -.15em; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.page { padding-top: 28px; padding-bottom: 96px; }
.center-page { flex: 1; display: grid; place-items: center; padding: 24px 16px; }

/* Buttons and inputs */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-icon { width: 38px; padding: 0; }
.btn-sm { height: 32px; padding: 0 10px; font-size: .9rem; }
.btn-sm.btn-icon { width: 32px; padding: 0; }
.btn-block { width: 100%; }

.link-button {
  border: 0; background: none; padding: 4px; color: var(--accent);
  font: inherit; cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions.end { justify-content: flex-end; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* Top bar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-icon { width: 24px; height: 24px; color: var(--accent); }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.topbar-actions form { margin: 0; }

/* Dropdown menu and theme toggle */

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 150px;
  display: grid; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.menu-list a { padding: 8px 10px; border-radius: 6px; color: var(--text); }
.menu-list a:hover { background: var(--surface-2); text-decoration: none; }
.menu-list a[aria-current] { color: var(--accent); font-weight: 600; }

[data-theme-toggle] .icon { display: none; }
:root:not([data-theme]) [data-theme-toggle] .theme-auto,
:root[data-theme="light"] [data-theme-toggle] .theme-light,
:root[data-theme="dark"] [data-theme-toggle] .theme-dark { display: inline; }

/* Page header and toolbar */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head p { margin-top: 4px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; }
.search { position: relative; flex: 1; max-width: 420px; }
.search > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }

.segmented { display: inline-flex; margin-left: auto; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented .btn { height: 32px; width: 34px; border: 0; background: transparent; color: var(--muted); }
.segmented .btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* File list */

.files {
  --cols: 36px 44px minmax(0, 1fr) 110px 150px 168px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.files-head, .file {
  display: grid; grid-template-columns: var(--cols);
  align-items: center; gap: 10px; padding: 0 12px;
}
.files-head {
  height: 42px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: .85rem; font-weight: 600;
}
.files-head .sort:first-of-type { grid-column: 2 / 4; }
.sort {
  justify-self: start; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 6px; margin-left: -6px; border: 0; border-radius: 6px;
  background: none; color: inherit; font: inherit; cursor: pointer;
}
.sort:hover { background: var(--surface-2); color: var(--text); }
.sort[aria-sort]::after { content: "↓"; color: var(--accent); }
.sort[aria-sort="ascending"]::after { content: "↑"; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file { min-height: 58px; border-bottom: 1px solid var(--border); transition: background-color .12s; }
.file:last-child { border-bottom: 0; }
.file:hover { background: var(--surface-2); }
.file.is-selected { background: var(--accent-soft); }

.check { display: grid; place-items: center; width: 36px; height: 36px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.file-thumb {
  position: relative; display: grid; place-items: center; overflow: hidden;
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted);
}
.file-thumb .icon { width: 20px; height: 20px; }
.file-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface-2); }
.kind-image { color: #7048e8; }
.kind-pdf { color: #e03131; }
.kind-video { color: #d6336c; }
.kind-audio { color: #0c8599; }
.kind-archive { color: #e67700; }
.kind-sheet { color: #2b8a3e; }
.kind-doc { color: #1c7ed6; }
.kind-slides { color: #f76707; }
.kind-text, .kind-code { color: #5c7cfa; }

.file-main { min-width: 0; display: flex; flex-direction: column; }
.file-name {
  color: var(--text); font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-meta { display: none; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size, .file-date { font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-actions { display: flex; justify-content: flex-end; gap: 2px; }

/* Grid view */

.files[data-view="grid"] { background: none; border: 0; box-shadow: none; }
.files[data-view="grid"] .files-head { display: none; }
.files[data-view="grid"] .file-list {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.files[data-view="grid"] .file {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 0;
  padding: 0; min-height: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.files[data-view="grid"] .file:hover { box-shadow: var(--shadow-lg); }
.files[data-view="grid"] .file.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.files[data-view="grid"] .check {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  background: var(--surface); border-radius: 8px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .15s;
}
.files[data-view="grid"] .file:hover .check,
.files[data-view="grid"] .file.is-selected .check,
.files[data-view="grid"] .check:focus-within { opacity: 1; }
.files[data-view="grid"] .file-thumb { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 0; }
.files[data-view="grid"] .file-thumb .icon { width: 44px; height: 44px; }
.files[data-view="grid"] .file-main { padding: 10px 12px 2px; }
.files[data-view="grid"] .file-meta { display: block; }
.files[data-view="grid"] .file-size, .files[data-view="grid"] .file-date { display: none; }
.files[data-view="grid"] .file-actions { justify-content: flex-start; padding: 2px 6px 8px; }

.empty, .empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 48px 16px; text-align: center; color: var(--muted);
}
.empty .icon, .empty-state .icon { width: 36px; height: 36px; }
.empty-state {
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--text); padding: 72px 16px;
}
.empty-state:hover { border-color: var(--accent); text-decoration: none; }
.empty-state .icon { width: 48px; height: 48px; color: var(--accent); }

.selection-bar {
  position: fixed; left: 50%; bottom: 20px; z-index: 25; transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px; padding: 8px 8px 8px 18px;
  max-width: calc(100vw - 24px);
  background: var(--text); color: var(--bg);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: rise .18s ease-out;
}
.selection-bar #selection-count { font-weight: 600; white-space: nowrap; }
.selection-bar .row-actions { flex-wrap: nowrap; }
.selection-bar .btn:not(.btn-danger) { background: transparent; border-color: color-mix(in srgb, var(--bg) 30%, transparent); color: var(--bg); }
.selection-bar .btn:not(.btn-danger):hover { background: color-mix(in srgb, var(--bg) 15%, transparent); }

/* Upload */

.uploader { display: grid; gap: 16px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 240px; padding: 32px 16px; text-align: center; cursor: pointer;
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius);
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { border-color: var(--accent); }
.dropzone-icon { width: 52px; height: 52px; color: var(--accent); margin-bottom: 6px; }
.dropzone-title { font-weight: 600; font-size: 1.05rem; }

.queue { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.queue-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.queue-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.queue-item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.queue-item:last-child { border-bottom: 0; }
.queue-icon { display: grid; place-items: center; width: 40px; height: 40px; overflow: hidden; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); }
.queue-icon img { width: 100%; height: 100%; object-fit: cover; }
.queue-info { display: grid; gap: 4px; min-width: 0; }
.queue-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.queue-meta { font-size: .82rem; }
.queue-item.is-done .queue-meta { color: var(--success); }
.queue-item.is-failed .queue-meta { color: var(--danger); }
.queue-item.is-done .progress-bar { background: var(--success); }
.queue-item.is-failed .progress-bar { background: var(--danger); }

.progress { display: block; height: 4px; overflow: hidden; background: var(--surface-2); border-radius: 4px; }
.progress-bar { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .2s; }
.queue > .progress { border-radius: 0; }

/* Login and error pages */

.auth-card { width: 100%; max-width: 380px; padding: 36px 28px 20px; text-align: center; display: grid; gap: 14px; }
.auth-logo { display: grid; place-items: center; width: 60px; height: 60px; margin: 0 auto 4px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); }
.auth-logo .icon { width: 30px; height: 30px; }
.auth-title { font-size: 1.4rem; }
.auth-form { display: grid; gap: 12px; margin-top: 8px; }
.code-input { height: 56px; text-align: center; font: 600 1.6rem var(--mono); letter-spacing: .35em; padding-left: calc(12px + .35em); }
.code-input.is-backup { font-size: 1.1rem; letter-spacing: .08em; }
.code-input::placeholder { color: var(--border); }
.auth-footer { display: flex; justify-content: center; gap: 4px; padding-top: 10px; border-top: 1px solid var(--border); }
.auth-footer .menu-list { right: auto; left: 50%; transform: translateX(-50%); top: auto; bottom: calc(100% + 6px); }

.error-card { width: 100%; max-width: 440px; padding: 40px 28px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.error-code { font: 800 4.5rem/1 var(--font); letter-spacing: -.04em; color: var(--accent); }
.error-card .row-actions { justify-content: center; margin-top: 12px; }

/* Dialogs */

.modal {
  width: min(460px, calc(100vw - 24px)); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal[open] { animation: pop .16s ease-out; }
.modal::backdrop { background: rgb(10 12 16 / .55); backdrop-filter: blur(2px); }
.modal > form { margin: 0; }
.modal-title { padding: 20px 22px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 12px 22px 4px; display: grid; gap: 10px; }
.modal-body ul { margin: 0; padding-left: 18px; max-height: 180px; overflow-y: auto; color: var(--muted); word-break: break-all; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px 20px; }

.copy-field { display: flex; gap: 8px; }
.copy-field .input { font: .85rem var(--mono); }

.modal-preview {
  width: min(1100px, calc(100vw - 24px)); height: min(860px, calc(100dvh - 24px));
  max-width: none; max-height: none;
  display: none; flex-direction: column;
  background: #0b0c0f; color: #e7e9ee; border-color: #22252d;
}
.modal-preview[open] { display: flex; }
.preview-head { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 0; border-bottom: 1px solid #22252d; }
.preview-head .modal-title { flex: 1; padding: 0 0 0 18px; font-size: 1rem; font-weight: 600; }
.preview-head .btn-ghost { color: #aab1be; }
.preview-head .btn-ghost:hover { background: #22252d; color: #fff; }
.preview-body { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: auto; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-body audio { width: min(520px, 90%); }
.preview-body pre {
  align-self: stretch; justify-self: stretch; margin: 0; padding: 18px 22px;
  font: .85rem/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
  color: #d8dce4; text-align: left;
}
.preview-note { position: absolute; top: 8px; right: 12px; padding: 2px 8px; border-radius: 6px; background: #22252d; font-size: .8rem; }
.preview-nav {
  position: absolute; top: 50%; z-index: 2; width: 44px; height: 64px; transform: translateY(-50%);
  border: 0; border-radius: 10px; background: rgb(0 0 0 / .45); color: #fff;
  font-size: 2rem; line-height: 1; cursor: pointer; opacity: .7;
}
.preview-nav:hover { opacity: 1; }
.preview-nav.prev { left: 10px; }
.preview-nav.next { right: 10px; }
.spinner { width: 32px; height: 32px; border: 3px solid #333; border-top-color: #aab1be; border-radius: 50%; animation: spin .8s linear infinite; }

/* Toasts */

.toasts { position: fixed; top: 72px; right: 16px; z-index: 50; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  pointer-events: auto; animation: slide-in .2s ease-out;
}
.toast .icon { margin-top: 2px; color: var(--accent); }
.toast-success { border-left-color: var(--success); }
.toast-success .icon { color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-error .icon { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .icon { color: var(--warning); }
.toast.is-leaving { opacity: 0; transform: translateX(16px); transition: opacity .2s, transform .2s; }

@keyframes pop { from { opacity: 0; transform: scale(.97); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Small screens */

@media (max-width: 760px) {
  .container { padding: 0 14px; }
  .page { padding-top: 18px; }
  h1 { font-size: 1.35rem; }
  .nav { margin-left: 0; }
  .nav span, .brand span { display: none; }
  .files { --cols: 36px 44px minmax(0, 1fr) auto; }
  .files-head .sort[data-sort="size"], .files-head .sort[data-sort="mtime"] { display: none; }
  .file-size, .file-date { display: none; }
  .file-meta { display: block; }
  .file-actions [data-action="share"], .file-actions [data-action="preview"] { display: none; }
  .files[data-view="grid"] .file-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .files[data-view="grid"] .check { opacity: 1; }
  .files[data-view="grid"] .file-actions [data-action] { display: inline-flex; }
  .selection-bar { bottom: 12px; gap: 8px; padding-left: 14px; }
  .selection-bar .btn span { display: none; }
  .toasts { top: auto; bottom: 16px; right: 16px; }
  .modal-preview { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
}
