:root {
  --bg: #f4f3f0;
  --surface: #ffffff;
  --surface-2: #f9f8f6;
  --border: #e4e1db;
  --text: #1d1c1a;
  --muted: #6d6a64;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee4;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --ok: #2b8a3e;
  --ok-soft: #e9f6ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --viewer-bg: #e9e7e2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --surface: #1e1e1e;
    --surface-2: #252525;
    --border: #333230;
    --text: #ecebe8;
    --muted: #9b978f;
    --accent: #ff7a2e;
    --accent-ink: #1a1007;
    --accent-soft: #3a2316;
    --danger: #ff6b6b;
    --danger-soft: #3a1b1b;
    --ok: #69db7c;
    --ok-soft: #17301d;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --viewer-bg: #222220;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

/* ── topo ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; height: 58px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand small { font-weight: 500; color: var(--muted); }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav a, .nav button.link {
  text-decoration: none; padding: 7px 11px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: .92rem;
  background: none; border: 0; cursor: pointer; font-family: inherit;
}
.nav a:hover, .nav button.link:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { color: var(--text); background: var(--surface-2); }
.nav form { margin: 0; }
.btn.menu-toggle { display: none; }

main.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 60px; }

/* ── botões / form ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .9rem;
  text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 25%, var(--border)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; flex: none; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 5px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > .grow { flex: 1 1 220px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .pad { padding: 20px; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ── login ── */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at top, var(--accent-soft), var(--bg) 60%); }
.login-box { width: 100%; max-width: 380px; }
.login-box .brand { justify-content: center; margin-bottom: 22px; font-size: 1.15rem; }
.login-box .brand .logo { width: 38px; height: 38px; }

