:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-muted: #edf1f5;
    --text: #0f172a;
    --muted: #687587;
    --line: #d8dee6;
    --primary: #234e9d;
    --primary-dark: #18376f;
    --accent-red: #c6152f;
    --accent-gold: #eea927;
    --black: #000000;
    --white: #ffffff;
    --success: #234e9d;
    --danger: #c6152f;
    --shadow: 0 12px 28px rgba(28, 39, 51, 0.08);
    --viewport-height: 100vh;
    --viewport-width: 100vw;
    --page-padding: clamp(16px, 2.4vw, 34px);
    --control-height: clamp(42px, 5.2vh, 48px);
    --login-logo-width: clamp(230px, 28vw, 360px);
    --login-panel-width: clamp(360px, 34vw, 500px);
}

* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

body {
    margin: 0;
    font-family: "Montserrat", Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        linear-gradient(135deg, rgba(35, 78, 157, 0.05), rgba(238, 169, 39, 0.04)),
        var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    display: flex;
    min-height: var(--viewport-height);
}

.sidebar {
    width: clamp(244px, 19vw, 292px);
    flex: 0 0 clamp(244px, 19vw, 292px);
    background: linear-gradient(180deg, #ffffff 0%, #f7f9fd 100%);
    color: var(--text);
    padding: clamp(18px, 2vw, 28px) clamp(14px, 1.5vw, 20px);
    border-right: 1px solid var(--line);
    box-shadow: 8px 0 24px rgba(35, 78, 157, 0.06);
}

.sidebar-backdrop,
.sidebar-close,
.menu-toggle {
    display: none;
}

.brand {
    display: grid;
    gap: 10px;
    font-weight: 700;
    margin-bottom: 28px;
    padding: 10px 10px 18px;
    border-bottom: 1px solid var(--line);
    color: var(--primary);
}

.brand-logo {
    display: block;
    width: min(190px, 100%);
    height: auto;
    margin: 0 auto;
    object-fit: contain;
}

.brand span {
    display: block;
    text-align: center;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    height: 42px;
    padding: 0 8px;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 700;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.sidebar-nav a {
    padding: 12px 14px;
    border-radius: 8px;
    color: #334155;
    font-size: 14px;
    border: 1px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(35, 78, 157, 0.09);
    border-color: rgba(35, 78, 157, 0.18);
    color: var(--primary);
    font-weight: 700;
}

.main {
    flex: 1;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: clamp(18px, 2vw, 26px) var(--page-padding);
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-bottom: 1px solid var(--line);
    color: var(--white);
}

.topbar-title {
    min-width: 0;
    flex: 1;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(21px, 2vw, 28px);
}

.eyebrow {
    margin: 0 0 4px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.88);
    font-size: 14px;
}

.role-badge {
    padding: 5px 8px;
    border-radius: 6px;
    background: rgba(238, 169, 39, 0.18);
    color: var(--white);
    border: 1px solid rgba(238, 169, 39, 0.4);
    font-size: 12px;
    text-transform: uppercase;
}

.content {
    padding: var(--page-padding);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.metric-card,
.panel,
.login-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric-card {
    position: relative;
    padding: 18px;
    overflow: hidden;
}

.metric-card::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    content: "";
    background: var(--primary);
}

.metric-card:nth-child(2)::before {
    background: var(--accent-red);
}

.metric-card:nth-child(3)::before {
    background: var(--accent-gold);
}

.metric-card:nth-child(4)::before {
    background: var(--black);
}

.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.metric-card strong {
    font-size: clamp(26px, 2.6vw, 36px);
    color: var(--primary);
}

.panel {
    padding: 22px;
    border-top: 4px solid var(--primary);
}

.dashboard-brand-panel {
    background:
        linear-gradient(135deg, rgba(35, 78, 157, 0.04), rgba(238, 169, 39, 0.05)),
        var(--surface);
}

.dashboard-brand-panel .panel-header {
    display: flex;
    align-items: center;
    gap: 18px;
}

.dashboard-brand-logo {
    width: clamp(150px, 18vw, 260px);
    height: auto;
    object-fit: contain;
}

.panel-header h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.panel-header p {
    margin: 0;
    color: var(--muted);
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 18px;
}

.module-grid span {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    font-size: 14px;
    border-left: 4px solid var(--primary);
    font-weight: 600;
}

.module-grid span:nth-child(2),
.module-grid span:nth-child(5) {
    border-left-color: var(--accent-red);
}

.module-grid span:nth-child(3),
.module-grid span:nth-child(6) {
    border-left-color: var(--accent-gold);
}

.guest-body {
    position: relative;
    min-height: var(--viewport-height);
    display: grid;
    place-items: center;
    padding: clamp(14px, 2.4vh, 28px);
    overflow: auto;
    background:
        linear-gradient(135deg, rgba(244, 246, 248, 0.96), rgba(228, 234, 241, 0.96)),
        #f4f6f8;
}

.guest-body::before {
    position: fixed;
    inset: 0;
    z-index: 0;
    content: "";
    background: url("../img/logo-comercializadora.png") center / min(660px, 82vw) no-repeat;
    opacity: 0.07;
    pointer-events: none;
}

.guest-shell {
    position: relative;
    z-index: 1;
    width: min(100%, var(--login-panel-width));
}

.login-panel {
    padding: clamp(22px, 3vw, 34px);
}

.login-panel-refined {
    padding: clamp(24px, 3.1vw, 38px);
    border-color: rgba(216, 222, 230, 0.9);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
}

.login-heading {
    text-align: center;
    margin-bottom: clamp(18px, 2.4vh, 24px);
}

.login-logo {
    display: block;
    width: min(var(--login-logo-width), 88%);
    height: auto;
    margin: 0 auto clamp(18px, 2.6vh, 26px);
}

.login-heading h1 {
    margin: 0 0 10px;
    font-size: clamp(22px, 2.2vw, 28px);
    font-weight: 800;
    letter-spacing: 0;
}

.login-heading p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
    text-align: center;
    font-size: clamp(13px, 1.2vw, 15px);
}

