/* ==========================================================================
   FileManager - design tokens, reset, and shared components.
   Light and dark are both first-class: every colour is a token, and the
   dark block only re-points tokens, never adds rules.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Neutrals */
  --bg:            #f6f7f9;
  --bg-raised:     #ffffff;
  --bg-sunken:     #eceef2;
  --bg-hover:      #e8eaef;
  --bg-active:     #dfe2e9;
  --surface-1:     #ffffff;
  --surface-2:     #f9fafb;

  /* Text */
  --text:          #14171f;
  --text-muted:    #5b6472;
  --text-faint:    #8b94a3;
  --text-inverse:  #ffffff;

  /* Lines */
  --border:        #dde1e8;
  --border-strong: #c4cad4;

  /* Accent */
  --accent:        #5b52e0;
  --accent-hover:  #4c43d1;
  --accent-soft:   #ecebfd;
  --accent-text:   #4038b8;
  --accent-ring:   rgba(91, 82, 224, .35);

  /* Status */
  --danger:        #d33a48;
  --danger-soft:   #fdeced;
  --success:       #17864f;
  --success-soft:  #e6f6ee;
  --warning:       #a76a08;
  --warning-soft:  #fdf2e0;
  --info:          #1668b8;
  --info-soft:     #e7f1fb;

  /* File-kind accents, used by icons and labels */
  --kind-folder:   #eab308;
  --kind-image:    #10b981;
  --kind-video:    #ec4899;
  --kind-audio:    #8b5cf6;
  --kind-pdf:      #ef4444;
  --kind-text:     #64748b;
  --kind-code:     #3b82f6;
  --kind-archive:  #f97316;
  --kind-doc:      #2563eb;
  --kind-sheet:    #059669;
  --kind-slides:   #d97706;

  /* Shape and depth */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --shadow-sm:  0 1px 2px rgba(16, 20, 28, .06), 0 1px 3px rgba(16, 20, 28, .04);
  --shadow:     0 4px 12px rgba(16, 20, 28, .08), 0 1px 3px rgba(16, 20, 28, .06);
  --shadow-lg:  0 16px 40px rgba(16, 20, 28, .16), 0 4px 12px rgba(16, 20, 28, .08);
  --shadow-menu: 0 10px 32px rgba(16, 20, 28, .18), 0 2px 6px rgba(16, 20, 28, .10);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  /* Stacking order. Every fixed-position layer in the app takes its
     z-index from here, so a new surface cannot accidentally paint over a
     dialog opened from inside it. */
  --z-drawer:  150;   /* the mobile sidebar */
  --z-surface: 200;   /* full-screen surfaces: admin, viewer, editor */
  --z-tray:    260;   /* the upload tray */
  --z-modal:   300;   /* dialogs, which must sit above every surface */
  --z-menu:    400;   /* context menus, above the dialog that opened them */
  --z-toast:   500;   /* always visible */

  /* Metrics */
  --sidebar-w:  260px;
  --details-w:  320px;
  --topbar-h:   56px;
  --toolbar-h:  46px;
  --row-h:      38px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0e1116;
  --bg-raised:     #161a21;
  --bg-sunken:     #0a0d11;
  --bg-hover:      #1d222b;
  --bg-active:     #262d38;
  --surface-1:     #161a21;
  --surface-2:     #1b2028;

  --text:          #e6e9ef;
  --text-muted:    #98a1b0;
  --text-faint:    #6b7484;
  --text-inverse:  #0e1116;

  --border:        #262c36;
  --border-strong: #39414e;

  --accent:        #7b73ff;
  --accent-hover:  #8d86ff;
  --accent-soft:   #1e1c3a;
  --accent-text:   #a9a3ff;
  --accent-ring:   rgba(123, 115, 255, .40);

  --danger:        #f0616f;
  --danger-soft:   #2c1418;
  --success:       #3ec98a;
  --success-soft:  #0f2a1e;
  --warning:       #e0a34a;
  --warning-soft:  #2b2010;
  --info:          #62aef5;
  --info-soft:     #10222f;

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .5);
  --shadow:     0 4px 14px rgba(0, 0, 0, .5);
  --shadow-lg:  0 20px 48px rgba(0, 0, 0, .6);
  --shadow-menu: 0 12px 36px rgba(0, 0, 0, .6);
}

