/* ==========================================================
   Cloudflare Mail — interfaz inspirada en iCloud Mail
   ========================================================== */

@font-face {
    font-family: "AppFont";
    src: url("font.ttf") format("truetype");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-app: #ffffff;
    --bg-topbar: #f5f5f7;
    --bg-sidebar: #ffffff;
    --bg-field: #ececee;
    --bg-hover: #f2f2f4;
    --bg-selected: #e9e9ec;
    --border: #e0e0e4;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --text-placeholder: #a1a1a6;
    --accent: #1a73e8;
    --accent-hover: #0f5fc7;
    --accent-soft: rgba(26, 115, 232, 0.1);
    --selected-bg: #1a73e8;
    --selected-text: #ffffff;
    --danger: #d93025;
    --avatar-bg: #a2a2a8;
    --font: "AppFont", -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
            "Helvetica Neue", Helvetica, Arial, sans-serif;
    --sidebar-w: 280px;
    --list-w: 340px;
    --topbar-h: 52px;
    --auth-bg: #f5f5f7;
    --auth-card: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-app: #1c1c1e;
        --bg-topbar: #2a2a2c;
        --bg-sidebar: #232325;
        --bg-field: #3a3a3c;
        --bg-hover: #2c2c2e;
        --bg-selected: #3a3a3c;
        --border: #38383a;
        --text: #f5f5f7;
        --text-secondary: #98989d;
        --text-placeholder: #6e6e73;
        --accent: #4c8dff;
        --accent-hover: #6fa2ff;
        --accent-soft: rgba(76, 141, 255, 0.16);
        --selected-bg: #2f6fe0;
        --avatar-bg: #5a5a5e;
        --auth-bg: #141416;
        --auth-card: #1f1f21;
    }
}

[hidden] {
    display: none !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-app);
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

svg {
    display: block;
    flex-shrink: 0;
}

/* ---------- Barra superior ---------- */

