:root {
    --primary-color: #00b4d8;
    --secondary-color: #0077b6;
    --primary-soft: #e6f7fa;
    --bg-color: #f4f7f6;
    --surface: #ffffff;
    --surface-alt: #f8fbfc;
    --text-dark: #22313f;
    --text-light: #708090;
    --border-color: #e0e7ea;
    --shadow-soft: 0 12px 34px rgba(16, 42, 67, 0.08);
    --shadow-card: 0 24px 60px rgba(10, 30, 50, 0.12);
    --success: #16a34a;
    --warning: #f59e0b;
    --error: #dc2626;
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-dark);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; }
code {
    background: rgba(0, 119, 182, 0.08);
    padding: 2px 8px;
    border-radius: 8px;
    direction: ltr;
    unicode-bidi: embed;
}

.app-guest {
    background-color: var(--bg-color);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'><path fill='%2300b4d8' fill-opacity='0.10' d='M0,128L80,149.3C160,171,320,213,480,202.7C640,192,800,128,960,117.3C1120,107,1280,149,1360,170.7L1440,192L1440,320L1360,320C1280,320,1120,320,960,320C800,320,640,320,480,320C320,320,160,320,80,320L0,320Z'></path></svg>");
    background-repeat: no-repeat;
    background-position: bottom center;
    background-size: cover;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 18px 90px;
}

.login-card-wrap {
    width: min(1080px, 100%);
}

.login-card {
    display: grid;
    grid-template-columns: minmax(280px, 420px) minmax(320px, 1fr);
    background: var(--surface);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

.login-visual {
    background: linear-gradient(145deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    padding: 42px 34px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.login-visual::before,
.login-visual::after {
    content: "";
    position: absolute;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.login-visual::before {
    width: 210px;
    height: 210px;
    top: -80px;
    left: -70px;
}

.login-visual::after {
    width: 160px;
    height: 160px;
    bottom: -55px;
    right: -40px;
}

.login-brand-logo {
    width: 96px;
    height: 96px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255,255,255,0.22);
    padding: 12px;
    border-radius: 22px;
    margin-bottom: 18px;
    position: relative;
    z-index: 1;
}

.login-visual-icon {
    width: 108px;
    height: 108px;
    border-radius: 999px;
    background: rgba(255,255,255,0.14);
    border: 1px solid rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.login-visual h1,
.login-visual p,
.login-badges { position: relative; z-index: 1; }
.login-visual h1 { margin: 0 0 12px; font-size: 2rem; font-weight: 800; }
.login-visual p { margin: 0 0 24px; color: rgba(255,255,255,0.9); line-height: 1.9; }

.login-badges {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 999px;
    font-size: 0.95rem;
}

.login-form-container {
    padding: 50px 44px;
}

.eyebrow {
    font-size: 0.82rem;
    letter-spacing: 0.14em;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.login-form-container h2 {
    margin: 0 0 8px;
    font-size: 2rem;
    color: var(--primary-color);
}

.login-copy,
.muted,
.tiny-note,
.page-subtitle,
.brand-tagline {
    color: var(--text-light);
}

.login-copy {
    margin: 0 0 24px;
    line-height: 1.9;
}

.auth-card,
.panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.auth-card {
    padding: 0;
}

.field {
    display: block;
    margin-bottom: 18px;
}

.field span {
    display: block;
    margin-bottom: 9px;
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--text-dark);
}

.field-input,
.field input,
.field textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: #fff;
    transition: 0.25s ease;
}

.field-input {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
}

.field-input i {
    color: var(--text-light);
    font-size: 0.95rem;
}

.field input,
.field textarea {
    padding: 14px 16px;
    color: var(--text-dark);
    outline: none;
}

.field-input input {
    border: 0;
    padding: 14px 0;
    background: transparent;
}

.field textarea {
    min-height: 300px;
    resize: vertical;
}

.field-input:focus-within,
.field input:focus,
.field textarea:focus {
    border-color: rgba(0, 180, 216, 0.75);
    box-shadow: 0 0 0 4px rgba(0, 180, 216, 0.12);
}

.login-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 6px 0 18px;
}

.remember-me {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-light);
    font-size: 0.92rem;
}

.primary-btn,
.ghost-btn,
.compose-link,
.logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: none;
    cursor: pointer;
    border-radius: 14px;
    font-weight: 700;
    transition: 0.2s ease;
}

.primary-btn,
.compose-link {
    color: #fff;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 10px 25px rgba(0, 119, 182, 0.22);
}

.primary-btn,
.ghost-btn { padding: 13px 18px; }
.compose-link { padding: 14px 18px; width: 100%; }

.primary-btn:hover,
.compose-link:hover,
.ghost-btn:hover,
.logout-link:hover {
    transform: translateY(-1px);
}

.ghost-btn,
.logout-link {
    background: rgba(0, 119, 182, 0.05);
    color: var(--secondary-color);
    border: 1px solid rgba(0, 119, 182, 0.12);
}

.ghost-btn.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.full { width: 100%; }

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    line-height: 1.8;
}

.alert.success { background: rgba(22,163,74,0.10); border-color: rgba(22,163,74,0.18); color: #166534; }
.alert.error { background: rgba(220,38,38,0.10); border-color: rgba(220,38,38,0.18); color: #991b1b; }
.alert.warning { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.18); color: #92400e; }

.app-auth .app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-left: 1px solid var(--border-color);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px 4px;
}

.brand-logo {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    background: var(--surface-alt);
    padding: 8px;
    object-fit: contain;
    border: 1px solid rgba(0, 119, 182, 0.08);
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary-color);
}

