/* ==========================================================================
   InsulaCRM — Modern theme layer
   Loaded after Tabler. Only restyles; no markup changes required.
   Remove the <link> to modern.css in the layouts to revert.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root,
[data-bs-theme="light"] {
    --m-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --m-radius: 14px;
    --m-radius-sm: 10px;
    --m-brand: #4f46e5;
    --m-brand-rgb: 79, 70, 229;
    --m-brand-2: #7c3aed;
    --m-bg: #f6f7fb;
    --m-surface: #ffffff;
    --m-border: #e8eaf1;
    --m-text: #0f172a;
    --m-muted: #64748b;
    --m-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
    --m-shadow-hover: 0 2px 4px rgba(16, 24, 40, .06), 0 12px 28px rgba(16, 24, 40, .09);
    --m-sidebar: #0f1220;
    --m-sidebar-2: #161a2e;

    /* Map onto Tabler / Bootstrap variables */
    --tblr-font-sans-serif: var(--m-font);
    --tblr-body-font-family: var(--m-font);
    --tblr-primary: var(--m-brand);
    --tblr-primary-rgb: var(--m-brand-rgb);
    --tblr-primary-fg: #fff;
    --tblr-primary-darken: #4338ca;
    --tblr-link-color: var(--m-brand);
    --tblr-link-color-rgb: var(--m-brand-rgb);
    --tblr-body-bg: var(--m-bg);
    --tblr-bg-surface: var(--m-surface);
    --tblr-border-color: var(--m-border);
    --tblr-border-radius: var(--m-radius-sm);
    --tblr-border-radius-lg: var(--m-radius);
    --tblr-card-border-radius: var(--m-radius);
    --tblr-body-color: var(--m-text);
    --tblr-secondary: var(--m-muted);
}

[data-bs-theme="dark"] {
    --m-bg: #0b0d17;
    --m-surface: #131729;
    --m-border: #23283f;
    --m-text: #e5e7f0;
    --m-muted: #8a91a8;
    --m-brand: #818cf8;
    --m-brand-rgb: 129, 140, 248;
    --m-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --m-shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 12px 28px rgba(0, 0, 0, .4);
    --tblr-body-bg: var(--m-bg);
    --tblr-bg-surface: var(--m-surface);
    --tblr-bg-surface-secondary: #0f1322;
    --tblr-border-color: var(--m-border);
    --tblr-body-color: var(--m-text);
    --tblr-primary: var(--m-brand);
    --tblr-primary-rgb: var(--m-brand-rgb);
    --tblr-link-color: var(--m-brand);
}

/* ---------- Base ---------- */
body {
    font-family: var(--m-font);
    background: var(--m-bg);
    color: var(--m-text);
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.006em;
}
h1, h2, h3, .h1, .h2, .h3, .page-title {
    letter-spacing: -0.02em;
    font-weight: 650;
}
.text-secondary, .text-muted { color: var(--m-muted) !important; }
::selection { background: rgba(var(--m-brand-rgb), .18); }
* { scrollbar-width: thin; scrollbar-color: rgba(100, 116, 139, .35) transparent; }

/* ---------- Sidebar ---------- */
.navbar-vertical {
    background: linear-gradient(180deg, var(--m-sidebar) 0%, var(--m-sidebar-2) 100%) !important;
    border-right: 1px solid rgba(255, 255, 255, .05);
}
.navbar-vertical .navbar-nav { padding: 0 .75rem; gap: 2px; }
.navbar-vertical .nav-link {
    border-radius: 10px;
    padding: .55rem .8rem !important;
    color: rgba(255, 255, 255, .62) !important;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.navbar-vertical .nav-link:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff !important;
}
.navbar-vertical .nav-item.active > .nav-link,
.navbar-vertical .nav-link.active {
    background: linear-gradient(135deg, rgba(var(--m-brand-rgb), .9), rgba(124, 58, 237, .85));
    color: #fff !important;
    box-shadow: 0 6px 18px rgba(var(--m-brand-rgb), .35);
}
.navbar-vertical .nav-link-icon { opacity: .9; }
.navbar-vertical .nav-link-icon .icon { width: 20px; height: 20px; stroke-width: 1.75; }
.navbar-vertical .dropdown-menu {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding-left: 1.75rem !important;
}
.navbar-vertical .dropdown-item {
    color: rgba(255, 255, 255, .55) !important;
    border-radius: 8px;
    font-size: .8125rem;
}
.navbar-vertical .dropdown-item:hover,
.navbar-vertical .dropdown-item.active {
    background: rgba(255, 255, 255, .06) !important;
    color: #fff !important;
}

