:root {
    --bg: #f2f4f8;
    --card: #ffffff;
    --primary: #411e5a;
    --primary-dark: #35184a;
    --text: #111827;
    --text-muted: #6b7280;
    --border: #d7deea;
    --sidebar: #411e5a;
    --sidebar-soft: #35184a;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* Login */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 20px;
    box-shadow: 0 4px 20px rgba(21, 30, 51, 0.08);
}

.auth-logo {
    width: 46px;
    height: 46px;
    margin: 0 auto 12px;
    border-radius: 12px;
    background: #411e5a;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-logo-image {
    width: 70%;
    height: 70%;
    object-fit: contain;
    display: block;
}

.auth-title {
    margin: 0;
    text-align: center;
    font-size: 32px;
}

.auth-subtitle {
    margin: 6px 0 20px;
    text-align: center;
    color: var(--text-muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-label {
    margin-top: 6px;
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.auth-input {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    min-height: 44px;
    padding: 10px 12px;
    background: #f7f9fc;
}

.auth-input:focus {
    outline: 2px solid rgba(35, 104, 216, 0.2);
    border-color: var(--primary);
}

.auth-submit {
    margin-top: 12px;
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

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

.auth-submit.is-loading {
    opacity: 0.95;
}

.auth-error {
    margin: 8px 0 0;
    color: #b42318;
    background: #fef3f2;
    border: 1px solid #fecdca;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
}

.auth-footnote {
    margin: 16px 0 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Portal */
.portal-shell {
    min-height: 100vh;
    display: flex;
    position: relative;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.25);
    z-index: 20;
}

.portal-sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar));
    color: #dbe5ff;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 30;
    transition: left 0.25s ease;
    box-sizing: border-box;
}

.portal-sidebar.open {
    left: 0;
}

.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 18px;
}

.sidebar-header span {
    margin-top: 6px;
    display: block;
    font-size: 12px;
    color: #9db1da;
}

.sidebar-menu {
    padding: 14px 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.menu-item {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: #dbe5ff;
    text-decoration: none;
}

.menu-item.active {
    background: var(--sidebar-soft);
    font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
    flex-shrink: 0;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1f2f54;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.user-meta {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.user-meta strong {
    font-size: 12px;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.user-meta span {
    font-size: 11px;
    line-height: 1.35;
    color: #9db1da;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.logout-link {
    border: 0;
    background: transparent;
    color: #f3f4f6;
    font-size: 12px;
    flex-shrink: 0;
    padding: 4px 0;
    align-self: center;
}

.portal-content {
    width: 100%;
    padding: 14px;
}

.content-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.content-header h1 {
    margin: 0;
    font-size: 20px;
}

.content-header p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}

.menu-button,
.refresh-button,
.btn-retry {
    min-height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    padding: 0 12px;
}

.refresh-button {
    margin-left: auto;
}

.leads-toolbar {
    margin-bottom: 14px;
}

.leads-toolbar-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px 10px;
    box-shadow: 0 2px 8px rgba(21, 30, 51, 0.05);
}

.leads-filter-label {
    display: block;
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.leads-filter-field {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 46px;
    padding: 0 4px 0 12px;
    background: #f7f9fc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.leads-filter-field:focus-within {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(65, 30, 90, 0.12);
}

.leads-filter-icon {
    flex-shrink: 0;
    display: flex;
    color: #64748b;
}

.leads-filter-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 10px 8px 10px 4px;
    border: 0;
    background: transparent;
    font-size: 16px;
    color: var(--text);
}

.leads-filter-input::placeholder {
    color: #94a3b8;
}

.leads-filter-input:focus {
    outline: none;
}

.leads-filter-clear {
    flex-shrink: 0;
    margin: 2px 2px 2px 0;
    padding: 0 14px;
    min-height: 40px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
}

.leads-filter-clear:active {
    background: rgba(65, 30, 90, 0.08);
}

.leads-filter-hint {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.35;
}

@media (min-width: 992px) {
    .leads-filter-clear:hover {
        background: rgba(65, 30, 90, 0.06);
    }
}

.state-panel--soft {
    text-align: center;
}

.state-empty--center {
    margin-bottom: 4px;
    font-size: 15px;
    color: var(--text);
}

.state-empty-sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.45;
}

.btn-retry--block {
    display: block;
    width: 100%;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.leads-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sort-indicator {
    display: inline-block;
    min-width: 12px;
    margin-left: 6px;
    font-size: 11px;
    color: #64748b;
}

.state-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}

.state-empty,
.state-error {
    margin: 0;
    color: var(--text-muted);
}

.state-error {
    color: #b42318;
    margin-bottom: 10px;
}

.skeleton-card {
    height: 86px;
    border-radius: 10px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #edf1f7, #f9fbff, #edf1f7);
    background-size: 200% 100%;
    animation: pulse 1.2s linear infinite;
}

@keyframes pulse {
    from {
        background-position: 200% 0;
    }

    to {
        background-position: -200% 0;
    }
}

.leads-cards {
    display: grid;
    gap: 10px;
}

.lead-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}

.lead-card-main h3 {
    margin: 0;
    font-size: 16px;
}

.lead-card-main p {
    margin: 4px 0;
    color: #334155;
}

.lead-card-main small {
    color: var(--text-muted);
}

.lead-card-footer {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.lead-card-footer span {
    background: #eef2f8;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
}

.whatsapp-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #16a34a;
    background: #22c55e;
    color: #fff;
    border-radius: 8px;
    min-height: 36px;
    padding: 0 12px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.table-wrapper {
    display: none;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: auto;
}

.leads-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.leads-table th,
.leads-table td {
    padding: 12px;
    border-bottom: 1px solid #ebeff7;
    text-align: left;
}

.store-badge {
    background: #eef2f8;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
}

@media (min-width: 992px) {
    .portal-shell {
        align-items: flex-start;
    }

    .portal-sidebar {
        left: 0;
        position: sticky;
        top: 0;
        height: 100vh;
        max-height: 100vh;
        align-self: flex-start;
    }

    .menu-button {
        display: none;
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .portal-content {
        flex: 1;
        min-width: 0;
        padding: 18px 20px;
    }

    .leads-cards {
        display: none;
    }

    .table-wrapper {
        display: block;
    }
}

body.portal-modal-open {
    overflow: hidden;
}

.portal-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    background: rgba(17, 24, 39, 0.45);
    backdrop-filter: blur(2px);
}

.portal-modal {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 20px;
    box-shadow: 0 16px 48px rgba(21, 30, 51, 0.18);
}

.portal-modal__title {
    margin: 0 0 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.portal-modal__text {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-muted);
}

.portal-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.portal-modal__btn {
    min-height: 42px;
    padding: 0 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
}

.portal-modal__btn--secondary {
    background: #fff;
    color: var(--text);
}

.portal-modal__btn--secondary:hover {
    background: #f7f9fc;
}

.portal-modal__btn--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.portal-modal__btn--primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}