/* BaaliGames Files — responsive file-manager styling.
   System fonts, CSS custom properties for theme (auto light/dark),
   mobile-first layout that grows up to desktop. */

:root {
  --bg:           #f5f7fb;
  --bg-elev:      #ffffff;
  --bg-elev-2:    #f0f3f8;
  --line:         #e3e7ee;
  --line-2:       #d9dee7;
  --text:         #0d1424;
  --text-soft:    #4a5468;
  --text-mute:    #8390a3;
  --accent:       #4f46e5;
  --accent-h:     #4338ca;
  --accent-tint:  #eef2ff;
  --danger:       #dc2626;
  --danger-h:     #b91c1c;
  --warn:         #f59e0b;
  --good:         #16a34a;
  --radius-1:     8px;
  --radius-2:     12px;
  --radius-3:     16px;
  --radius-4:     24px;
  --shadow-1:     0 1px 2px rgba(15,23,42,0.06), 0 1px 1px rgba(15,23,42,0.04);
  --shadow-2:     0 10px 30px -10px rgba(15,23,42,0.15);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0b1220;
    --bg-elev:     #131b2c;
    --bg-elev-2:   #1a2438;
    --line:        #243049;
    --line-2:      #2c3a57;
    --text:        #eef2ff;
    --text-soft:   #c4cce0;
    --text-mute:   #8995ad;
    --accent:      #818cf8;
    --accent-h:    #a5b4fc;
    --accent-tint: #1f2647;
    --danger:      #f87171;
    --danger-h:    #fca5a5;
    --shadow-1:    0 1px 2px rgba(0,0,0,0.35);
    --shadow-2:    0 18px 40px -12px rgba(0,0,0,0.55);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }
.muted { color: var(--text-mute); }
.small { font-size: 12px; }
.icon { font-family: 'Material Symbols Rounded'; font-style: normal; font-weight: normal; line-height: 1; font-variant-ligatures: discretionary-ligatures; vertical-align: -4px; }

/* ─── Top bar ───────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 15px;
  color: var(--text);
}
.brand .icon { color: var(--accent); font-size: 24px; }
.topnav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.logout-form { margin: 0; }
.navlink {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: var(--radius-2);
  color: var(--text-soft); background: transparent;
  border: 0; cursor: pointer;
  font: inherit;
}
.navlink:hover { background: var(--bg-elev-2); color: var(--text); }
.navlink .icon { font-size: 20px; }
.navlink-text { font-size: 13px; font-weight: 600; }
@media (max-width: 540px) {
  .navlink-text, .brand-text { display: none; }
  .topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
}

/* ─── Page shell ───────────────────────────────────────────────── */
.page { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: max(48px, env(safe-area-inset-bottom)); }

/* ─── Auth / share / settings cards ────────────────────────────── */
.auth-wrap { min-height: 70dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 8px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow-2);
  padding: 28px 24px;
}
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .icon { font-size: 44px; color: var(--accent); }
.auth-brand h1 { margin: 6px 0 4px; font-size: 20px; }
.auth-footnote { margin-top: 18px; font-size: 12px; text-align: center; }
.share-card .share-name { word-break: break-all; }

.settings-wrap { max-width: 760px; margin: 0 auto; }
.section-title { margin: 8px 0 16px; font-size: 20px; }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-3); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-1); }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--bg-elev-2); color: var(--text-soft); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.badge-admin { background: var(--accent-tint); color: var(--accent); }

/* ─── Forms ─────────────────────────────────────────────────────── */
.form { display: grid; gap: 12px; }
.form-inline { grid-template-columns: 1fr 1fr auto auto; align-items: end; gap: 12px; }
@media (max-width: 720px) { .form-inline { grid-template-columns: 1fr; } }
.field { display: grid; gap: 6px; }
.field-label { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.field input, .field-input {
  width: 100%;
  padding: 10px 12px; border-radius: var(--radius-2);
  border: 1px solid var(--line-2); background: var(--bg);
  color: var(--text); font: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field-check { display: inline-flex; align-items: center; gap: 8px; padding: 10px 0; }

.alert { padding: 10px 12px; border-radius: var(--radius-2); margin-bottom: 12px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.alert-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert-info  { background: var(--accent-tint); color: var(--accent); }

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--radius-2);
  border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px;
  text-decoration: none;
  transition: background .15s, color .15s, transform .03s, border-color .15s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn .icon { font-size: 18px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); color: #fff; }
.btn-ghost { background: var(--bg-elev-2); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--line-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-h); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.iconbtn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: var(--radius-2);
  background: transparent; color: var(--text-soft);
  border: 1px solid transparent; cursor: pointer;
}
.iconbtn:hover { background: var(--bg-elev-2); color: var(--text); border-color: var(--line); }
.iconbtn .icon { font-size: 22px; }

/* ─── File manager ─────────────────────────────────────────────── */
.fm-shell { position: relative; }

.fm-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.fm-tools {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
}
.fm-search {
  position: relative; min-width: 180px;
}
.fm-search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-mute); font-size: 18px; }
.fm-search input {
  padding: 9px 12px 9px 34px; width: 100%;
  border: 1px solid var(--line-2); background: var(--bg-elev);
  border-radius: 999px; color: var(--text); outline: none; font: inherit;
}
.fm-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.fm-view { display: inline-flex; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-2); padding: 2px; }
.fm-view .iconbtn { width: 32px; height: 32px; border-radius: 8px; }
.fm-view .iconbtn[aria-pressed="true"] { background: var(--accent-tint); color: var(--accent); }
@media (max-width: 720px) {
  .fm-toolbar { grid-template-columns: 1fr; }
  .fm-search { width: 100%; }
  .btn-text { display: none; }
  .fm-tools .btn { padding: 8px 10px; }
}

