:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --border: #e4dcd0;
  --text: #241c15;
  --muted: #75695c;
  --accent: #b4531a;
  --accent-strong: #97410f;
  --accent-soft: #fbe9d9;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(36, 28, 21, 0.14);
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --surface: #211b16;
    --surface-2: #2b241d;
    --border: #3a3128;
    --text: #f3ece3;
    --muted: #a89b8c;
    --accent: #e8853f;
    --accent-strong: #f29a5b;
    --accent-soft: #3a2616;
    --on-accent: #1a120b;
    --danger: #ff8a80;
    --warn: #f0b429;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 10px 0 0; font-size: 14px; }

.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* ---------- botões e campos ---------- */

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, .sort:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 11px 14px; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.field { display: block; margin-top: 14px; text-align: left; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input, .search input {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

/* ---------- login ---------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; text-align: center; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 12px 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.auth-card .muted { margin: 0 0 6px; font-size: 14px; }
.auth-card .btn.block { margin-top: 20px; }
.auth-logo { border-radius: 12px; }

/* ---------- app ---------- */

.app { max-width: 1100px; margin: 0 auto; padding: 0 16px 90px; min-height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 0;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px;
  color: var(--text); text-decoration: none; letter-spacing: -0.01em;
}
.brand img { border-radius: 7px; }
.search { flex: 1 1 220px; min-width: 0; }
.search input { background: var(--surface-2); border-color: transparent; }
.topbar-actions { display: flex; gap: 2px; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 0 12px; flex-wrap: wrap;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 18px; font-weight: 600; min-width: 0; }
.breadcrumbs button {
  font: inherit; color: var(--muted); background: none; border: 0; padding: 4px 8px; border-radius: 6px; cursor: pointer;
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.breadcrumbs button:hover { background: var(--surface-2); color: var(--text); }
.breadcrumbs button[aria-current] { color: var(--text); cursor: default; }
.breadcrumbs .sep { color: var(--muted); font-weight: 400; }

.selection {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 10px;
  font-size: 14px; font-weight: 600;
}
.selection span { margin-right: auto; }

.listing { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.files { width: 100%; border-collapse: collapse; table-layout: fixed; }
.files th, .files td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.files tbody tr:last-child td { border-bottom: 0; }
.files thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--surface-2); }
.files tbody tr:hover { background: var(--surface-2); }
.files tbody tr.selected { background: var(--accent-soft); }
.col-check { width: 40px; }
.col-date { width: 170px; }
.col-size { width: 100px; }
.col-actions { width: 150px; }
.files td.col-date, .files td.col-size { color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.files td.col-actions { text-align: right; white-space: nowrap; }

.sort { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-transform: inherit; letter-spacing: inherit; font-weight: 700; }
.sort[data-dir="asc"]::after { content: " ↑"; }
.sort[data-dir="desc"]::after { content: " ↓"; }

.name {
  display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0;
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
}
.name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.name .where { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.name:hover .label { text-decoration: underline; }
.icon { flex: none; width: 22px; height: 22px; color: var(--muted); }
.icon.folder { color: var(--accent); }

.iconbtn {
  background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--muted); line-height: 0;
}
.iconbtn:hover { background: var(--border); color: var(--text); }
.iconbtn.danger:hover { color: var(--danger); }
.iconbtn svg { width: 17px; height: 17px; }

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.storage {
  margin-top: 18px; padding: 16px 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.storage header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.storage h2 { margin: 0; font-size: 14px; font-weight: 700; }
.storage-percent { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.storage-bar { height: 10px; margin: 10px 0 14px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.storage-fill { height: 100%; width: 0; min-width: 0; border-radius: 999px; background: var(--accent); transition: width 0.3s ease; }
.storage[data-level="warn"] .storage-fill { background: var(--warn); }
.storage[data-level="full"] .storage-fill { background: var(--danger); }
.storage-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; }
.storage-stats dt { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.storage-stats dd { margin: 2px 0 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.storage-note { margin: 12px 0 0; font-size: 13px; color: var(--danger); }
.storage[data-level="warn"] .storage-note { color: var(--text); }

@media (max-width: 560px) {
  .storage-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.usage { padding: 14px 4px; font-size: 13px; color: var(--muted); }

.dropzone {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.dropzone div {
  background: var(--surface); border: 2px dashed var(--accent); border-radius: 16px;
  padding: 28px 40px; font-weight: 700; font-size: 17px; box-shadow: var(--shadow);
}

/* ---------- envios ---------- */

.uploads {
  position: fixed; right: 16px; bottom: 16px; z-index: 20; width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.uploads header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; background: var(--surface-2); }
.uploads ul { list-style: none; margin: 0; padding: 6px 14px 10px; max-height: 240px; overflow: auto; }
.uploads li { padding: 7px 0; font-size: 13.5px; }
.uploads li .row { display: flex; justify-content: space-between; gap: 10px; }
.uploads li .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads li .state { color: var(--muted); flex: none; }
.uploads li.failed .state { color: var(--danger); }
.uploads progress { width: 100%; height: 5px; margin-top: 5px; accent-color: var(--accent); }

/* ---------- diálogos ---------- */

dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 0; }
dialog::backdrop { background: rgba(20, 14, 9, 0.55); }

.dialog { width: min(420px, calc(100vw - 32px)); }
.dialog form { padding: 22px; }
.dialog h2 { margin: 0 0 6px; font-size: 18px; }
.dialog p { margin: 6px 0 0; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.tree { list-style: none; margin: 12px 0 0; padding: 4px; max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.tree button {
  width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0;
  padding: 7px 8px; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree button:hover { background: var(--surface-2); }
.tree button[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.tree button:disabled { opacity: 0.4; cursor: not-allowed; }

.preview { width: min(1000px, calc(100vw - 24px)); height: min(820px, calc(100vh - 24px)); }
.preview[open] { display: flex; flex-direction: column; }
.preview header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border); }
.preview header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview header span { display: flex; gap: 6px; flex: none; }
.preview-body { flex: 1; min-height: 0; display: grid; place-items: center; overflow: auto; background: var(--surface-2); }
.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 pre { align-self: start; justify-self: stretch; margin: 0; padding: 18px; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }
.preview-body .note { text-align: center; color: var(--muted); padding: 24px; }
.preview-body progress { width: 220px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  .col-date { display: none; }
  .col-actions { width: 76px; }
  .iconbtn.optional { display: none; }
  .topbar-actions { margin-left: auto; }
  .search { order: 3; flex-basis: 100%; }
  .breadcrumbs { font-size: 16px; }
}

@media (max-width: 460px) {
  .col-size { display: none; }
}
