/* ==========================================================================
   Procy – app shell (sidebar + topbar) on top of Bootstrap 5.3
   ========================================================================== */

/* ---- Design tokens ------------------------------------------------------ */
:root,
[data-bs-theme="light"] {
    --procy-primary: #5b5bd6;
    --procy-primary-rgb: 91, 91, 214;
    --procy-primary-hover: #4a4ac4;
    --procy-accent: #8b5cf6;
    --procy-gradient: linear-gradient(135deg, #5b5bd6 0%, #8b5cf6 100%);

    --procy-bg: #f4f5fa;
    --procy-surface: #ffffff;
    --procy-surface-rgb: 255, 255, 255;
    --procy-border: #e5e7f0;
    --procy-text: #1a1d2e;
    --procy-muted: #6b7189;
    --procy-shadow: 0 1px 2px rgba(20, 22, 40, .04), 0 4px 16px rgba(20, 22, 40, .06);

    --bs-body-bg: var(--procy-bg);
    --bs-body-color: var(--procy-text);
    --bs-secondary-color: var(--procy-muted);
    --bs-border-color: var(--procy-border);
    --bs-tertiary-bg: #eceef6;
    --bs-primary: var(--procy-primary);
    --bs-primary-rgb: var(--procy-primary-rgb);
    --bs-link-color: var(--procy-primary);
    --bs-link-color-rgb: var(--procy-primary-rgb);
    --bs-link-hover-color: var(--procy-primary-hover);
    --bs-border-radius: .6rem;
    --bs-border-radius-lg: .9rem;
    --bs-focus-ring-color: rgba(var(--procy-primary-rgb), .25);
}

[data-bs-theme="dark"] {
    --procy-primary: #7c7cf0;
    --procy-primary-rgb: 124, 124, 240;
    --procy-primary-hover: #9595f5;
    --procy-accent: #a78bfa;

    --procy-bg: #0c0e18;
    --procy-surface: #141726;
    --procy-surface-rgb: 20, 23, 38;
    --procy-border: #252a3f;
    --procy-text: #e4e6f1;
    --procy-muted: #9197b3;
    --procy-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);

    --bs-body-bg: var(--procy-bg);
    --bs-body-color: var(--procy-text);
    --bs-secondary-color: var(--procy-muted);
    --bs-border-color: var(--procy-border);
    --bs-tertiary-bg: #1a1e31;
    --bs-secondary-bg: #1a1e31;
    --bs-primary: var(--procy-primary);
    --bs-primary-rgb: var(--procy-primary-rgb);
    --bs-link-color: var(--procy-primary);
    --bs-link-color-rgb: var(--procy-primary-rgb);
    --bs-link-hover-color: var(--procy-primary-hover);
    --bs-focus-ring-color: rgba(var(--procy-primary-rgb), .3);
}

/* The sidebar is dark in both themes. */
:root {
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 76px;
    --topbar-h: 64px;

    --sb-bg: #10121f;
    --sb-bg-2: #181a33;
    --sb-text: #c3c7dc;
    --sb-muted: #767c9b;
    --sb-hover: rgba(255, 255, 255, .06);
    --sb-active-bg: linear-gradient(90deg, rgba(124, 124, 240, .28) 0%, rgba(139, 92, 246, .10) 100%);
    --sb-border: rgba(255, 255, 255, .07);
}

/* ---- Base --------------------------------------------------------------- */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--procy-bg);
    -webkit-font-smoothing: antialiased;
}

[v-cloak] { display: none !important; }