/* ---------- Header / page header ---------- */
.page-wrapper > .page-header,
header.navbar {
    background: rgba(255, 255, 255, .72);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--m-border);
    position: sticky;
    top: 0;
    z-index: 1020;
    margin: 0 !important;
    padding-top: 1rem;
    padding-bottom: 1rem;
}
[data-bs-theme="dark"] .page-wrapper > .page-header,
[data-bs-theme="dark"] header.navbar { background: rgba(11, 13, 23, .72); }
.page-pretitle {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: .6875rem;
    font-weight: 600;
    color: var(--m-brand);
}
.page-body { margin-top: 1.5rem; }

/* ---------- Cards ---------- */
.card {
    border: 1px solid var(--m-border);
    border-radius: var(--m-radius);
    box-shadow: var(--m-shadow);
    background: var(--m-surface);
    transition: box-shadow .2s ease, transform .2s ease;
}
.card-link:hover, a.card:hover, .card-hover:hover {
    box-shadow: var(--m-shadow-hover);
    transform: translateY(-2px);
}
.card-header {
    border-bottom: 1px solid var(--m-border);
    background: transparent;
    padding: 1rem 1.25rem;
}
.card-title { font-weight: 600; letter-spacing: -0.01em; }
.card-body { padding: 1.25rem; }
.card-footer { background: transparent; border-top: 1px solid var(--m-border); }
.card-sm .card-body .h1, .card .display-6 { font-weight: 700; letter-spacing: -0.03em; }
.card-status-top, .card-status-start { border-radius: 0; }

