/* FileIt v2 — "a filing cabinet". Brand tokens are the EXISTING ones from
   /static/styles.css (blue primary, sky accent, IBM Plex); the brief says keep the
   brand, so the prototype's teal and dark theme were not adopted. Shape/spacing
   follow brief §7: 12px cards, 10px buttons, 8px inputs, 16px base unit. */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #5b6472;
  --border: #e5e8ee;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --accent: #0ea5e9;
  --accent-soft: #eff6ff;
  --danger: #d92d20;
  --ok: #15803d;
  --r-card: 12px;
  --r-btn: 10px;
  --r-input: 8px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "IBM Plex Serif", Georgia, serif;
  --header-h: 56px;
  --tabbar-h: 64px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--primary); }
button { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Header ---------- */
.header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand .logo { font-size: 24px; line-height: 1; color: var(--primary); }
.brand h1 { font-family: var(--font-display); font-size: 20px; font-weight: 600; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--primary);
  font-weight: 600; font-size: 14px; border: 1px solid var(--border);
  cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  min-height: 44px; padding: 0 16px;
  border-radius: var(--r-btn);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--ink);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
  transition: background 150ms ease-out, border-color 150ms ease-out;
}
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-text { border-color: transparent; background: transparent; color: var(--primary); padding: 0 8px; }
.btn-text:hover { background: var(--accent-soft); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-btn);
  border: 1px solid transparent; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; font-size: 18px; color: var(--ink);
}
.icon-btn:hover { background: #f1f5f9; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: calc(100vh - var(--header-h)); }
.sidebar {
  display: none;
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h));
}
.sidebar .btn-primary { width: 100%; margin-bottom: 16px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 12px;
  border-radius: var(--r-btn);
  color: var(--ink); text-decoration: none;
  border-left: 3px solid transparent;
}
.nav a:hover { background: #f1f5f9; }
.nav a.active { color: var(--primary); background: var(--accent-soft); border-left-color: var(--primary); }
.nav .glyph { font-size: 18px; width: 24px; text-align: center; }

main { flex: 1; min-width: 0; padding: 16px; padding-bottom: calc(var(--tabbar-h) + 24px); }
.view { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: var(--tabbar-h);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a, .tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none;
  border: 0; background: transparent; cursor: pointer; position: relative;
}
.tabbar a.active { color: var(--primary); }
.tabbar a.active::before {
  content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px;
  background: var(--primary); border-radius: 0 0 3px 3px;
}
.tabbar .glyph { font-size: 20px; }
.tabbar .fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 26px;
  display: grid; place-items: center; margin-top: -22px;
  box-shadow: 0 6px 16px rgba(29, 78, 216, 0.35);
}

@media (min-width: 900px) {
  :root { --header-h: 60px; }
  .sidebar { display: block; }
  .tabbar { display: none; }
  main { padding: 24px; }
  .header-actions .btn-upload { display: inline-flex; }
}
@media (max-width: 899px) {
  .header-actions .btn-upload { display: none; }
}