/* Bootstrap components on the new palette */
.btn-primary {
    --bs-btn-bg: var(--procy-primary);
    --bs-btn-border-color: var(--procy-primary);
    --bs-btn-hover-bg: var(--procy-primary-hover);
    --bs-btn-hover-border-color: var(--procy-primary-hover);
    --bs-btn-active-bg: var(--procy-primary-hover);
    --bs-btn-active-border-color: var(--procy-primary-hover);
    --bs-btn-disabled-bg: var(--procy-primary);
    --bs-btn-disabled-border-color: var(--procy-primary);
    --bs-btn-focus-shadow-rgb: var(--procy-primary-rgb);
}
.btn-outline-primary {
    --bs-btn-color: var(--procy-primary);
    --bs-btn-border-color: var(--procy-primary);
    --bs-btn-hover-bg: var(--procy-primary);
    --bs-btn-hover-border-color: var(--procy-primary);
    --bs-btn-active-bg: var(--procy-primary);
    --bs-btn-active-border-color: var(--procy-primary);
    --bs-btn-focus-shadow-rgb: var(--procy-primary-rgb);
}
.form-control:focus,
.form-select:focus {
    border-color: rgba(var(--procy-primary-rgb), .6);
    box-shadow: 0 0 0 .25rem rgba(var(--procy-primary-rgb), .18);
}
.form-check-input:checked {
    background-color: var(--procy-primary);
    border-color: var(--procy-primary);
}
.nav-pills {
    --bs-nav-pills-link-active-bg: var(--procy-primary);
}
.card {
    --bs-card-bg: var(--procy-surface);
    --bs-card-border-color: var(--procy-border);
    --bs-card-cap-bg: transparent;
    box-shadow: var(--procy-shadow);
}
.dropdown-menu {
    --bs-dropdown-bg: var(--procy-surface);
    --bs-dropdown-border-color: var(--procy-border);
    --bs-dropdown-link-active-bg: var(--procy-primary);
    --bs-dropdown-item-padding-y: .45rem;
    box-shadow: var(--procy-shadow);
    padding: .4rem;
}
.dropdown-item { border-radius: .45rem; display: flex; align-items: center; gap: .6rem; }

/* ---- Shell layout ------------------------------------------------------- */
.app-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left .25s ease;
}
.app-content {
    flex: 1 1 auto;
    padding: 1.75rem clamp(1rem, 3vw, 2.25rem) 2.5rem;
}

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    color: var(--sb-text);
    background: linear-gradient(180deg, var(--sb-bg) 0%, var(--sb-bg-2) 100%);
    border-right: 1px solid var(--sb-border);
    transition: width .25s ease, transform .25s ease, box-shadow .25s ease;
    overflow: hidden;
}

.sidebar-brand {
    height: var(--topbar-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.1rem;
    border-bottom: 1px solid var(--sb-border);
}
.brand-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .01em;
    white-space: nowrap;
}
.brand-link:hover { color: #fff; }
.brand-mark {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: var(--procy-gradient);
    box-shadow: 0 6px 18px rgba(124, 92, 246, .45);
    font-size: 1.05rem;
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem .85rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .12) transparent;
}

.sidebar-search {
    position: relative;
    margin-bottom: 1rem;
}
.sidebar-search .bi {
    position: absolute;
    left: .8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sb-muted);
    font-size: .85rem;
    pointer-events: none;
}
.sidebar-search input {
    width: 100%;
    padding: .5rem .75rem .5rem 2.1rem;
    border-radius: .6rem;
    border: 1px solid var(--sb-border);
    background: rgba(255, 255, 255, .04);
    color: #fff;
    font-size: .875rem;
    outline: none;
    transition: border-color .15s, background .15s;
}
.sidebar-search input::placeholder { color: var(--sb-muted); }
.sidebar-search input:focus {
    border-color: rgba(124, 124, 240, .6);
    background: rgba(255, 255, 255, .07);
}

.nav-list,
.nav-children ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.nav-entry + .nav-entry { margin-top: .2rem; }

