:root {
    --bg: #f4f7fc;
    --surface: #ffffff;
    --surface-soft: #f7f9fd;
    --text: #09152b;
    --muted: #63708a;
    --line: #d8e1ef;
    --primary: #2f6df6;
    --primary-dark: #1f58da;
    --purple: #7447f4;
    --cyan: #05cfe6;
    --danger: #dc3545;
    --warning: #e59212;
    --success: #1daa78;
    --shadow: 0 12px 30px rgba(35, 62, 110, .07);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.topbar {
    min-height: 55px; padding: 6px 22px; background: #fff; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.brand strong { display: block; font-size: 15px; line-height: 1.1; }
.brand small { display: block; color: var(--primary); font-size: 11px; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-nav { display: flex; align-items: center; gap: 4px; }
.topbar-nav a { padding: 8px 9px; border-radius: 8px; color: #4f5e77; font-size: 11px; font-weight: 800; }
.topbar-nav a:hover { background: #f0f4fb; color: var(--primary); }
.workspace-label { color: #5d6880; font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.notification-link { color: #43516d; font-size: 12px; font-weight: 700; }
.notification-count { min-width: 20px; height: 20px; padding: 0 6px; margin-left: 3px; display: inline-grid; place-items: center; border-radius: 999px; background: #eef3ff; color: var(--primary); }

.container { width: min(1400px, calc(100% - 40px)); margin: 23px auto 58px; }
h1, h2, p { margin-top: 0; }
h1 { letter-spacing: -.035em; }

.hero-card {
    min-height: 220px; border: 1px solid #d4dff2; border-radius: 20px; padding: 30px 32px;
    background: linear-gradient(110deg, #fff 22%, #f0f6ff 55%, #dfd9ff 100%);
    box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between;
    gap: 36px; overflow: hidden; position: relative;
}
.hero-copy { max-width: 700px; position: relative; z-index: 2; }
.hero-chip { display: inline-block; padding: 6px 12px; margin-bottom: 13px; border-radius: 999px; background: #eaf1ff; color: var(--primary); font-size: 12px; font-weight: 800; }
.hero-copy h1 { margin: 0 0 2px; font-size: clamp(31px, 4vw, 40px); }
.hero-copy h2 { margin: 0 0 10px; color: var(--primary); font-size: clamp(21px, 3vw, 27px); letter-spacing: -.035em; }
.hero-copy p { max-width: 680px; margin: 0; color: #354462; line-height: 1.55; }
.hero-visual { width: 260px; height: 150px; position: relative; flex: 0 0 260px; }
.hero-visual::before { content: ""; position: absolute; inset: 5px 0 0 40px; background: rgba(255,255,255,.46); filter: blur(22px); border-radius: 50%; }
.mail-window { position: absolute; width: 210px; height: 125px; top: 7px; left: 12px; padding: 34px 13px 12px; background: rgba(255,255,255,.94); border-radius: 17px; box-shadow: 0 18px 35px rgba(67, 61, 160, .18); transform: rotate(6deg); display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.window-dot { position: absolute; top: 16px; width: 8px; height: 8px; border-radius: 50%; background: #8db1ed; }
.dot-one { left: 18px; }.dot-two { left: 31px; }.dot-three { left: 44px; }
.mail-column { padding: 8px 6px; border: 1px solid #dce6f4; border-radius: 8px; }
.mail-column i { display: block; height: 8px; margin-bottom: 7px; border-radius: 4px; background: #c7d8f5; }
.mail-column i:first-child { height: 13px; background: #82b3ff; }
.mail-column i:last-child { width: 70%; background: #61d3ba; }
.hero-visual img { position: absolute; width: 58px; height: 58px; right: 6px; bottom: 2px; border-radius: 14px; box-shadow: 0 15px 28px rgba(70, 57, 183, .26); z-index: 2; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0 16px; }
.metric-card { min-height: 78px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); transition: transform .16s, border-color .16s; }
.metric-card:hover { transform: translateY(-2px); border-color: #a9bee2; }
.metric-card span { display: block; color: #596780; font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin-top: 4px; font-size: 26px; line-height: 1; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 322px; gap: 15px; align-items: start; }
.table-card, .summary-card, .detail-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.table-card { overflow: hidden; }
.section-heading { min-height: 82px; padding: 20px 22px 10px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2, .summary-card h2 { margin: 7px 0 0; font-size: 22px; letter-spacing: -.025em; }
.section-kicker { color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .13em; }
.result-counter { padding: 7px 10px; border-radius: 9px; background: #f0f4fb; color: #5d6a81; font-size: 11px; font-weight: 700; }

.filters-row { padding: 0 22px 16px; display: grid; grid-template-columns: minmax(180px, 1.5fr) repeat(5, minmax(120px, 1fr)) auto auto; gap: 8px; }
input, select { width: 100%; min-width: 0; height: 40px; border: 1px solid #d4deed; border-radius: 10px; background: #fff; color: var(--text); padding: 0 11px; outline: none; font-size: 12px; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,109,246,.11); }
.button { min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid #d4deed; background: #fff; color: var(--text); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; cursor: pointer; white-space: nowrap; }
.button-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-ghost:hover { background: #f5f7fb; }
.button-block { width: 100%; }

.table-scroll { overflow-x: auto; border-top: 1px solid var(--line); }
.data-table { width: 100%; min-width: 1040px; border-collapse: collapse; }
.data-table th { padding: 13px 12px; background: #f7f9fd; color: #5d6a82; border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; white-space: nowrap; }
.data-table td { padding: 13px 12px; border-bottom: 1px solid #e7edf5; vertical-align: middle; color: #283753; font-size: 12px; }
.data-table tbody tr:hover { background: #fafcff; }
.data-table tr.row-new { background: #f8fbff; }
.data-table td strong, .data-table td small, .data-table time small { display: block; }
.data-table td strong { color: var(--text); }
.data-table td small { max-width: 280px; margin-top: 3px; color: #758198; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-cell { min-width: 270px; max-width: 340px; }
.mailbox-label { display: block; max-width: 195px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge, .priority-pill, .status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; font-size: 10px; line-height: 1; font-weight: 900; white-space: nowrap; }
.badge-urgente { background: #ffe4e6; color: #be123c; }
.badge-importante { background: #fff0cb; color: #a85b00; }
.badge-normal { background: #e1edff; color: #245bc4; }
.badge-publicidad { background: #eee8ff; color: #6640c7; }
.badge-spam, .badge-neutral { background: #e9edf4; color: #566176; }
.priority-alta { background: #ffe4e6; color: #be123c; }
.priority-media { background: #fff0cb; color: #a85b00; }
.priority-baja { background: #dff8ec; color: #167553; }
.status-nuevo { background: #e3edff; color: #245bc4; }
.status-revisado { background: #dff8ec; color: #167553; }
.table-action { display: inline-flex; padding: 7px 9px; border: 1px solid #cfdaeb; border-radius: 8px; color: var(--primary); font-size: 11px; font-weight: 800; white-space: nowrap; }
.table-action:hover { background: #edf3ff; }
.empty-table { height: 105px; text-align: center; color: #778399 !important; }
.table-footer { min-height: 58px; padding: 11px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: #6b7890; font-size: 11px; }
.pagination { display: flex; flex-wrap: wrap; gap: 5px; }
.pagination a { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #d4deed; border-radius: 8px; background: #fff; }
.pagination a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.summary-card { padding: 23px 19px; }
.summary-card p { color: #66738b; font-size: 12px; line-height: 1.5; margin: 10px 0 18px; }
.summary-list { border-top: 1px solid #e6ecf4; }
.summary-list a { min-height: 46px; padding: 9px 2px; border-bottom: 1px solid #e6ecf4; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.summary-list span { display: flex; align-items: center; gap: 8px; color: #45536c; }
.summary-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-normal { background: #4e86f7; }.dot-ad { background: #7b56ef; }.dot-spam { background: #8d98aa; }
.connected-box { margin-top: 18px; padding: 15px; border-radius: 12px; background: linear-gradient(135deg, #edf4ff, #efebff); }
.connected-box strong, .connected-box span { display: block; }
.connected-box strong { color: var(--primary); font-size: 25px; }
.connected-box span { color: #5e6b82; font-size: 11px; }

.site-footer { width: min(1400px, calc(100% - 40px)); min-height: 58px; margin: -28px auto 0; padding: 18px 2px; border-top: 1px solid #dde5f0; display: flex; justify-content: space-between; gap: 15px; color: #748198; font-size: 11px; }
.flash-stack { position: fixed; top: 68px; right: 22px; width: min(390px, calc(100% - 30px)); z-index: 50; display: grid; gap: 8px; }
.flash-stack .alert { margin: 0; border: 1px solid transparent; box-shadow: 0 15px 38px rgba(32, 54, 94, .14); transition: opacity .2s, transform .2s; }
.flash-stack .alert.is-hiding { opacity: 0; transform: translateY(-8px); }
.alert-success { background: #e2f8ed; border-color: #b9ead3 !important; color: #116a49; }

.page-heading-card { min-height: 132px; margin-bottom: 16px; padding: 24px 26px; border: 1px solid #d7e1ef; border-radius: 18px; background: linear-gradient(110deg, #fff 30%, #eef4ff 67%, #e9e3ff); box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 22px; }
.page-heading-card h1 { margin: 7px 0 5px; font-size: 30px; }
.page-heading-card p { margin: 0; color: #5f6d84; }
.management-card { margin-bottom: 18px; }
.mailbox-filters { grid-template-columns: minmax(250px, 1.6fr) minmax(180px, 1fr) minmax(160px, 1fr) auto auto; }
.management-table { min-width: 850px; }
.table-actions { display: flex; align-items: center; gap: 6px; }
.table-actions form { margin: 0; }
button.table-action { background: #fff; cursor: pointer; }
.table-action-danger { color: #bd2743; border-color: #efc9d0; }
.table-action-danger:hover { background: #fff0f2; }

.form-card { padding: 24px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.form-card-narrow { width: min(620px, 100%); }
.entity-form { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.entity-form label, .stack-form label { color: #5f6d84; font-size: 12px; font-weight: 700; }
.entity-form input, .entity-form select { margin-top: 6px; }
.full-row { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.checkbox-field { display: flex; align-items: center; gap: 9px; min-height: 40px; padding-top: 17px; }
.checkbox-field input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }

.password-field { position: relative; display: block; margin-top: 6px; }
.password-field input { margin-top: 0; padding-right: 45px; }
.password-toggle { position: absolute; right: 5px; top: 4px; width: 34px; height: 32px; padding: 7px; border: 0; border-radius: 8px; background: transparent; color: #71809a; cursor: pointer; }
.password-toggle:hover, .password-toggle.is-visible { background: #edf3ff; color: var(--primary); }
.password-toggle svg { width: 19px; height: 19px; fill: currentColor; }

.back-link { display: inline-block; margin: 3px 0 14px; color: var(--primary); font-weight: 800; }
.detail-card { padding: 25px; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-header h1 { margin: 13px 0 0; font-size: clamp(25px, 4vw, 34px); }
.detail-badges { display: flex; flex-wrap: wrap; gap: 7px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 19px 0; }
.detail-grid div { padding: 13px; border: 1px solid #e0e7f1; border-radius: 11px; background: #f9fbfe; min-width: 0; }
.detail-grid span, .detail-grid strong, .detail-grid small { display: block; overflow-wrap: anywhere; }
.detail-grid span, .detail-grid small { color: #718097; font-size: 11px; }
.detail-grid strong { margin: 4px 0; }
.ai-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-bottom: 18px; }
.ai-panel div { padding: 15px; border-left: 4px solid var(--primary); border-radius: 10px; background: #eef4ff; }
.ai-panel span { color: var(--primary-dark); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.ai-panel p { margin: 6px 0 0; line-height: 1.55; }
.message-panel { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.message-panel-header { padding: 12px 14px; border-bottom: 1px solid var(--line); background: #f8fafe; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.message-panel-header div { display: flex; align-items: center; gap: 7px; }
.message-panel pre { max-height: 600px; padding: 18px; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.auth-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: linear-gradient(135deg, #eef5ff, #e9e5ff); }
.auth-shell { width: min(420px, 100%); }
.auth-card { width: min(420px, 100%); padding: 32px; border: 1px solid #d8e2f0; border-radius: 20px; background: rgba(255,255,255,.97); box-shadow: 0 25px 70px rgba(48, 65, 113, .17); }
.auth-logo { width: 50px; height: 50px; border-radius: 13px; margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 7px; font-size: 32px; }
.eyebrow { margin-bottom: 8px; color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .15em; }
.muted { color: var(--muted); }
.stack-form { display: grid; gap: 14px; margin-top: 22px; }
.stack-form label { color: #5f6d84; font-size: 12px; font-weight: 700; }
.stack-form input { margin-top: 6px; }
.stack-form .password-field input { margin-top: 0; }
.alert { margin-top: 16px; padding: 11px 13px; border-radius: 9px; }
.alert-error { background: #ffe4e6; color: #a51032; }
.auth-footer { padding: 17px 8px 0; color: #6e7c93; text-align: center; font-size: 11px; }

@media (max-width: 1260px) {
    .filters-row { grid-template-columns: repeat(4, 1fr); }
    .filter-search { grid-column: span 2; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .summary-card { display: grid; grid-template-columns: 1fr 1fr; column-gap: 22px; }
    .summary-card > .section-kicker, .summary-card > h2, .summary-card > p { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
    .container { width: min(100% - 24px, 1400px); margin-top: 14px; }
    .hero-card { min-height: 0; padding: 24px; }
    .hero-visual { display: none; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-row { grid-template-columns: 1fr 1fr; padding: 0 15px 15px; }
    .filters-row input, .filters-row select { grid-column: 1 / -1; }
    .section-heading { padding-left: 15px; padding-right: 15px; }
    .detail-grid, .ai-panel { grid-template-columns: 1fr 1fr; }
    .page-heading-card { align-items: flex-start; }
    .mailbox-filters { grid-template-columns: 1fr 1fr; }
    .mailbox-filters .filter-search { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
    .workspace-label, .notification-link, .topbar-nav a:first-child { display: none; }
    .topbar-nav a { padding: 7px 5px; font-size: 10px; }
    .topbar { padding-left: 12px; padding-right: 12px; }
    .hero-copy h1 { font-size: 29px; }
    .hero-copy h2 { font-size: 21px; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .filters-row { grid-template-columns: 1fr; }
    .filters-row .button { width: 100%; }
    .summary-card { display: block; }
    .detail-card { padding: 17px; }
    .detail-header, .message-panel-header { flex-direction: column; align-items: stretch; }
    .detail-grid, .ai-panel { grid-template-columns: 1fr; }
    .site-footer { flex-direction: column; gap: 4px; }
    .page-heading-card { padding: 20px; flex-direction: column; }
    .page-heading-card .button { width: 100%; }
    .entity-form, .mailbox-filters { grid-template-columns: 1fr; }
    .entity-form .full-row, .mailbox-filters .filter-search { grid-column: auto; }
}
