:root {
    --ink: #121a16;
    --ink-soft: #5b6b62;
    --muted: #8a968e;
    --paper: #edf1ee;
    --surface: #ffffff;
    --surface-soft: #f7f9f7;
    --line: rgba(18, 26, 22, 0.08);
    --line-strong: rgba(18, 26, 22, 0.14);
    --olive: #1c4a38;
    --olive-deep: #0f2f24;
    --olive-mid: #2a6b50;
    --copper: #c06a2b;
    --copper-deep: #9d5320;
    --danger: #b42318;
    --success: #16794a;
    --shadow-sm: 0 1px 2px rgba(15, 47, 36, 0.05);
    --shadow: 0 18px 50px rgba(15, 47, 36, 0.12);
    --radius: 16px;
    --radius-sm: 12px;
    --font-brand: "Reem Kufi", sans-serif;
    --font-body: "IBM Plex Sans Arabic", sans-serif;
    --sidebar-w: 272px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--paper);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

/* Login */
.page-login {
    background: #0a2219;
    overflow-x: hidden;
}

.login-shell {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    align-items: stretch;
    isolation: isolate;
}

.login-stage {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background:
        radial-gradient(ellipse 70% 55% at 18% 20%, rgba(192, 106, 43, 0.34), transparent 55%),
        radial-gradient(ellipse 55% 45% at 78% 78%, rgba(61, 140, 102, 0.22), transparent 50%),
        linear-gradient(145deg, #071910 0%, #0f2f24 42%, #163a2c 72%, #0b241b 100%);
}

.login-grid {
    position: absolute;
    inset: -10%;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 72px 72px;
    mask-image: radial-gradient(circle at 35% 40%, #000 20%, transparent 72%);
    animation: gridFloat 28s linear infinite;
    opacity: 0.55;
}

.login-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(8px);
    pointer-events: none;
}

.login-orb-a {
    width: 42vw;
    height: 42vw;
    max-width: 520px;
    max-height: 520px;
    top: -8%;
    right: 8%;
    background: radial-gradient(circle, rgba(192, 106, 43, 0.45), transparent 68%);
    animation: orbPulse 10s ease-in-out infinite;
}

.login-orb-b {
    width: 34vw;
    height: 34vw;
    max-width: 420px;
    max-height: 420px;
    bottom: -12%;
    left: -6%;
    background: radial-gradient(circle, rgba(90, 170, 130, 0.28), transparent 70%);
    animation: orbPulse 14s ease-in-out infinite reverse;
}

.login-arc {
    position: absolute;
    width: min(58vw, 640px);
    height: min(58vw, 640px);
    left: 8%;
    top: 50%;
    transform: translateY(-54%);
    border: 1px solid rgba(244, 247, 244, 0.12);
    border-radius: 50%;
    box-shadow:
        inset 0 0 0 1px rgba(192, 106, 43, 0.08),
        0 0 80px rgba(192, 106, 43, 0.08);
    animation: arcSpin 48s linear infinite;
}

.login-arc::before,
.login-arc::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(244, 247, 244, 0.08);
}

.login-arc::before { inset: 12%; }
.login-arc::after {
    inset: 26%;
    border-color: rgba(192, 106, 43, 0.22);
}

@keyframes gridFloat {
    from { transform: translate3d(0, 0, 0); }
    to { transform: translate3d(-72px, 36px, 0); }
}

@keyframes orbPulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.08); opacity: 1; }
}

@keyframes arcSpin {
    from { transform: translateY(-54%) rotate(0deg); }
    to { transform: translateY(-54%) rotate(360deg); }
}

.login-hero,
.login-panel {
    position: relative;
    z-index: 1;
}

.login-hero {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: clamp(2rem, 6vw, 4.5rem);
    padding-bottom: clamp(3rem, 8vh, 5.5rem);
}