/* ---------- Buttons ---------- */
.btn {
    border-radius: 10px;
    font-weight: 550;
    padding: .5rem .95rem;
    box-shadow: none;
    transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(135deg, var(--m-brand), var(--m-brand-2));
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(var(--m-brand-rgb), .3);
}
.btn-primary:hover, .btn-primary:focus {
    background: linear-gradient(135deg, #4338ca, #6d28d9);
    border-color: transparent;
    box-shadow: 0 6px 20px rgba(var(--m-brand-rgb), .4);
}
.btn-outline-secondary, .btn-secondary:not(.bg-secondary), .btn-white, .btn-default {
    background: var(--m-surface);
    border-color: var(--m-border);
    color: var(--m-text);
}
.btn-outline-secondary:hover, .btn-white:hover {
    background: rgba(var(--m-brand-rgb), .06);
    border-color: rgba(var(--m-brand-rgb), .35);
    color: var(--m-brand);
}
.btn-ghost-primary:hover { background: rgba(var(--m-brand-rgb), .08); }
.btn-icon { padding: .5rem; }
.btn-sm { border-radius: 8px; padding: .3rem .65rem; }

/* ---------- Forms ---------- */
.form-control, .form-select, .input-group-text {
    border-radius: 10px;
    border-color: var(--m-border);
    background-color: var(--m-surface);
    padding: .55rem .8rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:hover, .form-select:hover { border-color: #cbd2e1; }
.form-control:focus, .form-select:focus {
    border-color: var(--m-brand);
    box-shadow: 0 0 0 4px rgba(var(--m-brand-rgb), .14);
}
.input-group > .form-control:not(:last-child), .input-group > .form-select:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > :not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.form-label { font-weight: 550; font-size: .8125rem; margin-bottom: .4rem; }
.form-check-input:checked { background-color: var(--m-brand); border-color: var(--m-brand); }
.form-check-input:focus { box-shadow: 0 0 0 4px rgba(var(--m-brand-rgb), .14); }

/* ---------- Tables ---------- */
.table { --tblr-table-border-color: var(--m-border); }
.table thead th, .table > :not(caption) > * > th {
    background: transparent;
    color: var(--m-muted);
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 1px solid var(--m-border);
    padding-top: .8rem;
    padding-bottom: .8rem;
}
.table > tbody > tr { transition: background .12s ease; }
.table-hover > tbody > tr:hover > *, .table > tbody > tr:hover > * {
    --tblr-table-accent-bg: rgba(var(--m-brand-rgb), .035);
    background-color: rgba(var(--m-brand-rgb), .035);
}
.table > :not(caption) > * > * { padding-top: .85rem; padding-bottom: .85rem; }
.card > .table-responsive:last-child .table, .card > .table:last-child { margin-bottom: 0; }

/* ---------- Badges ---------- */
.badge {
    border-radius: 999px;
    font-weight: 600;
    padding: .35em .7em;
    letter-spacing: .01em;
}
.badge[class*="-lt"] { border: 1px solid rgba(0, 0, 0, .04); }

/* ---------- Dropdowns, modals, toasts ---------- */
.dropdown-menu {
    border: 1px solid var(--m-border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(16, 24, 40, .14);
    padding: .4rem;
    animation: m-pop .14s ease-out;
}
.dropdown-item { border-radius: 8px; padding: .5rem .7rem; }
.dropdown-item:hover, .dropdown-item:focus { background: rgba(var(--m-brand-rgb), .07); color: inherit; }
.dropdown-item.active, .dropdown-item:active { background: rgba(var(--m-brand-rgb), .12); color: var(--m-brand); }
.modal-content {
    border: 0;
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(16, 24, 40, .25);
}
.modal-header, .modal-footer { border-color: var(--m-border); }
.modal-backdrop.show { opacity: .4; backdrop-filter: blur(2px); }
.toast { border-radius: 12px; box-shadow: var(--m-shadow-hover); }
@keyframes m-pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Alerts, nav tabs, pagination, misc ---------- */
.alert {
    border-radius: 12px;
    border: 1px solid var(--m-border);
    box-shadow: none;
}
.nav-tabs { border-bottom-color: var(--m-border); gap: .25rem; }
.nav-tabs .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--m-muted); font-weight: 550; }
.nav-tabs .nav-link:hover { color: var(--m-text); border-color: transparent; }
.nav-tabs .nav-link.active { color: var(--m-brand); border-bottom-color: var(--m-brand); background: transparent; }
.nav-pills .nav-link { border-radius: 10px; }
.nav-pills .nav-link.active { background: var(--m-brand); }
.pagination .page-link { border-radius: 8px !important; margin: 0 2px; border: 0; }
.pagination .page-item.active .page-link { background: var(--m-brand); box-shadow: 0 4px 12px rgba(var(--m-brand-rgb), .3); }
.progress { border-radius: 999px; background: rgba(var(--m-brand-rgb), .1); }
.progress-bar { border-radius: 999px; }
.avatar { border-radius: 10px; }
.avatar.rounded-circle, .avatar-rounded { border-radius: 50%; }
.list-group-item { border-color: var(--m-border); }
.empty { padding: 3rem 1rem; }
.empty-icon { color: rgba(var(--m-brand-rgb), .5); }
hr { border-color: var(--m-border); opacity: 1; }
:focus-visible { outline: 2px solid rgba(var(--m-brand-rgb), .6); outline-offset: 2px; }

/* ---------- Auth / installer pages ---------- */
body.m-auth {
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, .18), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(124, 58, 237, .16), transparent 60%),
        var(--m-bg);
    min-height: 100vh;
}
body.m-auth .card {
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(16, 24, 40, .12);
    border: 1px solid rgba(255, 255, 255, .6);
    backdrop-filter: blur(8px);
}
body.m-auth .card-body { padding: 2rem; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
