:root {
    --sidebar-width: 280px;
    --sidebar-bg: var(--tenant-sidebar, #0f172a);
    --sidebar-bg-light: var(--tenant-secondary, #1e293b);
    --sidebar-text: var(--tenant-menu-text, #cbd5e1);
    --sidebar-muted: #94a3b8;
    --sidebar-active: var(--tenant-primary, #14b8a6);
    --sidebar-active-hover: var(--tenant-secondary, #0d9488);
    --body-bg: var(--tenant-body-bg, #f1f5f9);
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-main: var(--tenant-text, #0f172a);
    --text-muted: #64748b;
    --submenu-width: 292px;
}

html,
body {
    height: 100%;
}

    body.app-body {
        margin: 0;
        background: var(--body-bg);
        color: var(--text-main);
        font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

.app-shell {
    min-height: 100vh;
    display: flex;
    overflow: visible;
}

/* SIDEBAR */
.app-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-light) 100%);
    color: var(--sidebar-text);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    overflow: visible;
    z-index: 1040;
}

@media (min-width: 992px) {
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: none !important;
        visibility: visible !important;
    }

    .app-main {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
}

.sidebar-brand {
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-brand {
    color: #ffffff;
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: .2px;
}

.app-brand-with-logo,
.topbar-brand-with-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.tenant-brand-logo {
    width: 38px;
    height: 38px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    padding: 3px;
}

.tenant-topbar-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 8px;
    background: #ffffff;
    padding: 2px;
    border: 1px solid var(--border-color);
}

    .app-brand:hover {
        color: #ffffff;
    }

.offcanvas-header {
    background: var(--sidebar-bg);
}

.offcanvas-body {
    height: 100%;
    overflow: visible;
}

.sidebar-nav {
    padding: 18px 14px 24px 14px;
    overflow: visible;
}

.sidebar-nav-modules {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-module {
    position: relative;
}

.sidebar-module-button {
    width: 100%;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 12px 14px;
    text-align: left;
    font-size: .96rem;
    font-weight: 650;
    transition: background-color .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.sidebar-module-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-module-arrow {
    color: var(--sidebar-muted);
    font-size: .82rem;
    transition: transform .18s ease, color .18s ease;
}

.sidebar-module:hover > .sidebar-module-button,
.sidebar-module:focus-within > .sidebar-module-button {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transform: translateX(2px);
}

.sidebar-module.active > .sidebar-module-button {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.96), rgba(15, 118, 110, 0.96));
    color: #ffffff;
    box-shadow: 0 14px 28px rgba(20, 184, 166, 0.2);
}

.sidebar-module:hover .sidebar-module-arrow,
.sidebar-module:focus-within .sidebar-module-arrow,
.sidebar-module.active .sidebar-module-arrow {
    color: #ffffff;
}

.sidebar-module:hover .sidebar-module-arrow,
.sidebar-module:focus-within .sidebar-module-arrow {
    transform: translateX(2px);
}

.sidebar-submenu {
    position: absolute;
    top: 0;
    left: calc(100% + 12px);
    z-index: 1050;
    width: var(--submenu-width);
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 14px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 22px 48px rgba(15, 23, 42, 0.18);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-8px);
    pointer-events: none;
    transition: opacity .18s ease, visibility .18s ease, transform .18s ease;
}

.sidebar-module:hover > .sidebar-submenu,
.sidebar-module:focus-within > .sidebar-submenu {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
}

.sidebar-submenu-title {
    color: var(--text-muted);
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .08em;
    margin: 2px 4px 10px;
    text-transform: uppercase;
}

.sidebar-submenu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    color: #334155;
    text-decoration: none;
    font-size: .95rem;
    font-weight: 600;
    margin-bottom: 4px;
    transition: all .18s ease-in-out;
}

    .sidebar-submenu-link:hover {
        background: #f1f5f9;
        color: var(--text-main);
        transform: translateX(2px);
    }

    .sidebar-submenu-link.active {
        background: linear-gradient(135deg, var(--sidebar-active), var(--sidebar-active-hover));
        color: #ffffff;
        box-shadow: 0 10px 24px rgba(20, 184, 166, 0.25);
    }

.sidebar-icon {
    width: 22px;
    font-size: 1rem;
    opacity: .95;
}

/* MAIN */
.app-main {
    min-height: 100vh;
    background: var(--body-bg);
}

.app-main-public {
    width: 100%;
    margin-left: 0;
}

.app-topbar {
    min-height: 76px;
    background: var(--tenant-topbar, #ffffff);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 24px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    min-width: 0;
}

.topbar-left {
    gap: 14px;
    justify-self: start;
    max-width: 360px;
}

.topbar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    width: 100%;
    text-align: center;
}

.topbar-right {
    gap: 12px;
    justify-content: flex-end;
    justify-self: end;
    max-width: min(50vw, 760px);
}

.tenant-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: var(--tenant-title, var(--text-main));
    text-decoration: none;
}

.tenant-brand:hover {
    color: var(--tenant-link, var(--sidebar-active-hover));
}

.tenant-logo {
    display: block;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    object-fit: contain;
    border-radius: 12px;
    background: #ffffff;
    padding: 4px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.tenant-name {
    min-width: 0;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.16rem;
    font-weight: 800;
    line-height: 1.1;
}

.topbar-brand {
    color: var(--tenant-title, var(--text-main));
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
}

    .topbar-brand:hover {
        color: var(--tenant-link, var(--sidebar-active-hover));
    }

.topbar-title {
    color: var(--text-muted);
    font-weight: 600;
}

.page-title {
    width: 100%;
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--tenant-title, var(--text-main));
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.15;
}

.tenant-context,
.user-summary {
    text-align: right;
    line-height: 1.2;
}

.tenant-context-name,
.user-summary-name {
    font-weight: 700;
    color: var(--tenant-title, var(--text-main));
}

.topbar-master-actions {
    align-items: center;
    gap: 8px;
}

.topbar-menu-button {
    border-radius: 10px;
    flex: 0 0 auto;
}

.app-content {
    padding: 28px 24px;
}

.app-content-public {
    min-height: 100vh;
}

    /* HEADINGS */
    .app-content h1,
    .app-content h2,
    .app-content h3 {
        color: var(--tenant-title, var(--text-main));
        font-weight: 750;
    }

    .app-content a {
        color: var(--tenant-link, #2563eb);
    }

    .app-content a.btn {
        color: inherit;
    }

    .app-content a.btn-primary,
    .app-content a.btn-success,
    .app-content a.btn-danger {
        color: #ffffff;
    }

    .app-content a.btn-outline-primary {
        color: var(--tenant-button-primary, #0f766e);
    }

    .app-content a.btn-outline-primary:hover {
        color: #ffffff;
    }

/* CARDS */
.card,
.dashboard-card,
.table-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.06);
}

.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    border-radius: 18px 18px 0 0 !important;
    font-weight: 700;
}

/* DASHBOARD CARDS */
.dashboard-card {
    padding: 20px;
    min-height: 104px;
    transition: all .18s ease-in-out;
}

    .dashboard-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 16px 32px rgba(15, 23, 42, 0.08);
    }