.brand-mark {
    margin: 0;
    font-family: var(--font-brand);
    font-size: clamp(2.6rem, 6vw, 3.8rem);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: -0.02em;
}

.brand-mark-hero {
    color: #f7faf7;
    font-size: clamp(3.6rem, 9vw, 6.4rem);
    text-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    max-width: 9ch;
}

.login-hero-line {
    margin: 1.35rem 0 0;
    color: rgba(247, 250, 247, 0.88);
    font-size: clamp(1.15rem, 2.2vw, 1.45rem);
    font-weight: 500;
    max-width: 16ch;
}

.login-hero-sub {
    margin: 0.7rem 0 0;
    color: rgba(239, 195, 154, 0.92);
    font-size: 0.98rem;
    letter-spacing: 0.04em;
}

.login-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: clamp(1.25rem, 4vh, 2.5rem);
    margin-inline-start: 0;
    padding: clamp(1.6rem, 3.5vw, 2.4rem);
    border-radius: 28px;
    background: rgba(255, 252, 248, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    max-width: 460px;
    width: calc(100% - 2rem);
    align-self: center;
}

.login-kicker {
    margin: 0 0 0.35rem;
    color: var(--copper);
    font-weight: 600;
    font-size: 0.9rem;
}

.login-title {
    margin: 0 0 0.45rem;
    font-size: clamp(1.45rem, 2.6vw, 1.85rem);
    font-weight: 700;
    color: var(--olive-deep);
}

.login-lead {
    margin: 0 0 1.5rem;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.login-form,
.compose-form {
    display: grid;
    gap: 1rem;
    max-width: 420px;
}

.login-form { max-width: none; }

.password-wrap {
    position: relative;
    display: grid;
}

.password-wrap input { padding-inline-end: 4.4rem; }

.password-toggle {
    position: absolute;
    inset-inline-end: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--olive-mid);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
    border-radius: 999px;
}

.password-toggle:hover {
    background: rgba(28, 74, 56, 0.08);
}

.btn-login {
    margin-top: 0.35rem;
    padding: 0.95rem 1.3rem;
    font-size: 1.02rem;
}

.reveal-login {
    opacity: 0;
    transform: translateY(18px);
    animation: loginRise 0.75s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: calc(var(--d, 0) * 0.12s);
}

@keyframes loginRise {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.field {
    display: grid;
    gap: 0.4rem;
}

.field span {
    font-size: 0.9rem;
    color: var(--ink-soft);
    font-weight: 500;
}

.field input,
.field textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1rem;
    background: var(--surface);
    color: var(--ink);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: rgba(28, 74, 56, 0.55);
    box-shadow: 0 0 0 4px rgba(28, 74, 56, 0.12);
}

.field textarea {
    resize: vertical;
    min-height: 220px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: none;
    border-radius: 999px;
    padding: 0.82rem 1.25rem;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.88rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--copper) 0%, var(--copper-deep) 100%);
    color: #fff;
    box-shadow: 0 10px 24px rgba(192, 106, 43, 0.28);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #cb7536 0%, var(--copper) 100%);
}

.btn-block {
    width: 100%;
}

.btn-compose {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.16);
    width: calc(100% - 2rem);
    margin: 0 1rem 1.1rem;
}

.btn-compose:hover {
    background: rgba(255, 255, 255, 0.18);
}

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    background: var(--copper);
    font-size: 0.95rem;
    line-height: 1;
}

.btn-ghost {
    background: var(--surface);
    border: 1px solid var(--line-strong);
    color: var(--ink);
}