/* ── biblioteca ── */
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 24px; }
.sidebar .card { padding: 10px; position: sticky; top: 78px; }
.sidebar h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 10px 6px; }
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list a { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px; text-decoration: none; font-size: .92rem; }
.cat-list a:hover { background: var(--surface-2); }
.cat-list a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-list .n { color: var(--muted); font-size: .8rem; }
.stats { display: flex; gap: 6px 14px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; padding: 4px 10px 8px; }
.stats b { color: var(--text); }

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 260px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; font-size: .85rem; font-weight: 500; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.tile { text-decoration: none; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s, border-color .15s; }
.tile:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.thumb { aspect-ratio: 4 / 3; background: var(--viewer-bg); display: grid; place-items: center; overflow: hidden; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .ph { color: var(--muted); opacity: .55; }
.thumb .ph svg { width: 54px; height: 54px; }
.badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.badge { font-size: .68rem; font-weight: 700; letter-spacing: .04em; padding: 2px 7px; border-radius: 5px; background: rgba(0,0,0,.62); color: #fff; }
.tile .info { padding: 11px 13px 13px; display: flex; flex-direction: column; gap: 3px; }
.tile .info strong { font-size: .95rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .meta { color: var(--muted); font-size: .8rem; }
.tag { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty svg { width: 64px; height: 64px; opacity: .4; margin: 0 auto 12px; }

.pager { display: flex; justify-content: center; gap: 6px; margin-top: 26px; }

/* ── detalhe ── */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.viewer-card { overflow: hidden; }
.viewer { position: relative; aspect-ratio: 4 / 3; background: var(--viewer-bg); }
.viewer canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.viewer .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 500; pointer-events: none; text-align: center; padding: 20px; }
.viewer .dims { position: absolute; left: 12px; bottom: 10px; font-size: .78rem; color: var(--muted); background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 4px 8px; border-radius: 6px; }
.viewer:fullscreen { aspect-ratio: auto; }
.viewer-tools { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.viewer-tools .sep { flex: 1; }
.viewer-tools input[type=color] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 7px; background: none; cursor: pointer; }

.side > .card + .card { margin-top: 16px; }
.side h2 { font-size: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .88rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.desc { white-space: pre-wrap; margin: 12px 0 0; font-size: .92rem; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--border); }
.file-list li:first-child { border-top: 0; }
.file-list li.on .fname { color: var(--accent); }
.file-list .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: .9rem; text-decoration: none; }
.file-list .fsize { color: var(--muted); font-size: .78rem; white-space: nowrap; }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery a, .gallery .ph-item { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--viewer-bg); display: block; position: relative; }
.gallery img { width: 100%; height: 100%; object-fit: cover; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; place-items: center; z-index: 50; padding: 20px; cursor: zoom-out; }
.lightbox.open { display: grid; }
.lightbox img { max-height: 92vh; max-width: 92vw; border-radius: 8px; }

.file-list .fthumb { width: 54px; height: 42px; flex: none; border-radius: 6px; overflow: hidden; background: var(--viewer-bg); display: grid; place-items: center; color: var(--muted); position: relative; }
.file-list .fthumb img { width: 100%; height: 100%; object-fit: cover; }
.file-list .fthumb .badge { position: absolute; left: 2px; bottom: 2px; top: auto; font-size: .58rem; padding: 1px 4px; }
.file-list li.on .fthumb { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── envio em massa ── */
.bulk-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
.bulk-grid .sticky { position: sticky; top: 78px; }
.queue { list-style: none; margin: 0; padding: 0; }
.queue li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); }
.queue li:first-child { border-top: 0; }
.queue .qthumb { width: 64px; height: 48px; border-radius: 6px; background: var(--viewer-bg); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.queue .qthumb img { width: 100%; height: 100%; object-fit: cover; }
.queue .qname { min-width: 0; }
.queue .qname strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.queue .qname span { font-size: .8rem; color: var(--muted); }
.queue .qbar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.queue .qbar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue .qstatus { font-size: .8rem; font-weight: 600; white-space: nowrap; color: var(--muted); }
.queue .ok { color: var(--ok); } .queue .err { color: var(--danger); } .queue .skip { color: var(--muted); }
.queue .qx { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 0 4px; }
.summary { display: flex; gap: 16px; flex-wrap: wrap; font-size: .88rem; color: var(--muted); }
.summary b { color: var(--text); }
@media (max-width: 900px) { .bulk-grid { grid-template-columns: 1fr; } .bulk-grid .sticky { position: static; } }

/* ── form modelo ── */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.drop .t { font-weight: 600; }
.picked { list-style: none; padding: 0; margin: 10px 0 0; font-size: .85rem; text-align: left; }
.picked li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px solid var(--border); }
.picked li:first-child { border-top: 0; }
.edit-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.edit-photos .ph-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--viewer-bg); }
.edit-photos img { width: 100%; height: 100%; object-fit: cover; }
.edit-photos .acts { position: absolute; inset: auto 4px 4px 4px; display: flex; gap: 4px; justify-content: flex-end; }
.edit-photos .acts form { margin: 0; }
.edit-photos .acts .btn { padding: 3px 7px; font-size: .72rem; background: rgba(0,0,0,.65); color: #fff; border-color: transparent; }
.cover-flag { position: absolute; top: 5px; left: 5px; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 12px; display: none; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ── tabelas admin ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
thead th { border-top: 0; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td form { margin: 0; }
.pill { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.pill.user { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
details.edit summary { list-style: none; cursor: pointer; }
details.edit summary::-webkit-details-marker { display: none; }
details.edit[open] { grid-column: 1 / -1; }
.edit-box { margin-top: 10px; padding: 14px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.check { display: flex; align-items: center; gap: 7px; font-weight: 500; }

/* ── responsivo ── */
@media (max-width: 900px) {
  .layout, .detail, .form-grid { grid-template-columns: 1fr; }
  .sidebar .card { position: static; }
  .sidebar .card { padding: 8px; }
  .sidebar h3 { display: none; }
  .cat-list { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .cat-list a { white-space: nowrap; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; }
  .cat-list a.on { border-color: var(--accent); }
}
@media (max-width: 1080px) {
  .btn.menu-toggle { display: inline-flex; margin-left: auto; }
  .nav { display: none; position: absolute; top: 58px; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px 12px; box-shadow: var(--shadow); }
  .nav.open { display: flex; }
  .nav a, .nav button.link { padding: 10px; text-align: left; width: 100%; }
}
@media (max-width: 680px) {
  .brand small { display: none; }
  h1 { font-size: 1.35rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}
