/**
 * Master Dealer — layout base e design tokens (§25.10)
 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #8B7355;
    --secondary-color: #C4A882;
    --accent-gradient: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    --bg-page: #F7F5F2;
    --bg-card: #FFFFFF;
    --bg-input: #F5F0EB;
    --bg-sidebar: #FFFFFF;
    --bg-sidebar-brand: #E8E3DD;
    --text-primary: #2D3748;
    --text-muted: #718096;
    --border-color: #E2E8F0;
    --success-color: #059669;
    --danger-color: #DC2626;
    --warning-color: #D97706;
    --radius-sm: 8px;
    --radius-md: 12px;
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);
    --sidebar-width: 260px;
    --header-height: 64px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--bg-page);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.hidden {
    display: none !important;
}

/* ─── Layout autenticado (§25.16) ─── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    height: calc(var(--header-height) + 0.25rem + 10px);
    min-height: calc(var(--header-height) + 0.25rem + 10px);
    padding: 0.2rem 0.4rem 0.25rem;
    background: var(--bg-sidebar-brand);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
}

.brand-logo-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0;
    line-height: 0;
    text-decoration: none;
    transition: opacity 0.15s;
}

.brand-logo-link:hover {
    opacity: 0.92;
    text-decoration: none;
}

.brand-logo-img {
    display: block;
    width: 100%;
    height: auto;
    max-height: calc(var(--header-height) + 2.40rem + 7px);
    margin: 0;
    object-fit: contain;
    object-position: center;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.65rem 1rem;
}

.menu-module {
    margin-bottom: 0;
}

.menu-module + .menu-module {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.menu-module-toggle,
.menu-submodule-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.menu-module-toggle:hover,
.menu-submodule-toggle:hover {
    background: var(--bg-input);
}

.menu-module-toggle {
    padding: 0.55rem 0.75rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--primary-color);
    background: rgba(139, 115, 85, 0.1);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
}

.menu-module-icon {
    font-size: 0.95rem;
    opacity: 0.9;
    flex-shrink: 0;
}

.menu-module-content {
    margin-left: 0.5rem;
    padding-left: 0.65rem;
    border-left: 2px solid rgba(139, 115, 85, 0.22);
}

.menu-submodule-toggle {
    padding: 0.38rem 0.5rem 0.38rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    margin-top: 0.15rem;
}

.menu-chevron {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    opacity: 0.6;
}

.menu-chevron-end {
    margin-left: auto;
}

.menu-module.is-collapsed > .menu-module-toggle .menu-chevron,
.menu-submodule.is-collapsed > .menu-submodule-toggle .menu-chevron {
    transform: rotate(-90deg);
}

.menu-module.is-collapsed > .menu-module-content,
.menu-submodule.is-collapsed > .menu-submodule-content {
    display: none;
}

.menu-module-label,
.menu-submodule-label {
    flex: 1;
    min-width: 0;
}

.menu-submodule {
    margin-bottom: 0.25rem;
}

.menu-submodule-content {
    padding-left: 0.35rem;
    margin-bottom: 0.35rem;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.48rem 0.65rem 0.48rem 0.75rem;
    margin-left: 0.15rem;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    transition: background 0.15s, border-color 0.15s;
}

.menu-link:hover {
    background: var(--bg-input);
    text-decoration: none;
}

.menu-link.active {
    background: var(--bg-input);
    border-left-color: var(--primary-color);
    color: var(--primary-color);
}

.menu-link i {
    font-size: 1rem;
    opacity: 0.9;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
}

.menu-link-label {
    flex: 1;
    min-width: 0;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-logout:hover {
    background: var(--bg-input);
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

.app-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left .page-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

.header-user-info {
    text-align: right;
}

.header-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0;
}

.header-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.header-notifications {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.35rem;
}

.app-content {
    flex: 1;
    padding: 1.5rem;
}

/* Dashboard */
.dashboard-welcome {
    margin-bottom: 1.5rem;
}

.dashboard-welcome h2 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
}

.dashboard-welcome p {
    margin: 0;
    color: var(--text-muted);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
}

.kpi-card .kpi-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.kpi-card .kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.kpi-card .kpi-icon {
    float: right;
    font-size: 1.5rem;
    color: var(--secondary-color);
    opacity: 0.6;
}

.screen-header {
    margin-bottom: 1.25rem;
}

.screen-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

/* ─── Menu toggle (desktop + mobile §25.19) ─── */
.btn-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.35rem;
    cursor: pointer;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 90;
}

.header-left {
    display: flex;
    align-items: center;
    min-width: 0;
}

.header-user-info {
    display: block;
}

@media (min-width: 1025px) {
    body.sidebar-collapsed .app-sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-collapsed .app-main {
        margin-left: 0;
    }
}

@media (max-width: 1024px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    .app-main {
        margin-left: 0;
    }

    .header-user-info {
        display: none;
    }
}

@media (max-width: 768px) {
    .app-content {
        padding: 1rem;
    }

    .app-header {
        padding: 0 1rem;
    }

    .header-left .page-title {
        font-size: 1.05rem;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .header-notifications {
        display: none;
    }

    .app-content {
        padding: 0.75rem;
    }
}