.btn-danger {
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
    border: 1px solid rgba(180, 35, 24, 0.14);
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-error {
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
}

.alert-success {
    background: rgba(22, 121, 74, 0.1);
    color: var(--success);
}

/* App shell */
.page-app {
    background:
        radial-gradient(circle at 100% 0%, rgba(192, 106, 43, 0.07), transparent 30%),
        linear-gradient(180deg, #e8eee9 0%, #f3f6f3 45%, #e7ece8 100%);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
    background:
        linear-gradient(180deg, #0f2f24 0%, #14382c 48%, #0d281f 100%);
    color: #f2f6f3;
    padding: 1.35rem 0 1rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    border-left: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-brand {
    font-family: var(--font-brand);
    font-size: 1.75rem;
    font-weight: 700;
    padding: 0.2rem 1.25rem 1.15rem;
    display: block;
}

.folder-nav {
    display: grid;
    gap: 0.2rem;
    padding: 0 0.7rem;
    overflow: auto;
    flex: 1;
}

.folder-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.72rem 0.85rem;
    border-radius: 12px;
    color: rgba(242, 246, 243, 0.72);
    transition: background 0.2s ease, color 0.2s ease;
}

.folder-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.28);
    flex-shrink: 0;
}

.folder-link:hover,
.folder-link.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.folder-link.is-active .folder-dot {
    background: var(--copper);
    box-shadow: 0 0 0 4px rgba(192, 106, 43, 0.2);
}

.sidebar-footer {
    padding: 1rem 1rem 0.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 0.8rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-meta {
    min-width: 0;
}

.user-email {
    margin: 0;
    font-size: 0.82rem;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-link {
    color: #efc39a;
    font-size: 0.82rem;
    font-weight: 500;
}

.app-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.35rem 1.6rem 0.4rem;
}

.topbar-kicker {
    margin: 0 0 0.15rem;
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

.topbar-title {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 700;
}

.nav-toggle {
    display: none;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: 12px;
    padding: 10px;
    flex-direction: column;
    justify-content: space-between;
}

.nav-toggle span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
}

.content-area {
    padding: 0.75rem 1.6rem 2rem;
}

.inbox-panel,
.message-view,
.compose-view {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.inbox-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.95rem 1.15rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
}

.inbox-count {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.92rem;
    font-weight: 500;
}

.mail-list {
    display: grid;
}

.mail-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.95rem;
    align-items: start;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--line);
    transition: background 0.16s ease;
}

.mail-row:last-child {
    border-bottom: none;
}

.mail-row:hover {
    background: #f4f8f5;
}

.mail-row.is-unread {
    background: linear-gradient(90deg, rgba(192, 106, 43, 0.06), transparent 42%);
}

.mail-row.is-unread .mail-from,
.mail-row.is-unread .mail-subject {
    font-weight: 700;
    color: var(--ink);
}

.avatar {
    --hue: 150;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: inline-grid;
    place-items: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(145deg, hsl(var(--hue) 42% 38%), hsl(calc(var(--hue) + 20) 48% 28%));
    flex-shrink: 0;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    font-size: 0.72rem;
}

.avatar-lg {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    font-size: 0.95rem;
}

.mail-main {
    min-width: 0;
    display: grid;
    gap: 0.18rem;
}

.mail-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.mail-from {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.mail-subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
}