.nav-row {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .6rem .8rem;
    border: 0;
    border-radius: .6rem;
    background: transparent;
    color: var(--sb-text);
    font-size: .925rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.nav-row:hover { background: var(--sb-hover); color: #fff; }
.nav-row:focus-visible { outline: 2px solid rgba(124, 124, 240, .7); outline-offset: 1px; }
.nav-row.active { color: #fff; background: var(--sb-active-bg); }
a.nav-row.active::before {
    content: "";
    position: absolute;
    left: -.85rem;
    top: 20%;
    bottom: 20%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--procy-gradient);
}
.nav-icon {
    flex: 0 0 1.35rem;
    font-size: 1.15rem;
    line-height: 1;
    text-align: center;
}
.nav-row.active .nav-icon { color: #b4b4ff; }
.nav-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity .2s;
}
.nav-chevron {
    font-size: .75rem;
    color: var(--sb-muted);
    transition: transform .25s ease, opacity .2s;
}
.nav-row.open .nav-chevron { transform: rotate(180deg); }

/* Smooth open/close without measuring heights */
.nav-children {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .25s ease;
}
.nav-children.open { grid-template-rows: 1fr; }
.nav-children > ul {
    min-height: 0;
    overflow: hidden;
    margin-left: 1.45rem;
    padding-left: .8rem;
    border-left: 1px solid var(--sb-border);
}
.nav-children > ul > li:first-child { margin-top: .2rem; }
.nav-child {
    padding: .45rem .7rem;
    font-size: .875rem;
    font-weight: 400;
    gap: .6rem;
}
.nav-child .nav-icon { font-size: .95rem; flex-basis: 1.1rem; }
.nav-child.active { background: rgba(124, 124, 240, .18); }

.nav-empty {
    padding: .6rem .8rem;
    color: var(--sb-muted);
    font-size: .85rem;
}

.sidebar-footer {
    flex: 0 0 auto;
    padding: .9rem 1.2rem;
    border-top: 1px solid var(--sb-border);
    color: var(--sb-muted);
    font-size: .75rem;
    white-space: nowrap;
}

/* ---- Collapsed sidebar (desktop): icons only, expands on hover ---------- */
@media (min-width: 992px) {
    html.sidebar-collapsed .app-main { margin-left: var(--sidebar-w-collapsed); }
    html.sidebar-collapsed .sidebar:not(:hover) { width: var(--sidebar-w-collapsed); }
    html.sidebar-collapsed .sidebar:hover { box-shadow: 12px 0 40px rgba(0, 0, 0, .35); }
    html.sidebar-collapsed .sidebar:not(:hover) :is(.nav-label, .nav-chevron, .brand-text, .sidebar-footer span) {
        opacity: 0;
    }
    html.sidebar-collapsed .sidebar:not(:hover) .sidebar-search { visibility: hidden; }
    html.sidebar-collapsed .sidebar:not(:hover) .nav-children { grid-template-rows: 0fr; }
}

/* ---- Mobile: sidebar slides in over the content ------------------------- */
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sidebar { width: 280px; transform: translateX(-100%); }
    html.sidebar-open .sidebar { transform: none; box-shadow: 12px 0 40px rgba(0, 0, 0, .4); }
    .app-main { margin-left: 0; }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1035;
        background: rgba(8, 10, 22, .55);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s ease;
    }
    html.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    html.sidebar-open { overflow: hidden; }
}

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 clamp(1rem, 3vw, 2.25rem);
    background: rgba(var(--procy-surface-rgb), .78);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--procy-border);
}
.topbar-title {
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: .6rem;
    background: transparent;
    color: var(--procy-muted);
    font-size: 1.2rem;
    transition: background .15s, color .15s, border-color .15s;
}
.btn-icon:hover,
.btn-icon[aria-expanded="true"] {
    background: rgba(var(--procy-primary-rgb), .08);
    color: var(--procy-primary);
}
.sidebar .btn-icon { color: var(--sb-muted); }
.sidebar .btn-icon:hover { background: var(--sb-hover); color: #fff; }

.user-chip {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .25rem .6rem .25rem .25rem;
    border: 1px solid var(--procy-border);
    border-radius: 999px;
    background: var(--procy-surface);
    color: var(--procy-text);
    font-size: .875rem;
    font-weight: 500;
    transition: border-color .15s, box-shadow .15s;
}
.user-chip:hover,
.user-chip[aria-expanded="true"] {
    border-color: rgba(var(--procy-primary-rgb), .45);
    box-shadow: 0 0 0 3px rgba(var(--procy-primary-rgb), .12);
}
.user-chip .bi-chevron-down { font-size: .7rem; color: var(--procy-muted); }
.avatar {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--procy-gradient);
    color: #fff;
    font-size: .85rem;
    font-weight: 700;
}
.dropdown-user-info { padding: .5rem .75rem .6rem; }
.dropdown-user-info .small { color: var(--procy-muted); }