.fm-breadcrumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; min-height: 36px;
  overflow-x: auto;
}
.crumb {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 999px;
  color: var(--text-soft); cursor: pointer;
  font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.crumb:hover { background: var(--bg-elev-2); color: var(--text); }
.crumb .icon { font-size: 18px; }
.crumb-sep { color: var(--text-mute); font-size: 12px; }

/* List view */
.fm-list {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-3); overflow: hidden;
  box-shadow: var(--shadow-1);
  min-height: 240px;
}
.fm-empty { padding: 40px 16px; text-align: center; color: var(--text-mute); }

/* Desktop row: one line — icon | name | meta | actions */
.fm-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto auto;
  gap: 10px; align-items: center;
  padding: 10px 12px; border-top: 1px solid var(--line);
  cursor: default;
}
.fm-row:first-child { border-top: 0; }
.fm-row:hover { background: var(--bg-elev-2); }
.fm-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--bg-elev-2); color: var(--accent); }
.fm-icon .icon { font-size: 22px; }
.fm-icon.is-zip { color: var(--warn); }
.fm-icon.is-folder { color: var(--accent); }
.fm-name { font-weight: 600; min-width: 0; }
.fm-name button {
  background: none; border: 0; padding: 0; color: inherit; font: inherit;
  font-weight: 600; text-align: left; cursor: pointer; min-width: 0;
  max-width: 100%; display: inline-block; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.fm-name button:hover { color: var(--accent); }
.name-text { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.fm-meta {
  font-size: 12px; color: var(--text-mute); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.fm-meta .sep { padding: 0 4px; color: var(--text-mute); opacity: .55; }

/* Action icons — visible on every screen, never hidden in a menu */
.row-actions {
  display: flex; gap: 2px; justify-content: flex-end; flex-wrap: nowrap;
}
.row-action {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-soft); border-radius: 8px;
  flex: 0 0 auto;
}
.row-action:hover { background: var(--accent-tint); color: var(--accent); }
.row-action.row-danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.row-action:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-action .icon { font-size: 20px; }

/* ─── Mobile rows (portrait phones) — 3 stacked lines ──────────── */
@media (max-width: 720px) {
  .fm-row {
    /* 3 explicit lines:
         row 1 → file icon + name (icon column spans rows 1-2)
         row 2 → "27 May, 8:30 PM · 1.2 MB" (date + size, same line)
         row 3 → action icons, FULL WIDTH, wrap to multiple lines if needed
       so every icon is always on-screen. */
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: 12px;
    row-gap: 2px;
    padding: 12px;
  }
  .fm-icon { grid-row: 1 / 3; grid-column: 1; align-self: center; }
  .fm-name { grid-row: 1; grid-column: 2; }
  .fm-meta { grid-row: 2; grid-column: 2; white-space: normal; }
  .row-actions {
    grid-row: 3; grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;          /* break onto new lines instead of scrolling off-screen */
    gap: 6px;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px dashed var(--line);
    overflow: visible;        /* no horizontal scroll, no mask */
  }
  .row-action {
    width: 40px; height: 40px;  /* roomier touch target on phones */
    background: var(--bg-elev-2);
  }
  .row-action .icon { font-size: 22px; }
  .row-action:hover, .row-action:active {
    background: var(--accent-tint); color: var(--accent);
  }
  .row-action.row-danger {
    background: color-mix(in srgb, var(--danger) 8%, var(--bg-elev-2));
  }
  .row-action.row-danger:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
}

/* Grid view */
.fm-list[data-view="grid"] {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; padding: 12px;
  background: transparent; border: 0; box-shadow: none;
}
.fm-list[data-view="grid"] .fm-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-3);
  background: var(--bg-elev); text-align: center;
}
.fm-list[data-view="grid"] .fm-icon { width: 56px; height: 56px; margin: 0 auto; }
.fm-list[data-view="grid"] .fm-icon .icon { font-size: 30px; }
.fm-list[data-view="grid"] .fm-name { text-align: center; }
.fm-list[data-view="grid"] .fm-name button { text-align: center; }
.fm-list[data-view="grid"] .fm-meta { text-align: center; font-size: 11px; white-space: normal; }
.fm-list[data-view="grid"] .row-actions {
  justify-content: center; flex-wrap: wrap; overflow: visible; border-top: 0; padding-top: 0;
}

