:root {
    --bg: #080b10;
    --bg-elevated: #101621;
    --bg-hover: #171f2d;
    --border: rgba(255, 255, 255, 0.08);
    --text: #eef2f7;
    --muted: #94a3b8;
    --accent: #f97316;
    --accent-hover: #fb923c;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 14px;
    --sidebar-width: 260px;
    --list-width: 360px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #ea580c);
    color: #fff;
    box-shadow: 0 8px 24px rgba(249, 115, 22, 0.25);
}

.btn-primary:hover { transform: translateY(-1px); background: var(--accent-hover); }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
}

.icon-btn:hover { background: var(--bg-hover); }
.icon-btn.danger:hover { color: var(--danger); border-color: rgba(239, 68, 68, 0.35); }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    font-size: 0.92rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

/* Login */
.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    position: relative;
}

.login-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 70% 50% at 50% -10%, rgba(249, 115, 22, 0.18), transparent 55%),
        linear-gradient(180deg, #080b10 0%, #0c1018 100%);
    z-index: 0;
}

.login-card {
    position: relative;
    z-index: 1;
    width: min(100%, 420px);
    background: rgba(16, 22, 33, 0.92);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), #ea580c);
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 8px 24px rgba(249, 115, 22, 0.35);
}

.brand-mark.sm { width: 38px; height: 38px; border-radius: 11px; font-size: 0.95rem; }

.login-brand strong { display: block; font-size: 1.15rem; }
.login-brand span, .sidebar-user span { color: var(--muted); font-size: 0.82rem; }

.login-lead {
    color: var(--muted);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.login-form label {
    display: block;
    margin-bottom: 1rem;
}

.login-form span {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.login-form input,
.search-wrap input,
.compose-form input,
.compose-form textarea {
    width: 100%;
    padding: 0.8rem 0.95rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #0b1018;
    color: var(--text);
    font: inherit;
}

.login-form input:focus,
.search-wrap input:focus,
.compose-form input:focus,
.compose-form textarea:focus {
    outline: none;
    border-color: rgba(249, 115, 22, 0.55);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12);
}

.login-form .btn { width: 100%; margin-top: 0.5rem; }

.login-footer {
    margin-top: 1.25rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.6;
}

/* App layout */
.app {
    height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) var(--list-width) 1fr;
    overflow: hidden;
}

.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.sidebar-user strong {
    display: block;
    font-size: 0.88rem;
    word-break: break-all;
}

.compose-btn { width: 100%; }

.folder-list {
    flex: 1;
    overflow: auto;
    padding: 0.75rem;
}

.folder-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.folder-item:hover { background: var(--bg-hover); color: var(--text); }
.folder-item.active {
    background: rgba(249, 115, 22, 0.12);
    color: var(--text);
    border: 1px solid rgba(249, 115, 22, 0.25);
}

.folder-badge {
    min-width: 24px;
    height: 24px;
    padding: 0 0.45rem;
    border-radius: 999px;
    background: rgba(249, 115, 22, 0.18);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.sidebar-bottom {
    padding: 1rem;
    display: grid;
    gap: 0.5rem;
    border-top: 1px solid var(--border);
}

.mail-list-pane {
    background: #0a0f17;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem 0.75rem;
}

.pane-header h1 { font-size: 1.2rem; }
.pane-header p { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }

#mobileBackBtn { display: none; }

.search-wrap { padding: 0 1rem 0.75rem; }

.message-list {
    flex: 1;
    overflow: auto;
    padding: 0 0.5rem 0.5rem;
}

.message-item {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
}

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

.message-item.active {
    background: rgba(249, 115, 22, 0.1);
    border-color: rgba(249, 115, 22, 0.25);
}

.message-item.unread .message-from,
.message-item.unread .message-subject {
    font-weight: 700;
    color: #fff;
}

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

.message-from {
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    color: var(--muted);
    font-size: 0.78rem;
    flex-shrink: 0;
}

.message-subject {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-preview {
    color: var(--muted);
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.pagination button {
    min-width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
}

.pagination button.active {
    background: rgba(249, 115, 22, 0.18);
    border-color: rgba(249, 115, 22, 0.35);
    color: var(--accent);
}

.mail-read-pane {
    background: var(--bg);
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

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

.empty-state {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--muted);
}

.empty-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 2rem;
    background: rgba(249, 115, 22, 0.12);
    color: var(--accent);
}

.mail-view-header {
    padding: 1.5rem 1.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(16, 22, 33, 0.65);
    position: sticky;
    top: 0;
    backdrop-filter: blur(10px);
}

.mail-view-top {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}

.mail-view-top h2 {
    font-size: 1.35rem;
    line-height: 1.3;
}

.mail-meta {
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.mail-meta span {
    display: inline-block;
    width: 2.5rem;
    color: #64748b;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.82rem;
    text-decoration: none;
}

.attachment-chip:hover {
    border-color: rgba(249, 115, 22, 0.35);
    text-decoration: none;
}

.mail-body {
    padding: 1.75rem;
    line-height: 1.65;
    font-size: 0.98rem;
    word-break: break-word;
    flex: 1;
    overflow: auto;
}

.mail-body img { max-width: 100%; height: auto; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    width: min(100%, 640px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.compose-form {
    padding: 1.25rem;
    display: grid;
    gap: 1rem;
}

.compose-form label span {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.list-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
}

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

    .mail-read-pane {
        position: fixed;
        inset: 0;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }

    .mail-read-pane.open {
        transform: translateX(0);
    }

    #mobileBackBtn { display: inline-grid; place-items: center; }
}

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

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(85vw, 280px);
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

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

    .mail-list-pane {
        border-right: none;
    }
}