/* ---- Page building blocks ----------------------------------------------- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -.01em;
    margin: 0;
}
.page-header p { color: var(--procy-muted); margin: .25rem 0 0; }

.hero-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--bs-border-radius-lg);
    padding: clamp(1.5rem, 4vw, 2.5rem);
    color: #fff;
    background: var(--procy-gradient);
    box-shadow: 0 12px 32px rgba(91, 91, 214, .3);
}
.hero-card::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -60px;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
}
.hero-card h2 { font-weight: 700; margin-bottom: .35rem; }
.hero-card p { opacity: .85; margin: 0; max-width: 40rem; }

.stat-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    height: 100%;
    color: inherit;
    text-decoration: none;
    transition: transform .15s ease, border-color .15s;
}
a.stat-card:hover { transform: translateY(-2px); border-color: rgba(var(--procy-primary-rgb), .45); color: inherit; }
.stat-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: .75rem;
    background: rgba(var(--procy-primary-rgb), .12);
    color: var(--procy-primary);
    font-size: 1.25rem;
}

/* Messages */
.app-messages .alert {
    border: 0;
    border-left: 4px solid currentColor;
    box-shadow: var(--procy-shadow);
}

/* Settings tabs (account pages) */
.settings-tabs {
    gap: .35rem;
    margin-bottom: 1.5rem;
}
.settings-tabs .nav-link { color: var(--procy-muted); font-weight: 500; }
.settings-tabs .nav-link.active { color: #fff; }

/* ---- Entrance (login etc.) ---------------------------------------------- */
.entrance {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(60rem 40rem at 10% -10%, rgba(139, 92, 246, .35), transparent 60%),
        radial-gradient(50rem 35rem at 110% 110%, rgba(91, 91, 214, .35), transparent 60%),
        var(--sb-bg);
}
.entrance-card {
    width: 100%;
    max-width: 440px;
    padding: clamp(1.75rem, 5vw, 2.75rem);
    border-radius: 1.1rem;
    background: var(--procy-surface);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}
.entrance-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .7rem;
    margin-bottom: 1.25rem;
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--procy-text);
}
.entrance-card h1 { font-size: 1.5rem; font-weight: 700; text-align: center; margin-top: 0 !important; }