/* Drop hint */
.fm-drop-hint {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  display: none; align-items: center; justify-content: center;
  pointer-events: none;
}
.fm-drop-hint.active { display: flex; }
.fm-drop-card {
  background: var(--bg-elev); border: 2px dashed var(--accent);
  border-radius: var(--radius-4); padding: 32px 48px; text-align: center;
  box-shadow: var(--shadow-2); pointer-events: auto;
}
.fm-drop-card .icon { font-size: 48px; color: var(--accent); }
.fm-drop-card p { margin: 8px 0 0; font-weight: 700; }

/* Upload tray */
.upload-tray {
  position: fixed; bottom: 16px; right: 16px; z-index: 60;
  width: min(360px, calc(100vw - 32px));
  max-height: 50vh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-3); box-shadow: var(--shadow-2);
}
.upload-tray-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.upload-tray-head strong { flex: 1; font-size: 13px; }
.upload-tray-body { padding: 8px 12px 12px; display: grid; gap: 8px; }
.upload-item { font-size: 12px; }
.upload-item-name { display: flex; justify-content: space-between; gap: 8px; }
.upload-item-name span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%; }
.upload-bar { margin-top: 4px; height: 6px; background: var(--bg-elev-2); border-radius: 999px; overflow: hidden; }
.upload-bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width .15s linear; }
.upload-item.done .upload-bar-fill { background: var(--good); }
.upload-item.err  .upload-bar-fill { background: var(--danger); }

/* Dialogs */
.dialog { border: 0; padding: 0; background: transparent; }
.dialog::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(3px); }
.dialog-card {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-3);
  padding: 18px; min-width: 280px; max-width: 480px;
  box-shadow: var(--shadow-2);
}
.dialog-card h3 { margin: 0 0 8px; font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.share-link-row { display: flex; gap: 8px; margin-top: 8px; }
.share-link-row input { flex: 1; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-2); background: var(--bg); color: var(--text); }

/* Move dialog folder picker */
.move-card { width: min(440px, 92vw); }
#move-source { color: var(--accent); font-weight: 700; word-break: break-all; }
.folder-picker {
  list-style: none; padding: 4px; margin: 8px 0 0;
  max-height: 320px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-2);
  background: var(--bg);
}
.folder-picker li {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  color: var(--text-soft); font-size: 13px;
}
.folder-picker li:hover { background: var(--bg-elev-2); color: var(--text); }
.folder-picker li.selected { background: var(--accent-tint); color: var(--accent); font-weight: 700; }
.folder-picker li.disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.folder-picker li .icon { font-size: 18px; color: var(--accent); }

/* ─── Preview dialog (image / video / text) ─────────────────────── */
.dialog-preview { width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; }
.dialog-preview::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(6px); }
.preview-card {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-3);
  box-shadow: var(--shadow-2);
  width: min(960px, 96vw); max-height: 92dvh;
  display: flex; flex-direction: column;
  margin: auto;
}
.preview-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.preview-head .preview-headicon { color: var(--accent); font-size: 22px; }
.preview-head h3 { margin: 0; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body {
  flex: 1 1 auto; min-height: 200px; max-height: 80dvh;
  overflow: auto; display: grid; place-items: center;
  background: #0b0f1a;
  position: relative;
}
.preview-body[data-mode="text"] {
  background: var(--bg-elev-2);
  align-items: stretch; justify-items: stretch;
}
.preview-body img,
.preview-body video {
  max-width: 100%; max-height: 80dvh; display: block;
  background: #0b0f1a;
}
.preview-body video { width: 100%; height: auto; }
.preview-body pre {
  width: 100%; max-height: 80dvh; overflow: auto; margin: 0;
  padding: 16px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
  background: transparent; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.preview-loading, .preview-error {
  color: #f5f7fb; text-align: center; padding: 24px;
}
.preview-error { color: #fca5a5; }
@media (max-width: 720px) {
  .preview-card { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0; height: 100dvh; }
  .preview-body { max-height: calc(100dvh - 56px); }
  .preview-body img, .preview-body video, .preview-body pre { max-height: calc(100dvh - 56px); }
}

/* Share list (profile page) */
.share-list { list-style: none; padding: 0; margin: 0; }
.share-item { padding: 12px 0; border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.share-item:first-child { border-top: 0; }
.share-meta strong { word-break: break-all; }
.share-actions { display: flex; gap: 6px; }

/* Users table */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 10px 8px; border-top: 1px solid var(--line); text-align: left; font-size: 13px; }
.users-table th { font-size: 11px; text-transform: uppercase; color: var(--text-mute); letter-spacing: .06em; }

/* Toasts */
#toast-stack {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 80; pointer-events: none;
}
.toast {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-2); pointer-events: auto;
  animation: toast-in .18s ease both;
}
.toast.toast-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.toast.toast-success { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