/* System preference when the user has not chosen explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:            #0e1116;
    --bg-raised:     #161a21;
    --bg-sunken:     #0a0d11;
    --bg-hover:      #1d222b;
    --bg-active:     #262d38;
    --surface-1:     #161a21;
    --surface-2:     #1b2028;
    --text:          #e6e9ef;
    --text-muted:    #98a1b0;
    --text-faint:    #6b7484;
    --text-inverse:  #0e1116;
    --border:        #262c36;
    --border-strong: #39414e;
    --accent:        #7b73ff;
    --accent-hover:  #8d86ff;
    --accent-soft:   #1e1c3a;
    --accent-text:   #a9a3ff;
    --accent-ring:   rgba(123, 115, 255, .40);
    --danger:        #f0616f;
    --danger-soft:   #2c1418;
    --success:       #3ec98a;
    --success-soft:  #0f2a1e;
    --warning:       #e0a34a;
    --warning-soft:  #2b2010;
    --info:          #62aef5;
    --info-soft:     #10222f;
    --shadow-sm:  0 1px 2px rgba(0, 0, 0, .5);
    --shadow:     0 4px 14px rgba(0, 0, 0, .5);
    --shadow-lg:  0 20px 48px rgba(0, 0, 0, .6);
    --shadow-menu: 0 12px 36px rgba(0, 0, 0, .6);
  }
}

/* --------------------------------------------------------------- reset -- */

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 .75em; }
a  { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid var(--bg);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

[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;
}

/* ------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 34px;
  padding: 0 .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text);
  font: inherit;
  font-weight: 520;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--danger); }

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

.btn-icon {
  width: 34px; min-height: 34px; padding: 0;
  background: transparent; border-color: transparent;
  color: var(--text-muted);
}
.btn-icon:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.btn-icon.is-on { background: var(--accent-soft); color: var(--accent-text); }

.btn-sm { min-height: 28px; padding: 0 .6rem; font-size: .8125rem; }
.btn-block { width: 100%; }

/* --------------------------------------------------------------- forms -- */

.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  margin-bottom: .35rem;
  font-size: .8125rem;
  font-weight: 560;
  color: var(--text-muted);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 36px;
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text);
  font: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:disabled, .select:disabled { background: var(--bg-sunken); color: var(--text-faint); }
.textarea { min-height: 90px; resize: vertical; font-family: var(--font-mono); font-size: .8125rem; }
.input-mono { font-family: var(--font-mono); font-size: .8125rem; }

.help { margin: .35rem 0 0; font-size: .75rem; color: var(--text-faint); }
.error-text { margin: .35rem 0 0; font-size: .75rem; color: var(--danger); }

.check {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  cursor: pointer;
  user-select: none;
}
.check input { margin: 2px 0 0; width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.check span { font-size: .875rem; }

.field-row { display: flex; gap: .75rem; }
.field-row > * { flex: 1; min-width: 0; }

/* --------------------------------------------------------------- alerts -- */

.alert {
  display: flex;
  gap: .6rem;
  padding: .7rem .85rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .875rem;
  line-height: 1.45;
}
.alert svg { flex: none; margin-top: 1px; }
.alert-error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--info-soft);    border-color: var(--info);    color: var(--info); }

/* --------------------------------------------------------------- badges -- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge-accent  { background: var(--accent-soft);  color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* --------------------------------------------------------------- modals -- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 11, 16, .55);
  backdrop-filter: blur(3px);
  animation: fade-in .12s ease;
}

.modal {
  width: min(100%, 30rem);
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop-in .14s cubic-bezier(.2, .9, .3, 1.1);
}
.modal-wide { width: min(100%, 46rem); }
.modal-xl   { width: min(100%, 62rem); }

.modal-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { flex: 1; min-width: 0; }
.modal-body { padding: 1.15rem; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
  padding: .85rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-foot .spacer { margin-right: auto; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- toasts -- */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: min(22rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
  font-size: .875rem;
  pointer-events: auto;
  animation: slide-in .16s ease;
}
.toast-error   { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
.toast-info    { border-left-color: var(--info); }
.toast-warning { border-left-color: var(--warning); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; }
.toast-text  { color: var(--text-muted); overflow-wrap: anywhere; }
.toast.is-leaving { animation: slide-out .16s ease forwards; }

@keyframes slide-in  { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes slide-out { to { opacity: 0; transform: translateX(16px); } }

/* --------------------------------------------------------------- utils -- */

.stack   { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: .5rem; }
.row     { display: flex; align-items: center; gap: .6rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.grow    { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono    { font-family: var(--font-mono); font-size: .8125rem; }
.muted   { color: var(--text-muted); }
.faint   { color: var(--text-faint); }
.small   { font-size: .8125rem; }
.tiny    { font-size: .75rem; }
.center  { text-align: center; }
.nowrap  { white-space: nowrap; }

.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--border); margin: .75rem 0; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