.topbar {
    height: var(--topbar-h);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.brand {
    font-size: 26px;
    font-weight: 500;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.brand strong {
    font-weight: 500;
    color: var(--accent);
}

.brand-chevron {
    color: var(--accent);
}

.active-address {
    font-size: 16px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 50%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* ---------- Layout principal ---------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) var(--list-w) 1fr;
    height: calc(100vh - var(--topbar-h));
}

/* ---------- Columnas: elementos comunes ---------- */

.pane-tools {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    height: 36px;
    align-items: center;
}

.icon-btn {
    width: 34px;
    height: 30px;
    border-radius: 8px;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.icon-btn:hover {
    background: var(--accent-soft);
}

.icon-btn.spinning svg {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.pane-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.8px;
}

/* ---------- Sidebar ---------- */

.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 10px 18px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar {
    padding-top: 18px;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.title-row .pane-title {
    margin: 0;
}

/* Formulario de dirección (input + botón) */

.address-form {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 18px;
}

.address-form label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.field {
    position: relative;
    display: flex;
    align-items: center;
    height: 36px;
    margin-bottom: 10px;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 9px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.field > svg {
    margin-left: 10px;
    color: var(--text-secondary);
    pointer-events: none;
}

.field input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 2px 0 8px;
    background: transparent;
    border: none;
    outline: none;
    text-align: right;
}

.field input::placeholder {
    color: var(--text-placeholder);
}

.field .domain {
    padding: 0 10px 0 0;
    color: var(--text-secondary);
    white-space: nowrap;
    user-select: none;
    cursor: default;
}

.btn-primary {
    width: 100%;
    height: 34px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: default;
}

.form-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 8px;
    min-height: 0;
}

.form-error:empty {
    display: none;
}

/* Navegación de buzones */

.mailbox-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mailbox-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border-radius: 9px;
    text-align: left;
    font-size: 15px;
    transition: background 0.12s;
}

.mailbox-item svg {
    color: var(--accent);
}

.mailbox-item .label {
    flex: 1;
}

.mailbox-item .count {
    color: var(--text-secondary);
    font-size: 14px;
}

.mailbox-item:hover:not(:disabled) {
    background: var(--bg-hover);
}

.mailbox-item.active {
    background: var(--bg-selected);
}

.mailbox-item:disabled {
    opacity: 0.45;
    cursor: default;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 0 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.section-head h2 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.recent-empty {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 6px 10px;
}

.recent-item .label {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.recent-item .remove {
    color: var(--text-secondary);
    opacity: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.recent-item:hover .remove {
    opacity: 1;
}

.recent-item .remove:hover {
    background: var(--bg-selected);
    color: var(--text);
}

/* ---------- Lista de mensajes ---------- */

.list-pane {
    border-right: 1px solid var(--border);
    background: var(--bg-app);
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 0 0;
}

.list-head {
    padding: 0 18px;
}

.list-head .pane-title {
    margin-top: 6px;
}

.list-count {
    color: var(--text-secondary);
    font-size: 15px;
    margin: 2px 0 10px;
}

.search-field {
    position: relative;
    margin-bottom: 10px;
}

.search-field svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-field input {
    width: 100%;
    height: 36px;
    padding: 0 12px 0 34px;
    border: none;
    border-radius: 18px;
    background: var(--bg-field);
    outline: none;
    font-size: 16px;
}

.search-field input::placeholder {
    color: var(--text-placeholder);
}

.search-field input:focus {
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 10px;
    list-style: none;
}

.message {
    position: relative;
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px 10px 24px;
    border-radius: 10px;
    margin-bottom: 1px;
}

.message::after {
    content: "";
    position: absolute;
    left: 24px;
    right: 12px;
    bottom: -1px;
    height: 1px;
    background: var(--border);
}

.message:hover {
    background: var(--bg-hover);
}

.message.selected {
    background: var(--selected-bg);
    color: var(--selected-text);
}

.message.selected::after,
.message.selected + .message::after {
    background: transparent;
}

.message .unread-dot {
    position: absolute;
    left: 8px;
    top: 17px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
}

.message.selected .unread-dot {
    background: #fff;
}

.message .row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.message .from {
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.message .time {
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.message .subject {
    font-size: 14px;
    margin-top: 1px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.message .preview {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.message.selected .time,
.message.selected .preview {
    color: rgba(255, 255, 255, 0.8);
}

.list-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 24px;
    font-size: 14px;
}

.list-state.error {
    color: var(--danger);
}

/* ---------- Panel de lectura ---------- */

.detail-pane {
    background: var(--bg-app);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.detail-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 500;
    color: var(--text-placeholder);
}

.detail-view {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.detail-pane.has-message .detail-empty {
    display: none;
}

.detail-pane.has-message .detail-view {
    display: flex;
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    min-height: 62px;
}

.detail-header h2 {
    flex: 1;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.back-btn {
    display: none;
}

.detail-card {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 32px;
}

.sender-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--avatar-bg);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sender-info {
    flex: 1;
    min-width: 0;
}

.sender-name {
    font-size: 16px;
    font-weight: 600;
}

.sender-addr,
.sender-to {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sender-time {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
}

.detail-body {
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
    :root {
        --sidebar-w: 240px;
        --list-w: 300px;
    }
}

@media (max-width: 860px) {
    .app {
        grid-template-columns: var(--sidebar-w) 1fr;
    }

    .detail-pane {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        z-index: 10;
    }

    .detail-pane.show {
        transform: translateX(0);
    }

    .back-btn {
        display: inline-flex;
    }
}

@media (max-width: 600px) {
    .app {
        grid-template-columns: 1fr;
        position: relative;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 48vh;
    }

    .app {
        grid-template-rows: auto 1fr;
    }

    .list-pane {
        border-right: none;
        min-height: 0;
    }

    .active-address {
        display: none;
    }
}

/* ---------- Topbar: sesión ---------- */

.topbar-right {
    display: flex;
    align-items: center;
    gap: 18px;
    max-width: 60%;
    min-width: 0;
}

.link-btn {
    color: var(--accent);
    font-size: 15px;
    white-space: nowrap;
}

.link-btn:hover {
    text-decoration: underline;
}

/* ---------- Login / Registro ---------- */

.auth-view {
    height: calc(100vh - var(--topbar-h));
    background: var(--auth-bg);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 40px 16px;
}

.auth-card {
    width: 100%;
    max-width: 800px;
    margin: auto 0;
    background: var(--auth-card);
    border-radius: 40px;
    padding: 48px 40px 52px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.auth-ring {
    width: 200px;
    height: 200px;
    color: var(--text);
    margin-bottom: 18px;
}

.auth-title {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1px;
    text-align: center;
    margin-bottom: 38px;
}

.auth-form {
    width: 100%;
    max-width: 575px;
}

.auth-field {
    display: block;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-hover);
    padding: 9px 20px 10px;
    margin-bottom: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-field label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-field input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 21px;
    line-height: 1.3;
    padding: 0;
}

.auth-input-row {
    display: flex;
    align-items: baseline;
    cursor: text;
}

.auth-input-row input {
    flex: none;
    width: auto;
    min-width: 40px;
    max-width: 70%;
}

.auth-input-row input::placeholder {
    color: var(--text-placeholder);
}

.auth-input-row .domain {
    font-size: 21px;
    line-height: 1.3;
    color: var(--text-secondary);
    user-select: none;
    white-space: nowrap;
}

.auth-info {
    margin: 34px 0 26px;
}

.auth-info svg {
    margin-bottom: 12px;
}

.auth-info p {
    font-size: 14px;
    line-height: 1.45;
}

.auth-error {
    font-size: 14px;
    margin: 0 0 14px;
}

.auth-form .btn-primary {
    height: 48px;
    border-radius: 12px;
    font-size: 17px;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 15px;
    color: var(--text-secondary);
}

.auth-switch .link-btn {
    margin-left: 4px;
}

@media (max-width: 600px) {
    .auth-card {
        padding: 32px 20px 36px;
        border-radius: 28px;
    }

    .auth-title {
        font-size: 28px;
    }

    .auth-ring {
        width: 150px;
        height: 150px;
    }
}

/* ---------- Correo en HTML ---------- */

.detail-html {
    background: #fff;
    color: #1d1d1f;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    overflow: auto;
    contain: layout paint;   /* evita que el correo se salga de su caja (position: fixed, etc.) */
    line-height: 1.5;
    word-wrap: break-word;
}

.detail-html img {
    max-width: 100%;
    height: auto;
}

.detail-html a {
    color: #0b57d0;
}