/* ---- Management (CRUD) pages -------------------------------------------- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .35rem;
    color: var(--procy-muted);
    font-size: .85rem;
    text-decoration: none;
}
.back-link:hover { color: var(--procy-primary); }

.crud-card { overflow: hidden; }
.crud-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--procy-border);
}
.crud-search { position: relative; flex: 1 1 240px; max-width: 360px; }
.crud-search .bi {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--procy-muted);
    pointer-events: none;
}
.crud-search .form-control { padding-left: 2.3rem; }
.crud-filter { width: auto; max-width: 240px; }

.crud-table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(var(--procy-primary-rgb), .045);
}
.crud-table thead th {
    padding: .75rem 1.25rem;
    background: var(--bs-tertiary-bg);
    color: var(--procy-muted);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom-color: var(--procy-border);
}
.crud-table td {
    padding: .7rem 1.25rem;
    border-bottom-color: var(--procy-border);
}
.crud-table tbody tr:last-child td { border-bottom: 0; }
.crud-table tr.is-clickable { cursor: pointer; }
.row-link { color: inherit; font-weight: 500; text-decoration: none; }
.row-link:hover { color: var(--procy-primary); }
.crud-empty {
    padding: 3rem 1rem !important;
    text-align: center;
    color: var(--procy-muted);
}
.crud-empty .bi { display: block; font-size: 2rem; margin-bottom: .5rem; opacity: .6; }
.crud-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--procy-border);
}
.pagination {
    --bs-pagination-color: var(--procy-text);
    --bs-pagination-bg: transparent;
    --bs-pagination-border-color: var(--procy-border);
    --bs-pagination-hover-bg: rgba(var(--procy-primary-rgb), .08);
    --bs-pagination-hover-color: var(--procy-primary);
    --bs-pagination-active-bg: var(--procy-primary);
    --bs-pagination-active-border-color: var(--procy-primary);
    --bs-pagination-disabled-bg: transparent;
    --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(var(--procy-primary-rgb), .2);
}

.tree-child { padding-left: 1.4rem; position: relative; }
.tree-child::before {
    content: "";
    position: absolute;
    left: .35rem;
    top: -.2rem;
    width: .6rem;
    height: .75rem;
    border-left: 1px solid var(--procy-muted);
    border-bottom: 1px solid var(--procy-muted);
    border-bottom-left-radius: 3px;
    opacity: .6;
}

.btn-icon-sm { width: 32px; height: 32px; font-size: 1rem; }
.btn-icon-danger:hover { background: rgba(220, 53, 69, .1); color: #dc3545; }

/* Soft badges */
.badge[class*="badge-soft-"] { font-weight: 600; padding: .35em .65em; border-radius: 999px; }
.badge-soft-primary { background: rgba(var(--procy-primary-rgb), .14); color: var(--procy-primary); }
.badge-soft-secondary { background: rgba(108, 117, 125, .15); color: var(--procy-muted); }
.badge-soft-success { background: rgba(25, 135, 84, .14); color: #198754; }
.badge-soft-info { background: rgba(13, 170, 202, .14); color: #0b8fab; }
.badge-soft-warning { background: rgba(255, 193, 7, .2); color: #a07400; }
.badge-soft-danger { background: rgba(220, 53, 69, .14); color: #dc3545; }
[data-bs-theme="dark"] .badge-soft-success { color: #4fd18b; }
[data-bs-theme="dark"] .badge-soft-info { color: #5fd3eb; }
[data-bs-theme="dark"] .badge-soft-warning { color: #ffd257; }
[data-bs-theme="dark"] .badge-soft-danger { color: #ff7b88; }

/* Forms */
.crud-form { max-width: 880px; }
.crud-form .card-header { padding: .9rem 1.25rem; border-bottom-color: var(--procy-border); }
.crud-form .card-body { padding: 1.25rem; }
.crud-form .form-label { font-weight: 500; font-size: .9rem; }
.crud-form .card-body > :last-child { margin-bottom: 0 !important; }
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
}
.form-switch .form-check-input { cursor: pointer; }

.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .5rem;
}
.choice-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin: 0;
    padding: .6rem .8rem;
    border: 1px solid var(--procy-border);
    border-radius: .55rem;
    background: var(--procy-surface);
    cursor: pointer;
    line-height: 1.3;
    transition: border-color .15s, background .15s;
}
.choice-item:hover { border-color: rgba(var(--procy-primary-rgb), .45); }
.choice-item:has(input:checked) {
    border-color: rgba(var(--procy-primary-rgb), .6);
    background: rgba(var(--procy-primary-rgb), .07);
}
.choice-item .form-check-input { flex: 0 0 auto; margin: 0; }

.icon-preview { min-width: 3rem; justify-content: center; font-size: 1.15rem; color: var(--procy-primary); }

.perm-matrix { border: 1px solid var(--procy-border); border-radius: .6rem; }
.perm-matrix table { --bs-table-bg: transparent; }
.perm-matrix thead th {
    background: var(--bs-tertiary-bg);
    color: var(--procy-muted);
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.perm-matrix td, .perm-matrix th { padding: .5rem .75rem; border-bottom-color: var(--procy-border); }
.perm-matrix tbody tr:last-child td { border-bottom: 0; }
.perm-matrix .form-check-input { cursor: pointer; }

/* Detail + delete confirm */
.detail-list {
    display: grid;
    grid-template-columns: minmax(140px, 220px) 1fr;
}
.detail-list dt, .detail-list dd {
    margin: 0;
    padding: .8rem 1.25rem;
    border-bottom: 1px solid var(--procy-border);
}
.detail-list dt { color: var(--procy-muted); font-weight: 500; font-size: .875rem; }
.detail-list dt:nth-last-of-type(1), .detail-list dd:last-of-type { border-bottom: 0; }
.detail-pre {
    margin: 0;
    padding: .75rem 1rem;
    border-radius: .5rem;
    background: var(--bs-tertiary-bg);
    font-size: .8rem;
    white-space: pre-wrap;
    word-break: break-word;
}
@media (max-width: 575.98px) {
    .detail-list { grid-template-columns: 1fr; }
    .detail-list dt { border-bottom: 0; padding-bottom: 0; }
}

.confirm-card { max-width: 480px; }
.confirm-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(220, 53, 69, .12);
    color: #dc3545;
    font-size: 1.5rem;
}

/* Error pages */
.error-page { max-width: 520px; margin: 4rem auto; text-align: center; }
.error-code {
    font-size: 5rem;
    font-weight: 800;
    line-height: 1;
    background: var(--procy-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Checkboxes need a clearly visible frame on white cards */
.crud-form .form-check-input:not(:checked),
.perm-matrix .form-check-input:not(:checked) {
    border: 1.5px solid rgba(107, 113, 137, .55);
}
.perm-matrix .form-check-input { width: 1.15em; height: 1.15em; }

/* ---- Command palette ---------------------------------------------------- */
.palette-trigger {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    height: 40px;
    padding: 0 .6rem 0 .8rem;
    border: 1px solid var(--procy-border);
    border-radius: .6rem;
    background: var(--procy-surface);
    color: var(--procy-muted);
    font-size: .875rem;
    transition: border-color .15s, box-shadow .15s;
}
.palette-trigger:hover {
    border-color: rgba(var(--procy-primary-rgb), .45);
    box-shadow: 0 0 0 3px rgba(var(--procy-primary-rgb), .1);
    color: var(--procy-text);
}
@media (min-width: 768px) {
    .palette-trigger span { min-width: 7rem; text-align: left; }
}
kbd {
    padding: .1rem .4rem;
    border: 1px solid var(--procy-border);
    border-bottom-width: 2px;
    border-radius: .35rem;
    background: var(--bs-tertiary-bg);
    color: var(--procy-muted);
    font-family: inherit;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}

html.palette-open { overflow: hidden; }
.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh 1rem 1rem;
    background: rgba(10, 12, 24, .45);
    backdrop-filter: blur(4px);
    animation: palette-fade .15s ease-out;
}
.palette {
    width: 100%;
    max-width: 620px;
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    overflow: hidden;
    border: 1px solid var(--procy-border);
    border-radius: 1rem;
    background: var(--procy-surface);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
    animation: palette-pop .18s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes palette-fade { from { opacity: 0; } }
@keyframes palette-pop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }

.palette-search {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--procy-border);
}
.palette-search > .bi { color: var(--procy-primary); font-size: 1.1rem; }
.palette-search input {
    flex: 1 1 auto;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--procy-text);
    font-size: 1.05rem;
}
.palette-results { overflow-y: auto; padding: .4rem; }
.palette-section {
    padding: .7rem .75rem .35rem;
    color: var(--procy-muted);
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.palette-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .55rem .75rem;
    border: 0;
    border-radius: .6rem;
    background: transparent;
    color: var(--procy-text);
    text-align: left;
}
.palette-item.active { background: rgba(var(--procy-primary-rgb), .1); }
.palette-icon {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: .55rem;
    background: var(--bs-tertiary-bg);
    color: var(--procy-muted);
}
.palette-item.active .palette-icon { background: var(--procy-gradient); color: #fff; }
.palette-text { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.palette-title { font-weight: 500; }
.palette-subtitle { color: var(--procy-muted); font-size: .78rem; }
.palette-enter { color: var(--procy-primary); opacity: 0; }
.palette-item.active .palette-enter { opacity: 1; }
.palette-empty { padding: 2.5rem 1rem; text-align: center; color: var(--procy-muted); }
.palette-empty .bi { display: block; font-size: 1.6rem; margin-bottom: .4rem; opacity: .6; }
.palette-footer {
    display: flex;
    gap: 1.2rem;
    padding: .6rem 1.1rem;
    border-top: 1px solid var(--procy-border);
    background: var(--bs-tertiary-bg);
    color: var(--procy-muted);
    font-size: .75rem;
}
.palette-footer kbd { margin-right: .2rem; }
@media (max-width: 575.98px) { .palette-footer { display: none; } }

/* ---- Dashboard ---------------------------------------------------------- */
.hero-hint {
    position: relative;
    z-index: 1;
    margin-top: 1.1rem;
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .4rem;
    padding: .45rem .85rem;
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: .85rem;
}
.hero-hint:hover { background: rgba(255, 255, 255, .22); }
.hero-hint kbd { background: rgba(255, 255, 255, .9); color: #4a4ac4; border-color: transparent; }

.stat-tile { padding: 1.2rem 1.3rem; }
.stat-value { display: block; font-size: 1.65rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat-label { display: block; color: var(--procy-muted); font-size: .82rem; margin-top: .15rem; }
.stat-tile.is-alert .stat-icon { background: rgba(220, 53, 69, .12); color: #dc3545; }
.stat-tile.is-alert .stat-value { color: #dc3545; }

.dash-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .95rem 1.25rem;
    border-bottom-color: var(--procy-border);
}
.dash-empty { padding: 2.5rem 1rem; text-align: center; color: var(--procy-muted); }
.dash-empty .bi { display: block; font-size: 1.8rem; margin-bottom: .4rem; opacity: .6; }

.live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, .6);
    animation: live-pulse 2s infinite;
}
@keyframes live-pulse {
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.job-list { list-style: none; margin: 0; padding: .25rem 0; }
.job-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .8rem 1.25rem;
}
.job-row + .job-row { border-top: 1px solid var(--procy-border); }
.job-main { flex: 1 1 auto; min-width: 0; }
.job-name { font-weight: 600; }
.job-meta { color: var(--procy-muted); font-size: .8rem; margin-bottom: .45rem; }
.job-progress { height: 4px; border-radius: 4px; background: var(--bs-tertiary-bg); overflow: hidden; }
.job-progress span {
    display: block;
    height: 100%;
    border-radius: 4px;
    background: var(--procy-gradient);
    transition: width 1s linear;
}
.job-countdown {
    flex: 0 0 auto;
    min-width: 5.5rem;
    text-align: right;
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--procy-primary);
}
.job-countdown.is-due { color: #d97706; font-size: .95rem; }

.activity-chart { width: 100%; height: 170px; display: block; }
.chart-grid { stroke: var(--procy-border); stroke-dasharray: 3 4; }
.chart-bar { fill: rgba(var(--procy-primary-rgb), .75); }
.chart-bar-error { fill: #ef4444; }
.chart-label { fill: var(--procy-muted); font-size: 11px; }
.chart-legend { display: flex; gap: 1.2rem; margin-top: .6rem; color: var(--procy-muted); font-size: .8rem; }
.legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: .4rem;
    border-radius: 3px;
    background: rgba(var(--procy-primary-rgb), .75);
}
.legend-swatch.is-error { background: #ef4444; }

.activity-feed { list-style: none; margin: 0; padding: .35rem 0; }
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    padding: .65rem 1.25rem;
    color: inherit;
    text-decoration: none;
    transition: background .15s;
}
.activity-item:hover { background: rgba(var(--procy-primary-rgb), .05); color: inherit; }
.activity-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    margin-top: .4rem;
    border-radius: 50%;
    background: var(--procy-muted);
    box-shadow: 0 0 0 4px rgba(108, 117, 125, .12);
}
.activity-dot.is-create { background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .15); }
.activity-dot.is-update { background: var(--procy-primary); box-shadow: 0 0 0 4px rgba(var(--procy-primary-rgb), .15); }
.activity-dot.is-delete { background: #ef4444; box-shadow: 0 0 0 4px rgba(239, 68, 68, .15); }
.activity-dot.is-action { background: #0ea5e9; box-shadow: 0 0 0 4px rgba(14, 165, 233, .15); }
.activity-dot.is-login_failed { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .18); }
.activity-body { display: flex; flex-direction: column; min-width: 0; }
.activity-message { font-size: .9rem; }
.activity-meta { color: var(--procy-muted); font-size: .78rem; }

/* Audit detail: old -> new */
.changes-table { --bs-table-bg: transparent; font-size: .875rem; }
.changes-table th { color: var(--procy-muted); font-weight: 500; }
.changes-table .change-old { color: #dc3545; text-decoration: line-through; text-decoration-color: rgba(220, 53, 69, .45); }
.changes-table .change-new { color: #198754; }
[data-bs-theme="dark"] .changes-table .change-old { color: #ff7b88; }
[data-bs-theme="dark"] .changes-table .change-new { color: #4fd18b; }