.mail-sub {
    color: var(--muted);
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-date {
    color: var(--muted);
    font-size: 0.82rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.attach-badge {
    display: inline-block;
    margin-inline-start: 0.4rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: rgba(28, 74, 56, 0.1);
    color: var(--olive);
    font-size: 0.72rem;
    font-weight: 600;
    vertical-align: middle;
}

.empty-state {
    text-align: center;
    padding: 4rem 1.5rem;
    color: var(--ink-soft);
}

.empty-icon {
    width: 54px;
    height: 54px;
    margin: 0 auto 1rem;
    border-radius: 16px;
    background:
        linear-gradient(145deg, rgba(28, 74, 56, 0.12), rgba(192, 106, 43, 0.14));
    border: 1px solid var(--line);
}

.empty-state h2 {
    margin: 0 0 0.35rem;
    color: var(--ink);
}

.empty-state p {
    margin: 0;
}

.pagination {
    margin-top: 1rem;
    display: flex;
    gap: 0.85rem;
    align-items: center;
    color: var(--ink-soft);
}

.message-view,
.compose-view {
    padding: 0;
}

.message-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
}

.message-actions-end {
    display: flex;
    gap: 0.55rem;
    align-items: center;
}

.message-header {
    padding: 1.35rem 1.4rem 1rem;
}

.message-header h2 {
    margin: 0 0 1.15rem;
    font-size: clamp(1.25rem, 2.4vw, 1.7rem);
    line-height: 1.35;
}

.message-sender {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.85rem;
    align-items: center;
}

.message-sender-name {
    margin: 0;
    font-weight: 700;
}

.message-sender-email {
    margin: 0.15rem 0 0;
    color: var(--ink-soft);
    font-size: 0.9rem;
}

.message-date {
    color: var(--muted);
    font-size: 0.88rem;
}

.message-meta {
    margin: 1rem 0 0;
    display: grid;
    gap: 0.35rem;
    color: var(--ink-soft);
    font-size: 0.9rem;
}

.message-meta div {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 0.5rem;
}

.message-meta dt {
    font-weight: 600;
    color: var(--ink);
}

.message-meta dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.attachments-panel {
    padding: 0 1.4rem 1rem;
}

.attachments-panel h3 {
    margin: 0 0 0.7rem;
    font-size: 0.95rem;
    color: var(--ink-soft);
}

.attachments {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.65rem;
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    transition: border-color 0.16s ease, transform 0.16s ease;
}

.attachment-card:hover {
    border-color: rgba(28, 74, 56, 0.35);
    transform: translateY(-1px);
}

.attachment-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background:
        linear-gradient(145deg, rgba(28, 74, 56, 0.16), rgba(192, 106, 43, 0.18));
    flex-shrink: 0;
}

.attachment-info {
    min-width: 0;
    display: grid;
}

.attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.9rem;
}

.attachment-size {
    color: var(--muted);
    font-size: 0.78rem;
}

.message-body {
    border-top: 1px solid var(--line);
    background: #fff;
}

.message-body.is-html {
    min-height: 420px;
}

.mail-frame {
    width: 100%;
    min-height: 480px;
    border: 0;
    display: block;
    background: #fff;
}

.message-text {
    padding: 1.4rem;
    overflow-wrap: anywhere;
}

.compose-view {
    padding: 1.35rem 1.4rem 1.5rem;
}

.compose-head {
    margin-bottom: 1.1rem;
}

.section-heading {
    margin: 0;
    font-size: 1.35rem;
}

.compose-hint {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.compose-form {
    max-width: none;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.35rem;
}

.reveal {
    animation: rise 0.45s ease both;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 980px) {
    .login-shell {
        grid-template-columns: 1fr;
        align-content: start;
    }

    .login-hero {
        min-height: 38vh;
        padding: 2rem 1.4rem 1.2rem;
        justify-content: flex-end;
    }

    .brand-mark-hero {
        font-size: clamp(3rem, 14vw, 4.4rem);
    }

    .login-panel {
        width: auto;
        max-width: none;
        margin: 0 1rem 1.4rem;
        justify-self: stretch;
    }

    .login-arc {
        left: 50%;
        transform: translate(-50%, -40%);
        width: min(90vw, 420px);
        height: min(90vw, 420px);
        animation: none;
        opacity: 0.55;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(300px, 88vw);
        z-index: 30;
        transform: translateX(110%);
        transition: transform 0.25s ease;
    }

    body.nav-open .sidebar {
        transform: translateX(0);
    }

    .nav-toggle {
        display: inline-flex;
    }

    .message-sender {
        grid-template-columns: auto 1fr;
    }

    .message-date {
        grid-column: 2;
    }

    .message-actions {
        flex-wrap: wrap;
    }

    body.nav-open::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(8, 18, 14, 0.42);
        z-index: 25;
    }
}