.form {
    display: grid;
    gap: clamp(12px, 1.8vh, 15px);
}

.form label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.form .checkbox-field {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.form input {
    width: 100%;
    min-height: var(--control-height);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

.form .checkbox-field input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.form input:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(31, 95, 139, 0.15);
}

.password-control {
    position: relative;
    display: block;
}

.password-control input {
    padding-right: 90px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    min-width: 68px;
    min-height: 32px;
    padding: 5px 9px;
    transform: translateY(-50%);
    border: 0;
    border-radius: 6px;
    background: rgba(35, 78, 157, 0.1);
    color: var(--primary);
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.login-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.forgot-password-link {
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
}

.forgot-password-link:hover {
    text-decoration: underline;
}

.recovery-destination {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
    text-align: center;
}

.recovery-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.recovery-link[aria-disabled="true"] {
    color: var(--muted);
    opacity: 0.55;
    cursor: not-allowed;
}

.recovery-link[aria-disabled="false"]:hover {
    border-color: var(--primary);
    background: rgba(31, 95, 139, 0.08);
}

.button {
    border: 0;
    border-radius: 8px;
    min-height: var(--control-height);
    padding: 11px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-ghost {
    background: rgba(255, 255, 255, 0.12);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.28);
}

.button-ghost:hover {
    background: rgba(255, 255, 255, 0.2);
}

.alert {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: #fbecec;
    color: var(--danger);
    border: 1px solid #efc4c4;
}

.alert-success {
    background: #e8f5ee;
    color: #17643e;
    border: 1px solid #b9ddc9;
}

.access-restricted-panel {
    text-align: center;
}

.access-restricted-mark {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: #fff0ca;
    color: #8a5a00;
    font-size: 28px;
    font-weight: 800;
}

.access-restricted-actions {
    display: grid;
    gap: 10px;
}

.access-restricted-actions form,
.access-restricted-actions .button {
    width: 100%;
}

.access-secondary-button {
    border: 1px solid var(--primary);
    color: var(--primary);
    background: #fff;
}

.quote-workspace {
    width: 100%;
}

.quote-tool-frame {
    display: block;
    width: 100%;
    min-height: calc(var(--viewport-height) - 138px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
}

@media (max-width: 980px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        flex-basis: auto;
        padding: 18px;
    }

    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric-grid,
    .module-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-brand-panel .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 1180px) {
    .is-tablet-ui .app-shell {
        display: block;
    }

    .is-tablet-ui .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 120;
        width: min(360px, 88vw);
        padding: 18px;
        overflow-y: auto;
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: 18px 0 42px rgba(15, 23, 42, .24);
    }

    .is-tablet-ui body.sidebar-open {
        overflow: hidden;
    }

    .is-tablet-ui body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .is-tablet-ui .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 110;
        background: rgba(8, 18, 35, .52);
    }

    .is-tablet-ui body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .is-tablet-ui .sidebar-close {
        display: block;
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 2;
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 9px;
        background: #eef3fb;
        color: var(--primary);
        font-size: 28px;
        cursor: pointer;
    }

    .is-tablet-ui .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 96px;
        min-height: 48px;
        padding: 10px 14px;
        border: 1px solid rgba(255,255,255,.34);
        border-radius: 9px;
        background: rgba(255,255,255,.14);
        color: #fff;
        font: inherit;
        font-weight: 800;
        cursor: pointer;
    }

    .is-tablet-ui .menu-toggle span:first-child {
        font-size: 22px;
        line-height: 1;
    }

    .is-tablet-ui .topbar {
        position: sticky;
        top: 0;
        z-index: 80;
        min-height: 82px;
        padding-block: 14px;
        box-shadow: 0 8px 22px rgba(24, 55, 111, .2);
    }

    .is-tablet-ui .sidebar-nav {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .is-tablet-ui .sidebar-nav a {
        display: flex;
        align-items: center;
        min-height: 50px;
        padding: 13px 15px;
        font-size: 15px;
    }
}

@media (min-width: 1366px) and (min-height: 720px) {
    :root {
        --login-panel-width: clamp(470px, 31vw, 540px);
        --login-logo-width: clamp(330px, 24vw, 395px);
    }
}

@media (max-height: 760px) {
    :root {
        --control-height: 40px;
        --login-logo-width: clamp(210px, 25vw, 290px);
    }

    .login-panel-refined {
        padding: 22px 28px;
    }

    .login-heading {
        margin-bottom: 14px;
    }

    .login-heading p {
        line-height: 1.35;
    }

    .form {
        gap: 10px;
    }
}

@media (max-width: 640px) {
    .topbar,
    .user-menu {
        align-items: flex-start;
        flex-direction: column;
    }

    .content {
        padding: 18px;
    }

    .quote-tool-frame {
        min-height: calc(var(--viewport-height) - 220px);
    }

    .sidebar-nav,
    .metric-grid,
    .module-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 420px) {
    :root {
        --login-panel-width: 100vw;
        --login-logo-width: 260px;
    }

    .login-panel-refined {
        padding: 22px 18px;
    }

    .login-options {
        align-items: flex-start;
        flex-direction: column;
    }
}
