:root {
    --bg: #0f1216; --panel: #1a1f27; --panel2: #222834; --line: #2c3543;
    --text: #e6e9ef; --muted: #8b95a5; --accent: #4f9cff; --danger: # e5484d;
    --danger: #e5484d; --ok: #3fbf7f; --warn: #e2b53e;
    --radius: 10px;
}
* { 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.5rem; } h2 { font-size: 1.15rem; }

.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar .logout { display: flex; align-items: center; gap: .6rem; }
.topbar .who { color: var(--muted); font-size: .9rem; }

.container { max-width: 1000px; margin: 1.5rem auto; padding: 0 1.25rem; }

.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1.1rem 1.25rem; margin: 1rem 0;
}
.card.narrow { max-width: 520px; margin: 3rem auto; }
.card.danger { border-color: #5a2a2c; }
.cards { display: flex; gap: 1rem; flex-wrap: wrap; }
.card.stat { text-align: center; min-width: 180px; }
.stat-num { display: block; font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.prewrap { white-space: pre-wrap; }
.row { display: flex; gap: .75rem; align-items: center; margin-top: .75rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
table.grid th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }

dl.detail { display: grid; grid-template-columns: 160px 1fr; gap: .4rem 1rem; margin: 0; }
dl.detail dt { color: var(--muted); }

label { display: block; margin: .6rem 0; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; margin: .2rem .8rem .2rem 0; }
input[type=text], input[type=number], input[type=file], select, textarea {
    width: 100%; padding: .5rem .6rem; background: var(--panel2); color: var(--text);
    border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
label.inline input { width: auto; }
textarea { min-height: 90px; resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: .8rem 0; padding: .6rem .8rem; }
.perm-grid { columns: 2; }
.stack > * { margin-bottom: .4rem; }
.filters { display: flex; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

button, .btn, .btn-primary, .btn-danger {
    display: inline-block; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line);
    background: var(--panel2); color: var(--text); cursor: pointer; font: inherit;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04122b; font-weight: 600; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-link { background: none; border: none; color: var(--accent); padding: .3rem; }
.danger-link { color: var(--danger); }

.tag, .status {
    display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem;
    background: var(--panel2); border: 1px solid var(--line);
}
.tag-grid { color: #ff9d5c; } .tag-estate { color: #7cc4ff; } .tag-parcel { color: #9fe0a0; }
.status-active, .status-enforced, .status-partially_enforced { color: var(--ok); }
.status-revoked, .status-failed, .status-expired { color: var(--danger); }
.status-draft, .status-pending { color: var(--warn); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin: .6rem 0; }
.flash-success { background: #143224; border: 1px solid #1f6b45; }
.flash-error { background: #3a1c1e; border: 1px solid #7a2f33; }

.gallery { display: flex; gap: .8rem; flex-wrap: wrap; }
.gallery img { max-width: 180px; max-height: 180px; border-radius: 8px; border: 1px solid var(--line); }
.gallery figure { margin: 0; text-align: center; }

/* --- admin area --------------------------------------------------------- */
.subnav {
    display: flex; gap: 1rem; flex-wrap: wrap;
    margin: 0 0 1.25rem; padding: .1rem 0 .6rem; border-bottom: 1px solid var(--line);
}
.subnav a { color: var(--muted); padding: .2rem 0; border-bottom: 2px solid transparent; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--text); border-bottom-color: var(--accent); }

a.card.stat { color: inherit; }
a.card.stat:hover { border-color: var(--accent); text-decoration: none; }

.table-scroll { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.cell-center { text-align: center; }
.j-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ua-cell { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table.matrix th, table.matrix td { white-space: nowrap; }

.perm-cols { columns: 2; }
.perm-cols .perm-group { break-inside: avoid; margin-bottom: .6rem; }
.perm-cols .perm-group strong { display: block; text-transform: uppercase; font-size: .72rem; letter-spacing: .04em; margin-bottom: .2rem; }
.perm-cols .perm-group label.inline { display: flex; margin: .1rem 0; }

.scope-row { margin-bottom: .3rem; }
.scope-row .scope-type { width: auto; min-width: 6rem; }
.scope-row .scope-id { width: auto; min-width: 12rem; max-width: 100%; }

/* --- sidebar shell ------------------------------------------------------- */
.app-shell { display: flex; align-items: stretch; min-height: 100vh; }
.nav-cb { display: none; }

.sidebar {
    flex: 0 0 240px; width: 240px;
    background: var(--panel); border-right: 1px solid var(--line);
    padding: 1rem .9rem 1.5rem;
    position: sticky; top: 0; align-self: flex-start;
    height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: .4rem;
}
.sidebar .brand { font-weight: 700; font-size: 1.15rem; padding: .2rem .4rem .6rem; }

.side-user {
    display: flex; flex-direction: column; gap: .1rem;
    padding: .5rem .55rem; margin-bottom: .5rem;
    background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
}
.side-user .su-label { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.side-user .su-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.side-user .su-role { color: var(--muted); font-size: .8rem; }

.side-nav ul { list-style: none; margin: 0 0 .5rem; padding: 0; }
.side-group {
    color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    margin: .7rem .55rem .25rem;
}
.side-nav li a {
    display: block; padding: .5rem .6rem; border-radius: 8px;
    color: var(--text); border-left: 3px solid transparent;
}
.side-nav li a:hover { background: var(--panel2); text-decoration: none; }
.side-nav li a.active {
    background: var(--panel2); border-left-color: var(--accent); color: #fff; font-weight: 600;
}
.side-logout { margin: .1rem 0; }
.side-logout button {
    width: 100%; text-align: left; background: none; border: 1px solid var(--line);
    color: var(--danger); padding: .5rem .6rem; border-radius: 8px;
}
.side-logout button:hover { background: #3a1c1e; }

.content { flex: 1 1 auto; min-width: 0; max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.5rem 3rem; width: 100%; }

.mobilebar { display: none; }

/* --- responsive: collapse the sidebar under a hamburger ------------------ */
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .mobilebar {
        display: flex; align-items: center; gap: .8rem;
        padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
        position: sticky; top: 0; z-index: 20;
    }
    .mobilebar .brand { font-weight: 700; }
    .hamburger {
        cursor: pointer; font-size: 1.3rem; line-height: 1;
        padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2);
    }
    .sidebar {
        display: none; position: static; height: auto; width: auto; flex-basis: auto;
        border-right: none; border-bottom: 1px solid var(--line);
    }
    .sidebar .brand { display: none; }
    .nav-cb:checked ~ .sidebar { display: flex; }
    .content { padding: 1rem 1rem 2.5rem; max-width: none; }
}

/* Field-level validation errors (settings form). The message sits under its own
   input, and the input is outlined — a rejected value must be findable without
   reading the whole form. */
.error { color: var(--danger); }
input[aria-invalid="true"] { border-color: var(--danger); }
