:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6ea;
  --text: #16191d;
  --muted: #66707c;
  --accent: #1f5eff;
  --accent-soft: #e8efff;
  --danger: #d33a3a;
  --danger-soft: #fdecec;
  --ok: #188a4b;
  --pdf: #d64545;
  --word: #2b5cd6;
  --excel: #1b8a4c;
  --folder: #e0a21a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #181b20;
    --surface-2: #1e2228;
    --border: #2b3038;
    --text: #e8eaed;
    --muted: #9aa3ae;
    --accent: #5b8cff;
    --accent-soft: #1d2a4a;
    --danger: #ff6b6b;
    --danger-soft: #3a1d1f;
    --ok: #3ccf7f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 18px; height: 18px; flex: none; }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- botões e campos ---------- */
button, .btn {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.icon-btn { padding: 6px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

label { display: block; font-weight: 500; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], select {
  font: inherit; width: 100%;
  padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--danger); margin-top: 10px; min-height: 1em; }

/* ---------- autenticação ---------- */
.auth-wrap { 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: 14px;
  padding: 28px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin: 10px 0 4px; }
.auth-card p { margin: 0 0 8px; }
.auth-card button[type=submit] { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 17px; height: 17px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 8px 16px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.me { padding: 4px 8px 10px; }
.me strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot button { width: 100%; justify-content: flex-start; border-color: transparent; background: transparent; color: var(--muted); }
.sidebar-foot button:hover { color: var(--text); background: var(--surface-2); }

.main { padding: 24px 28px 48px; min-width: 0; position: relative; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--muted); font-weight: 500; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--muted); font-weight: 400; }

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

/* ---------- tabela ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.col-name { width: 45%; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-cell a, .name-cell span.n { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell .badge { margin-left: 4px; }
.actions { text-align: right; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge.warn { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

.ficon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex: none; color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .02em; }
.ficon.folder { background: transparent; color: var(--folder); }
.ficon.folder svg { width: 26px; height: 26px; }
.ficon.pdf { background: var(--pdf); }
.ficon.word { background: var(--word); }
.ficon.excel { background: var(--excel); }
.ficon.other { background: var(--muted); }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- arrastar e soltar ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 3px dashed var(--accent);
  font-size: 18px; font-weight: 600; color: var(--accent);
}

/* ---------- uploads ---------- */
.uploads { position: fixed; right: 20px; bottom: 20px; width: 340px; max-width: calc(100vw - 32px); z-index: 50; }
.upload-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px; margin-top: 8px; }
.upload-item .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---------- modal ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.modal-head { padding: 18px 20px 0; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); }
.modal-body { padding: 8px 20px 4px; overflow: auto; max-height: calc(100vh - 220px); }
.modal-foot { padding: 16px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

.share-list { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; }
.share-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.share-row:last-child { border-bottom: 0; }
.share-row .who { flex: 1; min-width: 0; }
.share-row .who small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.share-row .opts { display: flex; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; white-space: nowrap; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.tree { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; max-height: 320px; overflow: auto; }
.tree button { width: 100%; border: 0; border-radius: 0; justify-content: flex-start; background: transparent; }
.tree button.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree button svg { color: var(--folder); }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- celular ---------- */
.menu-btn { display: none; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .hide-sm { display: none; }
  .col-name { width: auto; }
  th, td { padding: 10px; }
}

/* ---------- compartilhamento por nível ---------- */
.share-row select { width: auto; min-width: 190px; flex: none; }
.help { margin: 12px 0 0; padding-left: 18px; }
.help li { margin: 3px 0; }
@media (max-width: 560px) {
  .share-row { flex-wrap: wrap; }
  .share-row select { width: 100%; }
}

/* ---------- busca e filtros ---------- */
input[type=search], input[type=date], input[type=number] {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.filters { margin-bottom: 12px; }
.filter-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-box {
  flex: 1 1 260px; min-width: 0; margin: 0; font-weight: 400;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted);
}
.search-box:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-box input { border: 0; outline: none; padding: 8px 0; flex: 1; min-width: 0; background: transparent; }
.sort-select { width: auto; flex: none; }
[data-act=toggle-filters].has-filters { border-color: var(--accent); color: var(--accent); }
[data-act=toggle-filters] .count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center;
}
.filter-panel {
  margin-top: 8px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px;
}
.fgroup { min-width: 0; }
.fgroup-wide { grid-column: 1 / -1; }
.fgroup-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.flabel { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 99px; padding: 5px 12px; }
.chip[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.frange { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--muted); }
.frange input { flex: 1; min-width: 0; width: 100%; }
.btn-link { border: 0; background: transparent; color: var(--accent); padding: 4px 6px; }
.btn-link:hover { background: transparent; text-decoration: underline; }
.btn-link:disabled { color: var(--muted); text-decoration: none; }
.results-info { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); margin: 0 2px 8px; }
.results-info:empty { display: none; }
.results-info strong { color: var(--text); }
#listing.loading { opacity: .55; transition: opacity .15s; }

.th-sort { border: 0; background: transparent; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; gap: 4px; }
.th-sort:hover { background: transparent; color: var(--text); }
.th-sort .arrow { color: var(--accent); }
.name-wrap { min-width: 0; display: flex; flex-direction: column; }
.name-line { display: flex; align-items: center; min-width: 0; }
.name-line a { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.loc svg { width: 12px; height: 12px; color: var(--folder); }
.loc a { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
mark { background: color-mix(in srgb, #ffd43b 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
@media (max-width: 900px) { .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .filter-panel { grid-template-columns: 1fr; }
  .sort-select { flex: 1; }
}