.section-panel,
.metric-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.06);
    padding: 20px;
}

.metric-label {
    color: var(--text-muted);
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.metric-value {
    color: var(--text-main);
    font-size: 1.35rem;
    font-weight: 800;
}

.dashboard-chart {
    height: 360px;
    position: relative;
}

.dashboard-chart-compact {
    height: 280px;
}

    .dashboard-card .card-label {
        color: var(--text-muted);
        font-size: .88rem;
        font-weight: 600;
        margin-bottom: 8px;
    }

    .dashboard-card .card-value {
        color: var(--text-main);
        font-size: 1.6rem;
        font-weight: 800;
    }

/* TABLES */
.table {
    margin-bottom: 0;
}

    .table thead th {
        background: #f8fafc;
        color: #0f172a;
        font-size: .86rem;
        text-transform: uppercase;
        letter-spacing: .02em;
        border-bottom: 1px solid var(--border-color);
    }

    .table tbody td {
        vertical-align: middle;
        color: #1e293b;
    }

    .table tbody tr:hover {
        background: #f8fafc;
    }

.table-card {
    overflow: hidden;
}

/* BUTTONS */
.btn {
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
    transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease, border-color .16s ease;
}

    .btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
    }

    .btn:focus-visible {
        box-shadow: 0 0 0 .22rem rgba(20, 184, 166, 0.22);
    }

.btn-outline-secondary {
    color: #334155;
    border-color: #cbd5e1;
}

