:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --text: #1d2430;
    --muted: #6b7686;
    --line: #e2e6ec;
    --accent: #3d6df2;
    --accent-ink: #ffffff;
    --danger: #d64545;
    --ok-bg: #e6f6ee; --ok-ink: #17623d;
    --err-bg: #fdecec; --err-ink: #9b2222;
    --warn-bg: #fff6e0; --warn-ink: #7a5300;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b; --panel: #1b2029; --text: #e6e9ee; --muted: #8e98a8; --line: #2b323e;
        --accent: #6b8fff; --ok-bg: #133024; --ok-ink: #8fe0b5; --err-bg: #3a1a1a; --err-ink: #ffaaaa;
        --warn-bg: #3a2e10; --warn-ink: #ffd88a; --shadow: none;
    }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.inline { display: inline; margin: 0; }

/* Topo */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: .7rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 1.4rem; text-align: center; margin-bottom: 1rem; }
.logo { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a:not(.btn) { color: var(--muted); font-weight: 500; }
.topbar nav a.on { color: var(--text); }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.foot { text-align: center; padding: 2rem 0; font-size: .8rem; }

/* Botões e formulários */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
label { display: block; font-weight: 500; margin-bottom: .9rem; }
input:not([type=checkbox]):not([type=color]):not([type=file]), select, textarea {
    display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
    background: var(--panel); color: var(--text); font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=color] { width: 42px; height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--panel); }
select.small { display: inline-block; width: auto; padding: .25rem .4rem; margin: 0; font-size: .85rem; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; margin-top: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }

.alert { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert.err { background: var(--err-bg); color: var(--err-ink); }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* Login */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); padding: 2rem; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.auth-card .btn { width: 100%; justify-content: center; }

/* Listagem */
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 1.5rem; }
.side h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .4rem 0 .6rem; }
.catlist { list-style: none; padding: 0; margin: 0 0 1rem; }
.catlist a { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; border-radius: 7px; color: var(--text); }
.catlist a span { margin-left: auto; color: var(--muted); font-size: .8rem; }
.catlist a:hover { background: var(--panel); text-decoration: none; }
.catlist a.on { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.big { width: 14px; height: 14px; }
.muted-dot { background: var(--line); }

.toolbar { display: flex; gap: .5rem; margin-bottom: .75rem; }
.toolbar input[type=search] { margin: 0; flex: 1; }
.toolbar select { margin: 0; width: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: var(--text); transition: transform .12s, box-shadow .12s; }
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(20, 30, 50, .12); }
.thumb { aspect-ratio: 4 / 3; background: color-mix(in srgb, var(--line) 55%, var(--panel)); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.noimg { font-weight: 700; letter-spacing: .1em; color: var(--muted); }
.card-body { padding: .65rem .8rem .8rem; display: flex; flex-direction: column; gap: .15rem; }
.card-body strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: .35rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.pager { display: flex; justify-content: center; gap: 1.5rem; margin: 1.5rem 0; align-items: center; }

/* Ficha do modelo */
.crumbs { color: var(--muted); font-size: .9rem; margin: 0 0 .5rem; }
.detail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 2rem; align-items: start; }
.media { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.media img { width: 100%; border-radius: 8px; display: block; }
.tabs { display: flex; gap: .25rem; margin-bottom: .6rem; }
.tab { border: 0; background: transparent; padding: .4rem .8rem; border-radius: 7px; cursor: pointer; color: var(--muted); font: inherit; }
.tab.on { background: var(--bg); color: var(--text); font-weight: 600; }
.viewer { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--panel) 80%, #fff), var(--bg)); overflow: hidden; }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }
.viewer-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.small-viewer { margin: -.3rem 0 .5rem; }
.viewer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.info h1 { margin-bottom: .2rem; }
.desc { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); color: var(--accent); padding: .15rem .6rem; border-radius: 999px; font-size: .82rem; }
.props { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 1rem 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; word-break: break-word; }

/* Formulário de edição */
.editor .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1rem; background: var(--panel); display: flex; flex-direction: column; gap: .4rem; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.drop-title { font-weight: 600; }
.img-preview img { max-width: 100%; max-height: 260px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Categorias */
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline-form input:not([type=color]) { width: auto; flex: 1 1 180px; margin: 0; }
.card-form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: 1.2rem; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline-flex; gap: .3rem; align-items: center; }

@media (max-width: 860px) {
    .layout, .detail, .editor .cols { grid-template-columns: 1fr; }
    .side { order: 2; }
    .topbar nav { gap: .6rem; }
    .table .muted:nth-child(3) { display: none; }
}
@media (max-width: 520px) {
    .wrap { padding: 1rem; }
    .topbar-inner { padding: .6rem 1rem; }
    .grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
    .toolbar { flex-wrap: wrap; }
    .row2 { grid-template-columns: 1fr; }
}

/* Vários ficheiros por modelo */
h3.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2rem 0 .5rem; }
h3.section:first-child { margin-top: 0; }
.filelist { list-style: none; padding: 0; margin: 0 0 .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.filelist:empty { display: none; }
.filelist li { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; border-bottom: 1px solid var(--line); }
.filelist li:last-child { border-bottom: 0; }
.filelist .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .check { margin: 0; white-space: nowrap; }
.filelist li.removido .fname { text-decoration: line-through; color: var(--muted); }
.filelist li.grande .fname { color: var(--danger); }
.filelist li.total { justify-content: flex-end; }
.filelist.novos { border-style: dashed; }
.badge { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: color-mix(in srgb, var(--accent) 14%, var(--panel)); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: .2rem .7rem; font: inherit; font-size: .82rem; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.progress .bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.btn:disabled { opacity: .55; cursor: wait; }