.sidebar-section { display: grid; gap: 12px; }
.section-title { font-size: 0.84rem; font-weight: 800; color: var(--text-light); }
.folder-list { display: grid; gap: 6px; }

.folder-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    color: var(--text-dark);
    transition: 0.2s ease;
}

.folder-item:hover,
.folder-item.active {
    background: var(--primary-soft);
    color: var(--primary-color);
}

.folder-icon {
    width: 24px;
    text-align: center;
    color: var(--text-light);
}

.folder-item.active .folder-icon,
.folder-item:hover .folder-icon { color: var(--primary-color); }

.sidebar-account-card {
    background: var(--surface-alt);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 16px;
}

.account-pill {
    display: flex;
    align-items: center;
    gap: 10px;
}

.account-avatar,
.user-profile {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    font-weight: 800;
}

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

.spacer { flex: 1; }
.logout-link { width: 100%; padding: 12px 14px; }

.main-panel {
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 800;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f1f6f8;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 10px 16px;
    min-width: 320px;
}

.search-bar i { color: var(--text-light); }
.search-bar input {
    width: 100%;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--text-light);
}

.content-area {
    padding: 28px;
    display: grid;
    gap: 18px;
}

.panel {
    padding: 24px;
}

.toolbar,
.message-header,
.compose-actions,
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.toolbar {
    margin-bottom: 18px;
}

.toolbar-actions,
.message-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.message-list {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    background: var(--surface);
}

.message-row {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 155px;
    gap: 16px;
    align-items: center;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
    transition: 0.18s ease;
}

.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: #fbfdfe; }
.message-row.unseen { background: #f0fbff; font-weight: 700; }

.message-status {
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-status span {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: transparent;
}

.message-row.unseen .message-status span {
    background: var(--primary-color);
    box-shadow: 0 0 0 5px rgba(0, 180, 216, 0.12);
}

.message-primary {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.message-from,
.message-subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-from { font-size: 1rem; }
.message-subject { color: var(--text-light); font-size: 0.96rem; }
.message-row.unseen .message-subject { color: var(--text-dark); }

.message-meta {
    display: grid;
    gap: 6px;
    justify-items: end;
    color: var(--text-light);
    font-size: 0.83rem;
}

.message-header {
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 18px;
}

.message-header h2 {
    margin: 0 0 14px;
    font-size: 1.5rem;
}

.meta-stack {
    display: grid;
    gap: 8px;
    color: var(--text-light);
    line-height: 1.8;
}

.attachment-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    background: #f3f9fb;
    border: 1px solid rgba(0, 180, 216, 0.15);
    color: var(--secondary-color);
}

.attachment-chip small {
    color: var(--text-light);
    font-size: 0.8rem;
}

.message-body {
    background: var(--surface-alt);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    line-height: 2;
    overflow-x: auto;
}

.prose img { max-width: 100%; height: auto; }
.prose table { width: 100%; border-collapse: collapse; }
.prose td, .prose th { border: 1px solid var(--border-color); padding: 8px; }

.compose-form {
    display: grid;
    gap: 16px;
}

.inline-field {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.inline-field span,
.field-editor span {
    margin-bottom: 0;
}

.inline-field input {
    border: 0;
    padding: 10px 0;
    background: transparent;
}

.field-editor {
    margin-bottom: 0;
}

.field-editor textarea {
    margin-top: 10px;
    min-height: 320px;
}


.attachment-field {
    margin-bottom: 0;
}

.attachment-upload-box {
    border: 1px dashed rgba(0, 180, 216, 0.45);
    background: var(--surface-alt);
    border-radius: 16px;
    padding: 18px;
    display: grid;
    gap: 10px;
}

.attachment-upload-box input[type="file"] {
    display: block;
    width: 100%;
    color: var(--text-dark);
}

.attachment-upload-box input[type="file"]::file-selector-button {
    margin-left: 12px;
    border: 0;
    border-radius: 10px;
    background: rgba(0, 180, 216, 0.14);
    color: var(--primary-color);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

.attachment-upload-box input[type="file"]::-webkit-file-upload-button {
    margin-left: 12px;
    border: 0;
    border-radius: 10px;
    background: rgba(0, 180, 216, 0.14);
    color: var(--primary-color);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

.section-heading h2 {
    margin: 0 0 6px;
    font-size: 1.35rem;
}

.empty-state {
    min-height: 280px;
    display: grid;
    place-items: center;
    text-align: center;
    gap: 8px;
    color: var(--text-light);
}

.empty-icon {
    width: 76px;
    height: 76px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
}

.pagination {
    margin-top: 18px;
}

@media (max-width: 1100px) {
    .search-bar { min-width: 240px; }
    .message-row { grid-template-columns: 18px minmax(0, 1fr) 120px; }
}

@media (max-width: 900px) {
    .login-card { grid-template-columns: 1fr; }
    .login-form-container { padding: 36px 24px; }
    .app-auth .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        border-left: 0;
        border-bottom: 1px solid var(--border-color);
    }
    .topbar,
    .content-area { padding: 20px; }
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }
    .topbar-actions { justify-content: space-between; }
    .search-bar { min-width: 0; flex: 1; }
}

@media (max-width: 640px) {
    .login-page { padding: 18px 14px 70px; }
    .login-visual,
    .login-form-container,
    .panel { padding: 20px; }
    .message-row {
        grid-template-columns: 18px 1fr;
        align-items: start;
    }
    .message-meta {
        grid-column: 2;
        justify-items: start;
    }
    .inline-field {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .topbar-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .search-bar { width: 100%; }
}