/* ---------- Cards / rows ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 16px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.search {
  width: 100%; height: 48px; padding: 0 16px 0 44px;
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235b6472' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 14px center;
  font: inherit; color: var(--ink);
}
.search.small { height: 44px; }
input[type="text"], input[type="email"], select {
  min-height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--r-input);
  font: inherit; color: var(--ink); background: var(--surface);
  width: 100%;
}
label.field { display: grid; gap: 6px; font-size: 14px; }

.folder-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 900px) { .folder-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .folder-grid { grid-template-columns: repeat(4, 1fr); } }
.folder-card {
  display: flex; flex-direction: column; gap: 8px; text-align: left;
  min-height: 96px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  cursor: pointer; color: var(--ink);
}
.folder-card:hover { border-color: var(--accent); }
.folder-card .glyph { font-size: 24px; }
.folder-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row .glyph { font-size: 22px; width: 32px; text-align: center; flex: 0 0 32px; }
.row .main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: inherit; }
.row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.row .name-input { min-height: 36px; padding: 0 8px; font: inherit; width: 100%; border-radius: var(--r-input); border: 1px solid var(--accent); }
.row .rename-box { flex: 1; min-width: 0; }
.row .meta { color: var(--muted); font-size: 13px; }
.row .meta .long { display: none; }
@media (min-width: 900px) { .row .meta .long { display: inline; } .row .meta .short { display: none; } }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 100%; z-index: 30;
  min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  display: flex; flex-direction: column;
}
.menu-list button {
  text-align: left; min-height: 40px; padding: 0 12px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink);
}
.menu-list button:hover { background: #f1f5f9; }
.menu-list button.danger { color: var(--danger); }

.empty {
  display: grid; place-items: center; gap: 8px; text-align: center;
  padding: 32px 16px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--r-card); background: var(--surface);
}
.empty .glyph { font-size: 36px; }
.empty strong { color: var(--ink); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa;
  font-size: 14px; cursor: pointer;
}
.storage-strip {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 16px; color: var(--muted); font-size: 13px;
  text-decoration: none; border-radius: var(--r-card); border: 1px solid var(--border); background: var(--surface);
}
.storage-strip .bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.storage-strip .bar span { display: block; height: 100%; width: 0; background: var(--accent); }

.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 14px; }
.breadcrumb button { border: 0; background: transparent; color: var(--primary); cursor: pointer; padding: 6px 4px; font: inherit; min-height: 36px; }
.breadcrumb .sep { color: var(--muted); }
.breadcrumb .current { font-weight: 600; padding: 6px 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .search { flex: 1 1 220px; width: auto; }

/* ---------- File viewer ---------- */
.file-top { display: flex; align-items: center; gap: 8px; }
.file-top .title { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.file-top .title-input { flex: 1; font-size: 18px; font-weight: 600; }
.preview { background: #0f172a08; border: 1px solid var(--border); border-radius: var(--r-card); min-height: 320px; display: grid; place-items: center; overflow: hidden; }
.preview iframe, .preview img { width: 100%; height: 70vh; border: 0; display: block; background: #fff; }
.preview img { object-fit: contain; }
.action-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; min-height: 28px; display: flex; align-items: center; justify-content: space-between; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; color: var(--muted); transition: transform 150ms ease-out; }
details.card[open] > summary::after { transform: rotate(180deg); }
details.card > .body { margin-top: 12px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.danger-zone { border-color: #fecaca; }

/* ---------- Sharing / Settings ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button {
  min-height: 44px; padding: 0 16px; border: 0; background: transparent; cursor: pointer;
  color: var(--muted); border-bottom: 3px solid transparent; font: inherit; font-weight: 500;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.switch input { width: 44px; height: 24px; margin: 0; accent-color: var(--primary); }
.member { display: flex; align-items: center; gap: 12px; }
.member .avatar { width: 36px; height: 36px; font-size: 13px; cursor: default; }
.member .who { flex: 1; min-width: 0; }
.member .who .name { font-weight: 500; }
.member select { width: auto; min-height: 36px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #f1f5f9; color: var(--muted); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fff7ed; color: #9a3412; }
.advanced-item > summary { min-height: 44px; }
.advanced-item iframe { width: 100%; min-height: 60vh; border: 0; border-radius: var(--r-input); background: var(--surface); }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; background: #f1f5f9; padding: 8px 10px; border-radius: var(--r-input); }

/* ---------- Dialogs / sheets ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: 0;
  width: 100vw; max-width: 100vw; max-height: 92vh;
  position: fixed; left: 0; right: 0; bottom: 0; top: auto;
  border-radius: var(--r-card) var(--r-card) 0 0;
  background: var(--surface); color: var(--ink);
  animation: slide-up 200ms ease-out;
}
dialog.sheet::backdrop, dialog.dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
dialog.dialog {
  border: 0; padding: 0;
  width: min(480px, calc(100vw - 32px));
  border-radius: var(--r-card);
  background: var(--surface); color: var(--ink);
  animation: fade-in 150ms ease-out;
}
@media (min-width: 900px) {
  dialog.sheet {
    width: min(640px, calc(100vw - 32px)); max-width: none;
    left: 50%; top: 50%; bottom: auto; transform: translate(-50%, -50%);
    border-radius: var(--r-card); animation: fade-in 150ms ease-out;
  }
}
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 16px 0; }
.dlg-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px 16px; }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.dropzone {
  position: relative;
  display: grid; place-items: center; gap: 6px; text-align: center;
  min-height: 180px; padding: 16px;
  border: 2px dashed var(--border); border-radius: var(--r-card);
  background: var(--bg); color: var(--muted);
}
.dropzone .glyph { font-size: 32px; }
.dropzone strong { color: var(--ink); font-size: 16px; }
.dropzone input { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.dropzone.dragover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.dropzone .btn { pointer-events: none; }
.upload-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.upload-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.upload-item .name { font-weight: 500; overflow-wrap: anywhere; }
.upload-item .prog { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.upload-item .prog span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 150ms ease-out; }
.upload-item .prog.indeterminate span { width: 40%; animation: slide 1s linear infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.upload-item .err { color: var(--danger); font-size: 13px; grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (min-width: 900px) { .toast-host { bottom: 24px; } }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--r-btn);
  background: var(--ink); color: #fff; font-size: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  animation: fade-in 150ms ease-out;
  max-width: calc(100vw - 32px);
}
.toast button { border: 0; background: transparent; color: #93c5fd; font: inherit; font-weight: 600; cursor: pointer; padding: 4px; }
