:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --surface: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --ok: #16a34a;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    background: #f1f5f9;
    color: var(--text);
    line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.5rem;
    height: 56px;
    background: var(--bg);
    color: #e2e8f0;
}
.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}
.nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex: 1;
}
.nav a {
    color: #cbd5e1;
    text-decoration: none;
    font-size: .95rem;
}
.nav a:hover { color: #fff; }
.nav-spacer { flex: 1; }
.nav-user { color: #94a3b8; font-size: .9rem; }
.nav-logout { margin: 0; }

/* ---------- Content ---------- */
.content {
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

/* ---------- Tiles ---------- */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}
.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: 1.5rem;
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    border-top: 4px solid var(--primary);
    transition: transform .12s ease, box-shadow .12s ease;
    min-height: 130px;
}
a.tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,.12);
}
.tile-icon { font-size: 2rem; line-height: 1; }
.tile-name { font-weight: 600; font-size: 1.1rem; }
.tile-desc { color: var(--muted); font-size: .9rem; }
.tile.disabled {
    opacity: .5;
    filter: grayscale(.8);
    cursor: not-allowed;
}
.tile.disabled .lock { position: absolute; top: .9rem; right: 1rem; font-size: 1rem; }

.empty {
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 12px;
}

/* ---------- Cards / forms ---------- */
.card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
}
.card.narrow { max-width: 460px; margin: 3rem auto; }

.form-group { margin-bottom: 1rem; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select, textarea {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.checkbox label { margin: 0; font-weight: 400; }

.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; align-items: center; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }

.field-validation-error, .validation-summary-errors {
    color: var(--danger);
    font-size: .85rem;
}
.validation-summary-errors ul { margin: .5rem 0; padding-left: 1.2rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: .55rem 1.1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--primary);
    color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #e2e8f0; padding: .35rem .8rem; }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table th, .table td {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
}
.table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.badge {
    display: inline-block;
    padding: .15rem .6rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
}
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-member { background: #dcfce7; color: #15803d; }

.alert {
    padding: .8rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: .92rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: .4rem; }

/* ---------- Permission matrix ---------- */
.perm-row { display: flex; align-items: center; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.perm-row:last-child { border-bottom: none; }
.perm-tile { display: flex; align-items: center; gap: .6rem; flex: 1; }
.perm-tile .tile-icon { font-size: 1.4rem; }
.perm-options { display: flex; gap: 1rem; }
.perm-options label { display: flex; align-items: center; gap: .35rem; font-weight: 400; margin: 0; cursor: pointer; }
.perm-options input { width: auto; }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 6vh auto; }
.login-wrap h1 { text-align: center; }
.login-logo { text-align: center; font-size: 2.5rem; margin-bottom: .5rem; }