.btn-primary {
    background: var(--tenant-button-primary, #0f766e);
    border-color: var(--tenant-button-primary, #0f766e);
}

    .btn-primary:hover {
        background: var(--tenant-button-secondary, #115e59);
        border-color: var(--tenant-button-secondary, #115e59);
    }

.btn-outline-primary {
    color: var(--tenant-button-primary, #0f766e);
    border-color: var(--tenant-button-primary, #0f766e);
}

    .btn-outline-primary:hover {
        background: var(--tenant-button-primary, #0f766e);
        border-color: var(--tenant-button-primary, #0f766e);
        color: #ffffff;
    }

.btn-success {
    background: #16a34a;
    border-color: #16a34a;
}

.btn-danger {
    background: #dc2626;
    border-color: #dc2626;
}

.badge {
    border-radius: 999px;
    padding: .45em .7em;
}

.tenant-logo-preview {
    max-width: 220px;
    max-height: 96px;
    object-fit: contain;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    background: #ffffff;
}

.tenant-theme-preview {
    min-height: 220px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 112px 1fr;
    background: #f8fafc;
}

.preview-sidebar {
    background: var(--preview-sidebar);
    color: var(--preview-menu-text);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preview-sidebar span {
    border-radius: 8px;
    padding: 7px 8px;
    font-size: .86rem;
}

.preview-sidebar .active {
    background: var(--preview-primary);
    color: #ffffff;
}

.preview-main {
    color: var(--preview-text);
}

.preview-topbar {
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    background: var(--preview-topbar);
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
}

.preview-card {
    margin: 16px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: #ffffff;
}

.preview-card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.preview-card button {
    border: 0;
    border-radius: 8px;
    background: var(--preview-primary);
    color: #ffffff;
    padding: 7px 12px;
    font-weight: 700;
}

/* AUTH */
body.auth-body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(20, 184, 166, 0.18), transparent 34%),
        linear-gradient(135deg, #f8fafc 0%, #ecfeff 100%);
    color: var(--text-main);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 430px);
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}

.auth-icon {
    width: 64px;
    height: 64px;
    margin-inline: auto;
    border-radius: 20px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.16), rgba(15, 118, 110, 0.22));
    color: #0f766e;
    font-size: 1.75rem;
}

/* MOBILE */
@media (max-width: 991.98px) {
    .app-topbar {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "left right"
            "center center";
        gap: 8px 12px;
        padding: 10px 14px;
    }

    .topbar-left {
        grid-area: left;
        max-width: 100%;
    }

    .topbar-center {
        grid-area: center;
        width: 100%;
    }

    .topbar-right {
        grid-area: right;
    }

    .tenant-logo {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .tenant-name {
        max-width: 42vw;
        font-size: 1.02rem;
    }

    .page-title {
        max-width: 100%;
        font-size: 1.16rem;
    }

    .app-sidebar {
        width: 280px;
        overflow: hidden;
    }

    .app-main {
        width: 100%;
    }

    .app-content {
        padding: 20px 14px;
    }

    .offcanvas-body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-nav {
        padding-top: 14px;
        overflow: visible;
    }

    .sidebar-nav-modules {
        gap: 10px;
    }

    .sidebar-module-button {
        min-height: 50px;
    }

    .sidebar-module-arrow {
        transform: rotate(90deg);
    }

    .sidebar-module:hover .sidebar-module-arrow,
    .sidebar-module:focus-within .sidebar-module-arrow {
        transform: rotate(90deg);
    }

    .sidebar-submenu {
        position: static;
        width: auto;
        max-height: none;
        margin-top: 8px;
        padding: 10px;
        border-color: rgba(255, 255, 255, 0.08);
        border-radius: 16px;
        background: rgba(15, 23, 42, 0.62);
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        pointer-events: auto;
    }

    .sidebar-submenu-title {
        color: var(--sidebar-muted);
    }

    .sidebar-submenu-link {
        color: var(--sidebar-text);
    }

    .sidebar-submenu-link:hover {
        background: rgba(255, 255, 255, 0.08);
        color: #ffffff;
    }
}

@media (max-width: 575.98px) {
    .app-topbar {
        grid-template-columns: 1fr;
        grid-template-areas:
            "left"
            "center"
            "right";
    }

    .topbar-right {
        justify-self: stretch;
        justify-content: flex-end;
    }

    .tenant-name {
        max-width: calc(100vw - 136px);
    }
}
