:root {
  --primary: #2563eb; --primary-dark: #1d4ed8; --accent: #0ea5e9;
  --bg: #f4f6fb; --surface: #fff; --surface-2: #f1f4f9; --text: #1b2430; --muted: #66758a; --border: #dde3ec;
  --danger: #dc2626; --ok: #16a34a; --warn: #d97706; --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 4px 16px rgb(16 24 40 / .06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --bg: #0e131b; --surface: #171e29; --surface-2: #1e2734; --text: #e6ebf2; --muted: #93a1b5; --border: #2a3545; --shadow: 0 1px 2px #0006; }
}
:root[data-theme='dark'] { --bg: #0e131b; --surface: #171e29; --surface-2: #1e2734; --text: #e6ebf2; --muted: #93a1b5; --border: #2a3545; --shadow: 0 1px 2px #0006; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); } .right { margin-left: auto; } .hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: .8rem; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; font-size: 1.1rem; }
.logo { height: 32px; max-width: 160px; object-fit: contain; } .logo.sm { height: 24px; }
.logo-dot { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), var(--accent)); }

button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; gap: .4rem; align-items: center; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); } button.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
button.sm { padding: .25rem .55rem; font-size: .85rem; } button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }

input, select, textarea { font: inherit; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); width: 100%; }
input[type='checkbox'], input[type='radio'] { width: auto; }
input[type='color'] { padding: 2px; height: 38px; width: 70px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .8rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .8rem 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 99px; background: var(--surface-2); font-size: .78rem; border: 1px solid var(--border); }
.pill.ok { color: var(--ok); } .pill.err { color: var(--danger); } .pill.warn { color: var(--warn); }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); min-width: 90px; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.meter.full > i { background: var(--danger); }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; max-width: min(92vw, 380px); }
.toast { background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }

/* login */
.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 55%), var(--bg); }
.login { width: min(440px, 100%); }
.login .brand { justify-content: center; margin-bottom: 1.2rem; font-size: 1.4rem; }
.sep { display: flex; align-items: center; gap: .7rem; color: var(--muted); margin: 1rem 0; font-size: .85rem; }
.sep::before, .sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* front app */
.layout { display: grid; grid-template-columns: 270px 1fr; gap: 1rem; padding: 1rem 1.2rem; max-width: 1280px; margin: 0 auto; }
.sidebar { align-self: start; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.tree ul { list-style: none; margin: 0; padding-left: 1rem; } .tree > ul { padding-left: 0; }
.tree button { width: 100%; justify-content: flex-start; border: 0; background: transparent; padding: .35rem .5rem; }
.tree button.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.tree button.locked { opacity: .55; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.4rem; text-align: center; color: var(--muted); transition: .15s; }
.dropzone.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--primary); }
.uploads { display: grid; gap: .45rem; margin-top: .8rem; }
.upl { display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem; font-size: .88rem; }
.upl .meter { grid-column: 1 / -1; height: 5px; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
.hero { margin-bottom: 1rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* back-office */
.bo { display: grid; grid-template-columns: 210px 1fr; min-height: calc(100vh - 56px); }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: .8rem; display: grid; gap: .2rem; align-content: start; }
.nav button { border: 0; background: transparent; justify-content: flex-start; width: 100%; }
.nav button.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.content { padding: 1.2rem; max-width: 1200px; width: 100%; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat b { display: block; font-size: 1.7rem; }
.modal-bg { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; z-index: 40; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.3rem; width: min(640px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal.wide { width: min(900px, 100%); }
.perm { display: inline-flex; gap: .3rem; } .perm label { display: inline-flex; gap: .2rem; align-items: center; color: var(--text); margin: 0; font-size: .85rem; }
.ck-editor__editable { min-height: 260px; }
.qr { word-break: break-all; font-family: ui-monospace, monospace; background: var(--surface-2); padding: .6rem; border-radius: 8px; }

@media (max-width: 800px) {
  .layout, .bo { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .nav { grid-auto-flow: column; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav button { width: auto; white-space: nowrap; }
  .hide-sm { display: none; }
}

/* tri-state rights selects */
.perm { flex-wrap: wrap; gap: .5rem .9rem; }
.perm label { display: inline-flex; gap: .35rem; align-items: center; }
.perm select { width: auto; padding: .2rem .35rem; font-size: .85rem; }
select[multiple] { padding: .25rem; }

/* rights overview */
.chips { display: inline-flex; gap: .2rem; vertical-align: middle; }
.chip { width: 1.5rem; height: 1.5rem; display: inline-grid; place-items: center; border-radius: 6px; font-size: .78rem; font-weight: 700; border: 1px solid var(--border); cursor: help; }
.chip.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.deny { background: var(--danger); border-color: var(--danger); color: #fff; }
.chip.none { background: var(--surface-2); color: var(--muted); }
.matrix th, .matrix td { padding: .3rem .4rem; text-align: center; white-space: nowrap; }
.matrix td { font-family: ui-monospace, monospace; font-size: .8rem; }
.matrix td.full { background: color-mix(in srgb, var(--ok) 28%, transparent); }
.matrix td.part { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; background: var(--surface); text-align: left; z-index: 1; }
.matrix .vert { writing-mode: vertical-rl; transform: rotate(180deg); max-height: 9rem; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
