:root {
    --bg: #050508;
    --surface: rgba(14, 14, 22, 0.72);
    --surface-2: rgba(22, 22, 34, 0.9);
    --surface-hover: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #f8f8fc;
    --text-2: #a8a8be;
    --text-3: #6b6b82;
    --accent: #6d6aff;
    --accent-2: #a855f7;
    --accent-soft: rgba(109, 106, 255, 0.14);
    --glow: rgba(109, 106, 255, 0.45);
    --success: #34d399;
    --error: #fb7185;
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --sidebar: 280px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

/* ── Ambient background ── */
.ambient {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}
.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.55;
    animation: float 18s var(--ease) infinite alternate;
}
.orb-1 {
    width: 420px; height: 420px;
    background: radial-gradient(circle, rgba(109,106,255,0.35), transparent 70%);
    top: -120px; left: -80px;
}
.orb-2 {
    width: 360px; height: 360px;
    background: radial-gradient(circle, rgba(168,85,247,0.28), transparent 70%);
    bottom: -100px; right: -60px;
    animation-delay: -6s;
}
.orb-3 {
    width: 280px; height: 280px;
    background: radial-gradient(circle, rgba(99,102,241,0.2), transparent 70%);
    top: 40%; left: 45%;
    animation-delay: -12s;
}

@keyframes float {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(30px, -20px) scale(1.08); }
}

/* ── Layout shell ── */
.app-layout {
    position: relative;
    z-index: 1;
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar);
    background: var(--surface);
    backdrop-filter: blur(24px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.35s var(--ease);
}

.sidebar-header {
    padding: 1.5rem 1.35rem 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    transition: opacity 0.2s;
}

.brand:hover { opacity: 0.88; }

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 6px 20px var(--glow);
}

.brand-mark-lg {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
    border-radius: 16px;
    margin: 0 auto 1.25rem;
}


.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-text strong {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-text span {
    font-size: 0.68rem;
    color: var(--text-3);
    font-weight: 500;
}

.brand h2 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand span {
    display: block;
    font-size: 0.68rem;
    color: var(--text-3);
    margin-top: 0.1rem;
}

.user-pill {
    margin: 0 1.35rem 1rem;
    padding: 0.65rem 0.85rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-2);
    word-break: break-all;
    animation: fadeUp 0.5s var(--ease) both;
}

.sidebar-compose {
    padding: 0 1.35rem 1.25rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0 0.85rem;
    overflow-y: auto;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 0.5rem 0.75rem 0.65rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.72rem 0.9rem;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 4px;
    position: relative;
    transition: all 0.25s var(--ease);
    animation: fadeUp 0.45s var(--ease) both;
}

.nav-item:nth-child(2) { animation-delay: 0.05s; }
.nav-item:nth-child(3) { animation-delay: 0.1s; }
.nav-item:nth-child(4) { animation-delay: 0.15s; }
.nav-item:nth-child(5) { animation-delay: 0.2s; }

.nav-item::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px; height: 60%;
    background: linear-gradient(var(--accent), var(--accent-2));
    border-radius: 0 4px 4px 0;
    transition: transform 0.25s var(--ease);
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
    transform: translateX(3px);
}

.nav-item.active {
    background: var(--accent-soft);
    color: #c4b5fd;
    border: 1px solid rgba(109, 106, 255, 0.22);
}

.nav-item.active::before {
    transform: translateY(-50%) scaleY(1);
}

.nav-icon {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.25s;
}

.nav-item.active .nav-icon {
    background: rgba(109, 106, 255, 0.18);
    color: #a5b4fc;
}

.badge {
    margin-left: auto;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    min-width: 1.25rem;
    text-align: center;
    animation: popIn 0.4s var(--ease);
}

@keyframes popIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.sidebar-footer {
    padding: 1rem 1.35rem 1.35rem;
    border-top: 1px solid var(--border);
}

/* ── Main ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - var(--sidebar));
}

.top-bar {
    height: 68px;
    padding: 0 1.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(5, 5, 8, 0.65);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border);
}

.top-bar h3 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    flex: 1;
}

.top-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.content-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 1.5rem clamp(1rem, 4vw, 3rem) 2.5rem;
    width: 100%;
}

.content-area {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    display: flex;
    flex-direction: column;
    animation: fadeUp 0.5s var(--ease) both;
}

.content-area > .panel,
.content-area > form.panel,
.content-area > .templates-layout,
.content-area > .calendar-layout {
    width: 100%;
    min-width: 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.72rem 1.3rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.25s var(--ease);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.15) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform 0.5s;
}

.btn:hover::after { transform: translateX(120%); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    box-shadow: 0 4px 20px var(--glow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px var(--glow);
    color: #fff;
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    border-color: var(--border-strong);
    background: rgba(255,255,255,0.07);
    color: var(--text);
}

.btn-ghost {
    width: 100%;
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-icon {
    width: 40px; height: 40px;
    padding: 0;
    border-radius: var(--radius-xs);
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-icon:hover { border-color: var(--border-strong); }

.btn-sm { padding: 0.55rem 1rem; font-size: 0.8125rem; }
.sidebar-compose .btn-primary { width: 100%; }

.menu-toggle { display: none; }

/* ── Forms ── */
.form-group { margin-bottom: 1.15rem; }

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 0.45rem;
    letter-spacing: 0.02em;
}

.form-control {
    width: 100%;
    padding: 0.82rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9375rem;
    transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}

.form-control:hover {
    border-color: var(--border-strong);
    background: rgba(255,255,255,0.045);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(109, 106, 255, 0.12);
    background: rgba(255,255,255,0.05);
}

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.75rem;
    cursor: pointer;
    color-scheme: dark;
    background-color: rgba(255, 255, 255, 0.03);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b6b82' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
}

select.form-control:hover {
    background-color: rgba(255, 255, 255, 0.045);
}

select.form-control:focus {
    background-color: rgba(255, 255, 255, 0.05);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a5b4fc' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

select.form-control option,
select.form-control optgroup {
    background: #12121c;
    color: #f8f8fc;
}

.custom-select {
    position: relative;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.custom-select-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-2);
}

.custom-select.is-open .custom-select-value,
.custom-select-trigger:focus .custom-select-value {
    color: var(--text);
}

.custom-select-chevron {
    flex-shrink: 0;
    color: var(--text-3);
    transition: transform 0.25s var(--ease), color 0.2s;
}

.custom-select.is-open .custom-select-chevron {
    transform: rotate(180deg);
    color: #a5b4fc;
}

.custom-select-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 70;
    margin: 0;
    padding: 0.35rem;
    list-style: none;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 240px;
    overflow-y: auto;
    animation: customSelectIn 0.22s var(--ease) both;
}

.custom-select-menu[hidden] {
    display: none !important;
}

.custom-select-menu li {
    padding: 0.7rem 0.85rem;
    font-size: 0.9rem;
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.custom-select-menu li:hover,
.custom-select-menu li:focus {
    background: var(--accent-soft);
    color: #fff;
    outline: none;
}

.custom-select-menu li.is-active {
    background: rgba(109, 106, 255, 0.22);
    color: #c4b5fd;
}

@keyframes customSelectIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.form-control-lg {
    min-height: 260px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

.email-suggest-wrap { position: relative; }

.email-suggest-list {
    position: absolute;
    top: calc(100% - 4px);
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 220px;
    overflow-y: auto;
}

.email-suggest-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.email-suggest-item:last-child { border-bottom: none; }
.email-suggest-item:hover,
.email-suggest-item.active { background: var(--surface-hover); }

.email-suggest-item strong {
    font-size: 0.85rem;
    font-weight: 600;
}

.email-suggest-item span {
    font-size: 0.75rem;
    color: var(--text-3);
}

.email-quick-picks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.55rem;
}

.email-chip {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 99px;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.15s;
}

.email-chip:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--accent-soft);
}

/* ── Panel / Card ── */
.panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: scaleIn 0.45s var(--ease) both;
    min-width: 0;
    max-width: 100%;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.97) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Alerts / Toast ── */
.alert {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    animation: slideToast 0.45s var(--ease);
    border: 1px solid transparent;
}

@keyframes slideToast {
    from { opacity: 0; transform: translateY(-12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.alert-error {
    background: rgba(251, 113, 133, 0.1);
    border-color: rgba(251, 113, 133, 0.25);
    color: #fda4af;
}

.alert-success {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.25);
    color: #6ee7b7;
}

.alert.is-hiding {
    animation: hideToast 0.35s var(--ease) forwards;
}

@keyframes hideToast {
    to { opacity: 0; transform: translateY(-8px); }
}

/* ── Mailbox Suche & Filter ── */
.mailbox-toolbar {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.mailbox-search {
    flex: 1;
    min-width: min(100%, 280px);
    display: grid;
    align-items: center;
}

.mailbox-search-icon {
    grid-area: 1 / 1;
    justify-self: start;
    margin-left: 0.85rem;
    display: block;
    color: var(--text-3);
    pointer-events: none;
}

.mailbox-search .form-control {
    grid-area: 1 / 1;
    padding-left: 2.5rem;
    min-height: 42px;
}

.mailbox-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mailbox-filters .form-control {
    min-width: 150px;
    min-height: 42px;
}

.mailbox-panel { width: 100%; }

.mailbox-live {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.mailbox-live-status {
    align-self: flex-end;
    font-size: 0.72rem;
    font-weight: 600;
    color: #6ee7b7;
    padding: 0.25rem 0.65rem;
    margin-bottom: 0.35rem;
    border-radius: 999px;
    background: rgba(52, 211, 153, 0.12);
    border: 1px solid rgba(52, 211, 153, 0.25);
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.3s, transform 0.3s;
}

.mailbox-live-status.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.mail-row.is-new {
    animation: mailRowNew 1.2s var(--ease) both;
    background: linear-gradient(90deg, rgba(52, 211, 153, 0.1), transparent);
}

@keyframes mailRowNew {
    from { opacity: 0.4; transform: translateX(-6px); }
    to { opacity: 1; transform: translateX(0); }
}

.mailbox-panel-sent .mail-list-header {
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.08), transparent);
}

.mail-party-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    margin-right: 0.35rem;
}

.mail-row-sent:hover {
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.06), var(--surface-hover));
}

.mail-sent-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(14, 165, 233, 0.12);
    color: #38bdf8;
    flex-shrink: 0;
}

.mail-row-forward-auto_forward {
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.08), transparent);
}

.mail-row-forward-auto_forward::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #fbbf24, #f59e0b);
}

.mail-row-forward-manual_forward {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.08), transparent);
}

.mail-row-forward-manual_forward::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #38bdf8, #0ea5e9);
}

.mail-forward-badge,
.mail-forward-inline-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.mail-forward-badge {
    width: 30px;
    height: 30px;
    justify-content: center;
    border-radius: 10px;
}

.mail-forward-badge.is-auto_forward {
    background: rgba(251, 191, 36, 0.14);
    color: #fbbf24;
}

.mail-forward-badge.is-manual_forward {
    background: rgba(56, 189, 248, 0.14);
    color: #38bdf8;
}

.mail-forward-inline-badge {
    margin-right: 0.4rem;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

.mail-forward-inline-badge.is-auto_forward {
    background: rgba(251, 191, 36, 0.14);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.28);
}

.mail-forward-inline-badge.is-manual_forward {
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.28);
}

/* ── Mail list ── */
.mail-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-3);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.mail-list { display: flex; flex-direction: column; }

.mail-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    color: inherit;
    position: relative;
    transition: all 0.22s var(--ease);
    animation: fadeUp 0.4s var(--ease) both;
}

.mail-row:nth-child(1) { animation-delay: 0.04s; }
.mail-row:nth-child(2) { animation-delay: 0.08s; }
.mail-row:nth-child(3) { animation-delay: 0.12s; }
.mail-row:nth-child(4) { animation-delay: 0.16s; }
.mail-row:nth-child(5) { animation-delay: 0.2s; }

.mail-row:last-child { border-bottom: none; }

.mail-row:hover {
    background: var(--surface-hover);
    padding-left: 1.4rem;
}

.mail-row:hover .mail-chevron {
    opacity: 1;
    transform: translateX(0);
}

.mail-row.unread {
    background: linear-gradient(90deg, rgba(109,106,255,0.07), transparent);
}

.mail-row.unread::after {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: linear-gradient(var(--accent), var(--accent-2));
}

.mail-row-forward-auto_forward.unread::after {
    background: linear-gradient(180deg, #fbbf24, #f59e0b);
}

.mail-row-forward-manual_forward.unread::after {
    background: linear-gradient(180deg, #38bdf8, #0ea5e9);
}

.avatar {
    width: 44px; height: 44px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: 0.03em;
    transition: transform 0.25s var(--ease);
}

.mail-row:hover .avatar { transform: scale(1.06); }

.mail-content { flex: 1; min-width: 0; }

.mail-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.2rem;
}

.mail-from {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mail-row:not(.unread) .mail-from { color: var(--text-2); font-weight: 500; }

.mail-date {
    font-size: 0.72rem;
    color: var(--text-3);
    flex-shrink: 0;
    padding: 0.2rem 0.5rem;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
}

.mail-subject {
    font-size: 0.84rem;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mail-row.unread .mail-subject {
    color: var(--text);
    font-weight: 500;
}

.mail-chevron {
    color: var(--text-3);
    opacity: 0;
    transform: translateX(-6px);
    transition: all 0.22s var(--ease);
    flex-shrink: 0;
}

.mail-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-3);
    margin-top: 1.25rem;
    padding: 0.65rem 1rem;
    background: var(--surface-hover);
    border-radius: 99px;
    align-self: center;
    max-width: 420px;
}

/* ── Empty state ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
    min-height: min(520px, calc(100vh - 180px));
    width: 100%;
}

.empty-icon {
    width: 80px; height: 80px;
    margin: 0 auto 1.5rem;
    border-radius: 22px;
    background: var(--accent-soft);
    border: 1px solid rgba(109,106,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a5b4fc;
    animation: float 4s ease-in-out infinite alternate;
}

.empty-state h4 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.empty-state p {
    color: var(--text-3);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* ── Mail view ── */
.mail-view-page {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.mail-view-back {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-2);
    width: fit-content;
    padding: 0.35rem 0.15rem;
    transition: color 0.2s;
}

.mail-view-back:hover { color: var(--text); }

.mail-view-shell {
    overflow: visible;
}

.mail-view-head {
    padding: 1.5rem 1.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent);
}

.mail-view-page.is-sent .mail-view-head {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(99, 102, 241, 0.06));
}

.mail-view-folder-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-3);
    margin-bottom: 0.75rem;
}

.mail-view-folder-badge.is-sent-badge {
    background: rgba(14, 165, 233, 0.15);
    border-color: rgba(14, 165, 233, 0.35);
    color: #7dd3fc;
}

.mail-view-forward-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.mail-view-forward-badge.is-auto_forward {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.3);
    color: #fcd34d;
}

.mail-view-forward-badge.is-manual_forward {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.3);
    color: #7dd3fc;
}

.mail-forward-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    margin-top: 0.85rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.5;
}

.mail-forward-notice.is-auto_forward {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.24);
    color: #fde68a;
}

.mail-forward-notice.is-manual_forward {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.24);
    color: #bae6fd;
}

.mail-forward-notice svg {
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.mail-forward-original {
    color: #fcd34d;
    font-weight: 600;
}

.mail-view-page.is-forward-auto_forward .mail-view-shell {
    border-color: rgba(251, 191, 36, 0.22);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(251, 191, 36, 0.08) inset;
}

.mail-view-page.is-forward-manual_forward .mail-view-shell {
    border-color: rgba(56, 189, 248, 0.22);
}

.mail-view-subject {
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.25;
    margin: 0 0 0.45rem;
}

.mail-view-dateline {
    font-size: 0.82rem;
    color: var(--text-3);
}

.mail-view-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    align-items: start;
}

.mail-view-side {
    padding: 1.35rem 1.25rem 1.5rem 1.5rem;
    border-right: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.mail-view-person {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.mail-view-avatar {
    width: 52px;
    height: 52px;
    font-size: 0.95rem;
    border-radius: 15px;
    flex-shrink: 0;
}

.mail-view-person-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.mail-view-person-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
}

.mail-view-person-text strong {
    font-size: 0.88rem;
    line-height: 1.35;
    word-break: break-word;
}

.mail-view-details {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
}

.mail-view-detail {
    display: grid;
    gap: 0.15rem;
}

.mail-view-detail dt {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
}

.mail-view-detail dd {
    font-size: 0.82rem;
    color: var(--text-2);
    line-height: 1.45;
    word-break: break-word;
    margin: 0;
}

.mail-view-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.mail-view-actions .btn { width: 100%; }

.mail-view-main {
    padding: 1.35rem 1.5rem 1.5rem;
    min-width: 0;
}

.mail-view-body-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mail-view-page.is-sent .mail-view-body-card {
    border-color: rgba(14, 165, 233, 0.18);
    background: linear-gradient(180deg, rgba(14, 165, 233, 0.04), rgba(255,255,255,0.02));
}

.mail-view-body {
    padding: 1.5rem 1.65rem;
    line-height: 1.8;
    font-size: 0.96rem;
    color: var(--text);
    animation: fadeUp 0.5s var(--ease) 0.1s both;
}

.mail-view-body pre {
    white-space: pre-wrap;
    font-family: inherit;
    margin: 0;
}

.mail-view-body p { margin: 0 0 0.85rem; }
.mail-view-body p:last-child { margin-bottom: 0; }

.mail-attachments {
    padding: 1rem 0 0;
    margin-top: 1rem;
    border-top: 1px dashed var(--border);
}

.mail-attachments h4 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 0.75rem;
}

.attachment-list { display: flex; flex-wrap: wrap; gap: 0.55rem; }

.attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.9rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    transition: all 0.2s var(--ease);
}

.attachment-item:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.attachment-item small { color: var(--text-3); }

/* ── Compose ── */
.compose-form { padding: 0; }

.compose-header {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-2);
}

.compose-fields {
    padding: 1.5rem 1.75rem;
}

.compose-actions {
    display: flex;
    gap: 0.65rem;
    padding: 0 1.75rem 1.5rem;
    flex-wrap: wrap;
}

/* ── KI-Schreibhilfe ── */
.ai-assistant {
    margin-bottom: 0.75rem;
    padding: 0.85rem 1rem;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.22);
    border-radius: var(--radius-md);
}

.ai-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ai-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.ai-toolbar-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.btn-ai {
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-ai:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.4);
}

.btn-ai:disabled,
.btn-ai.is-loading {
    opacity: 0.55;
    cursor: wait;
}

.ai-suggestions {
    margin-top: 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 0.15rem;
}

.ai-suggest-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.35;
}

.ai-suggest-fix {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.28);
}

.ai-suggest-hint {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.ai-suggest-msg {
    flex: 1;
    min-width: 0;
}

.ai-suggest-apply {
    flex-shrink: 0;
    padding: 0.3rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-suggest-apply:hover {
    filter: brightness(1.08);
}

.ai-suggest-dismiss {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.ai-suggest-dismiss:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.ai-preview {
    margin-top: 0.75rem;
    padding: 0.85rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.ai-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

.ai-preview-source {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

.ai-preview-text {
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0 0 0.5rem;
    color: var(--text);
    background: transparent;
    border: none;
    padding: 0;
}

.ai-preview-tips {
    margin: 0 0 0.65rem;
    padding-left: 1.1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ai-preview-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-sm {
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
}

/* ── Login ── */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.25rem;
    position: relative;
    z-index: 1;
    isolation: isolate;
}

.login-shell::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99, 102, 241, 0.18), transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(168, 85, 247, 0.1), transparent 55%);
    pointer-events: none;
    z-index: -1;
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 440px;
    margin-inline: auto;
    padding: 2.5rem 2.15rem 2.15rem;
    background: rgba(10, 10, 16, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 22px;
    backdrop-filter: blur(28px);
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(109, 106, 255, 0.08) inset;
    animation: loginCardIn 0.7s var(--ease) both;
    overflow: hidden;
}

.login-card-glow {
    position: absolute;
    top: -50%;
    left: 50%;
    transform: translateX(-50%);
    width: 140%;
    height: 60%;
    background: radial-gradient(ellipse, rgba(99, 102, 241, 0.28) 0%, transparent 68%);
    pointer-events: none;
    animation: loginGlowPulse 5s ease-in-out infinite;
}

.login-card-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 38%,
        rgba(255, 255, 255, 0.04) 48%,
        transparent 58%
    );
    background-size: 200% 100%;
    pointer-events: none;
    animation: loginShine 7s ease-in-out infinite;
}

.login-reveal {
    opacity: 0;
    animation: loginReveal 0.65s var(--ease) var(--d, 0s) both;
}

.login-head {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-bottom: 2rem;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.login-brand-mark {
    animation: loginMarkPulse 3s ease-in-out infinite;
}

.login-brand-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.15;
    text-align: left;
}

.login-brand-text strong {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.login-brand-text span {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-3);
}

.login-badge {
    display: block;
    width: fit-content;
    margin: 0 auto 1.15rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #c4b5fd;
    background: rgba(99, 102, 241, 0.14);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 999px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.login-badge.login-reveal {
    animation:
        loginReveal 0.65s var(--ease) var(--d, 0s) both,
        loginBadgeGlow 2.8s ease-in-out 0.75s infinite;
}

.login-title {
    text-align: center;
    max-width: 340px;
}

.login-title h1 {
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.035em;
    margin: 0 0 0.55rem;
    color: var(--text);
    background: linear-gradient(135deg, #fff 30%, #a5b4fc 90%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-title p {
    font-size: 0.875rem;
    color: var(--text-3);
    line-height: 1.6;
    margin: 0;
}

.login-form {
    position: relative;
}

.login-form .form-group {
    margin-bottom: 1.25rem;
}

.login-form .form-group label {
    margin-bottom: 0.5rem;
}

.login-input-wrap {
    position: relative;
    display: block;
}

.login-input-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
    z-index: 2;
    transition: color 0.25s, transform 0.25s var(--ease);
}

.login-input-wrap:focus-within .login-input-icon {
    color: #a5b4fc;
    transform: translateY(-50%) scale(1.08);
}

.login-input {
    width: 100%;
    padding-left: 2.75rem !important;
    min-height: 48px;
    background: rgba(255, 255, 255, 0.035);
    border-color: rgba(255, 255, 255, 0.09);
    transition:
        border-color 0.3s,
        box-shadow 0.3s,
        background 0.3s,
        transform 0.25s var(--ease);
}

.login-input:hover {
    background: rgba(255, 255, 255, 0.05);
}

.login-input:focus {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14);
    transform: translateY(-1px);
}

.login-submit {
    position: relative;
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.95rem 1.25rem;
    font-size: 0.94rem;
    justify-content: center;
    gap: 0.5rem;
    overflow: hidden;
    transition: transform 0.25s var(--ease), box-shadow 0.3s;
}

.login-submit::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.18),
        transparent
    );
    transform: translateX(-120%);
    transition: transform 0.55s var(--ease);
}

.login-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(109, 106, 255, 0.45);
}

.login-submit:hover::before {
    transform: translateX(120%);
}

.login-submit:active {
    transform: translateY(0);
}

.login-submit-arrow {
    transition: transform 0.25s var(--ease);
}

.login-submit:hover .login-submit-arrow {
    transform: translateX(4px);
}

.login-trust {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin-top: 1.75rem;
    padding-top: 1.35rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.login-trust span {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-3);
    transition: color 0.2s;
}

.login-trust span:hover {
    color: var(--text-2);
}

.login-trust svg {
    opacity: 0.75;
}

@keyframes loginCardIn {
    from {
        opacity: 0;
        transform: scale(0.94) translateY(24px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes loginReveal {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loginGlowPulse {
    0%, 100% { opacity: 0.55; transform: translateX(-50%) scale(1); }
    50% { opacity: 0.9; transform: translateX(-50%) scale(1.06); }
}

@keyframes loginShine {
    0%, 100% { background-position: 200% 0; }
    50% { background-position: -100% 0; }
}

@keyframes loginMarkPulse {
    0%, 100% { box-shadow: 0 6px 20px var(--glow); }
    50% { box-shadow: 0 8px 28px rgba(109, 106, 255, 0.65); }
}

@keyframes loginBadgeGlow {
    0%, 100% { box-shadow: 0 0 16px rgba(99, 102, 241, 0.12); }
    50% { box-shadow: 0 0 24px rgba(139, 92, 246, 0.28); }
}

@media (prefers-reduced-motion: reduce) {
    .login-card,
    .login-reveal,
    .login-card-glow,
    .login-card-shine,
    .login-brand-mark,
    .login-badge {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ── FAB (mobile compose) ── */
.fab {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px; height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    border: none;
    box-shadow: 0 8px 28px var(--glow);
    align-items: center;
    justify-content: center;
    z-index: 80;
    transition: transform 0.25s var(--ease);
    animation: popIn 0.5s var(--ease) 0.3s both;
}

.fab:hover { transform: scale(1.08); color: #fff; }

/* ── Overlay ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

.hide-mobile { display: inline-flex; }

/* ── Tablet ── */
@media (max-width: 1024px) {
    .login-shell { padding: 1.5rem 1rem; }
    .login-card { padding: 2rem 1.5rem 1.75rem; }
    .login-title h1 { font-size: 1.45rem; }

    .sidebar {
        width: min(86vw, 300px);
        transform: translateX(-100%);
        box-shadow: var(--shadow);
    }

    .sidebar.open { transform: translateX(0); }

    .main-content {
        margin-left: 0;
        width: 100%;
        min-width: 0;
    }

    .menu-toggle { display: inline-flex; }
    .hide-mobile { display: none !important; }

    .top-bar {
        height: auto;
        min-height: 60px;
        padding: 0.75rem 1rem;
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }

    .top-bar h3 {
        font-size: 1rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .content-wrapper {
        padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom));
    }

    .fab {
        display: flex;
        bottom: calc(1.25rem + env(safe-area-inset-bottom));
        right: calc(1.25rem + env(safe-area-inset-right));
    }

    .sidebar-compose { display: none; }

    .cal-day { min-height: 72px; }

    .mail-row:hover { padding-left: 1.25rem; }
    .mail-chevron { opacity: 0.5; transform: none; }

    .mailbox-toolbar { flex-direction: column; }
    .mailbox-filters { width: 100%; }

    .mail-view-layout { grid-template-columns: 1fr; }

    .mail-view-side {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .mail-view-head,
    .mail-view-side,
    .mail-view-main,
    .mail-view-body,
    .mail-attachments,
    .compose-fields,
    .compose-actions,
    .compose-header {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .compose-header { padding-top: 1.25rem; }
    .compose-actions { padding-bottom: 1.25rem; }

    .nav-item {
        min-height: 48px;
        padding: 0.8rem 0.95rem;
    }

    .btn, .btn-icon, .menu-toggle {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ── Calendar ── */
.calendar-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    width: 100%;
    min-width: 0;
    align-items: start;
}

@media (min-width: 1025px) {
    .calendar-layout {
        grid-template-columns: 1fr 320px;
        gap: 1.25rem;
    }
}

.calendar-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.calendar-toolbar h2 {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: 0.65rem 1rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    padding: 0 0.75rem 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cal-day {
    min-height: 88px;
    padding: 0.45rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    transition: background 0.2s;
}

.cal-day:hover { background: var(--surface-hover); }
.cal-day-empty { border-color: transparent; background: transparent; }
.cal-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(109,106,255,0.25); }

.cal-num {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-2);
    margin-bottom: 0.25rem;
}

.cal-event {
    display: block;
    font-size: 0.62rem;
    padding: 0.15rem 0.35rem;
    margin-bottom: 2px;
    border-left: 2px solid var(--accent);
    background: rgba(255,255,255,0.04);
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-2);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.cal-event:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}

.cal-more { font-size: 0.6rem; color: var(--text-3); }

.calendar-side { display: flex; flex-direction: column; gap: 1rem; }

.calendar-form, .calendar-events-list { padding: 1.15rem; }
.calendar-form h3, .calendar-events-list h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.form-check label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-2);
    cursor: pointer;
}

.cal-list-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.cal-list-item:last-child { border-bottom: none; }

.cal-list-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: 8px;
    margin: -0.2rem 0;
    padding: 0.2rem 0.35rem 0.2rem 0;
    transition: background 0.2s;
}

.cal-list-link:hover { background: var(--surface-hover); }

.cal-list-link .cal-list-body { flex: 1; }

.cal-list-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cal-list-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.cal-list-body strong {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-list-body span { font-size: 0.72rem; color: var(--text-3); }

.btn-delete {
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    line-height: 1;
}

.btn-delete:hover { background: rgba(251,113,133,0.15); color: #fb7185; }

.cal-empty { font-size: 0.85rem; color: var(--text-3); }

/* ── Calendar event detail ── */
.cal-event-view-page {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.cal-event-view-shell { overflow: visible; }

.cal-event-view-head {
    padding: 1.5rem 1.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    border-left: 4px solid var(--cal-event-color, var(--accent));
    background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent);
}

.cal-event-color-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-3);
    margin-bottom: 0.75rem;
}

.cal-event-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cal-event-color, var(--accent));
    flex-shrink: 0;
}

.cal-event-view-title {
    font-size: clamp(1.25rem, 2.5vw, 1.65rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.25;
    margin: 0 0 0.45rem;
}

.cal-event-view-dateline {
    font-size: 0.82rem;
    color: var(--text-3);
}

.cal-event-view-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    align-items: start;
    width: 100%;
    min-width: 0;
}

@media (min-width: 1025px) {
    .cal-event-view-layout {
        grid-template-columns: 260px 1fr;
    }
}

.cal-event-view-side {
    padding: 1.35rem 1.25rem 1.5rem 1.5rem;
    border-right: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.cal-event-view-side .mail-view-actions form { width: 100%; }

.cal-event-view-main {
    padding: 1.35rem 1.5rem 1.5rem;
    min-width: 0;
}

.cal-event-view-section-label {
    padding: 0.85rem 1.25rem 0;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
}

.cal-event-view-description { padding-top: 0.75rem; }

.cal-event-view-empty {
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--text-3);
    font-size: 0.9rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.02);
}

.btn-danger {
    width: 100%;
    background: rgba(251, 113, 133, 0.12);
    border: 1px solid rgba(251, 113, 133, 0.35);
    color: #fb7185;
}

.btn-danger:hover {
    background: rgba(251, 113, 133, 0.22);
    border-color: rgba(251, 113, 133, 0.5);
    color: #fda4af;
}

@media (max-width: 1024px) {
    .cal-event-view-side {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

/* ── Vorlagen ── */
.templates-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: start;
    width: 100%;
    min-width: 0;
}

.templates-layout > .panel,
.templates-layout > form.panel {
    min-width: 0;
    width: 100%;
}

@media (min-width: 1025px) {
    .templates-layout {
        grid-template-columns: 1.2fr 1fr;
        gap: 1.25rem;
    }
}

@media (max-width: 1024px) {
    .templates-layout:has(.templates-form input[name="template_id"]),
    .templates-layout:has(.templates-form input[name="rule_id"]) {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .templates-layout:has(.templates-form input[name="template_id"]) .templates-form,
    .templates-layout:has(.templates-form input[name="rule_id"]) .templates-form {
        order: -1;
    }
}

.templates-list-panel,
.templates-form {
    padding: 1.1rem 1.15rem;
}

@media (min-width: 769px) {
    .templates-list-panel,
    .templates-form {
        padding: 1.25rem 1.5rem;
    }
}

.templates-toolbar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-bottom: 0.35rem;
}

.templates-toolbar h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.templates-badge {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.templates-intro {
    font-size: 0.85rem;
    color: var(--text-3);
    margin-bottom: 1rem;
}

.templates-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-card {
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.02);
}

.template-card-head {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.45rem;
}

.template-card-head strong { font-size: 0.92rem; }

.template-card-desc {
    font-size: 0.75rem;
    color: var(--text-3);
}

.template-card-subject {
    font-size: 0.78rem;
    color: var(--text-2);
    margin-bottom: 0.35rem;
}

.template-card-body {
    font-family: inherit;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-3);
    white-space: pre-wrap;
    margin: 0 0 0.55rem;
    background: transparent;
    border: none;
    padding: 0;
}

.template-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.72rem;
    color: var(--text-3);
}

.template-card-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.template-delete-form { display: inline; margin: 0; }

.templates-form h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.templates-form-actions {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-3);
    margin-top: 0.35rem;
}

.form-hint code {
    font-size: 0.72rem;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.compose-template-pick { margin-bottom: 0.25rem; }

.ai-learn-hint {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-3);
    margin-left: 0.35rem;
}

.writing-rules-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-height: 70vh;
    overflow-y: auto;
}

.writing-rule-card {
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.02);
}

.writing-rule-card.is-inactive { opacity: 0.55; }

.writing-rule-head {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.4rem;
}

.writing-rule-head strong { font-size: 0.88rem; }

.writing-rule-badges {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.writing-rule-type,
.writing-rule-source {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-3);
}

.writing-rule-source.is-learned {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.3);
    color: #6ee7b7;
}

.writing-rule-pattern {
    font-size: 0.78rem;
    color: var(--text-3);
    margin-bottom: 0.45rem;
    word-break: break-word;
}

.writing-rule-pattern code {
    font-size: 0.72rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

.writing-rule-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.72rem;
    color: var(--text-3);
}

.schreibhilfe-layout .templates-list-panel { max-height: none; }

.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 0.35rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Handy ── */
@media (max-width: 768px) {
    html { font-size: 15px; }

    .content-wrapper { padding: 0.85rem 0.85rem calc(5.5rem + env(safe-area-inset-bottom)); }

    .panel { border-radius: var(--radius-sm); }

    .mail-list-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        padding: 0.85rem 1rem;
    }

    .mail-row {
        gap: 0.75rem;
        padding: 0.9rem 1rem;
        align-items: flex-start;
    }

    .mail-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
    }

    .mail-date { align-self: flex-start; }

    .mail-chevron {
        position: absolute;
        right: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        opacity: 0.35;
    }

    .mail-content { padding-right: 1.5rem; }

    .mail-view-subject { font-size: 1.15rem; }

    .mail-view-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .mail-view-actions .btn { width: 100%; }

    .mailbox-filters .btn { width: 100%; }

    .calendar-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.9rem 1rem;
    }

    .calendar-toolbar h2 {
        order: -1;
        width: 100%;
        text-align: left;
        font-size: 1rem;
    }

    .calendar-weekdays {
        font-size: 0.6rem;
        padding: 0.5rem 0.35rem 0.25rem;
    }

    .calendar-grid {
        gap: 3px;
        padding: 0 0.35rem 0.85rem;
    }

    .cal-day { min-height: 56px; padding: 0.3rem; }

    .cal-event { font-size: 0; padding: 0; border: none; height: 4px; border-radius: 99px; background: var(--accent); }

    .form-row { grid-template-columns: 1fr; }

    .templates-toolbar h2 { font-size: 1rem; }

    .templates-intro { font-size: 0.8rem; }

    .template-card {
        padding: 0.85rem 0.9rem;
    }

    .template-card-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.65rem;
    }

    .template-card-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .template-card-actions .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 0.2rem);
        justify-content: center;
    }

    .templates-form h3 { font-size: 0.9rem; }

    .templates-form .form-control-lg {
        min-height: 200px;
    }

    .templates-form-actions {
        flex-direction: column;
    }

    .templates-form-actions .btn {
        width: 100%;
    }

    .writing-rule-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.55rem;
    }

    .writing-rule-meta .template-card-actions {
        width: 100%;
    }

    .writing-rules-list {
        max-height: none;
    }

    .email-quick-picks {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 0.25rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .email-quick-picks::-webkit-scrollbar { display: none; }

    .email-chip { flex-shrink: 0; }

    .email-suggest-list {
        position: fixed;
        left: 0.85rem;
        right: 0.85rem;
        top: auto;
        max-height: 40vh;
    }

    .empty-state {
        min-height: auto;
        padding: 3rem 1.25rem;
    }

    .login-card {
        padding: 1.85rem 1.2rem 1.65rem;
        border-radius: 18px;
    }

    .login-title h1 { font-size: 1.35rem; }
    .login-trust { gap: 0.55rem 0.85rem; }

    .user-pill { margin: 0 1rem 1rem; font-size: 0.7rem; }
    .sidebar-header { padding: 1.25rem 1rem 0.85rem; }
    .sidebar-nav { padding: 0 0.65rem; }
    .sidebar-footer { padding: 1rem; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
}

/* ── Kleine Handys ── */
@media (max-width: 480px) {
    html { font-size: 14px; }

    .compose-actions { flex-direction: column; }
    .compose-actions .btn { width: 100%; }

    .ai-toolbar { flex-direction: column; align-items: flex-start; }
    .ai-toolbar-btns { width: 100%; }
    .ai-suggest-item { flex-wrap: wrap; }
    .ai-suggest-apply { width: 100%; text-align: center; }
    .ai-preview-actions { flex-direction: column; }
    .ai-preview-actions .btn { width: 100%; }

    .avatar { width: 38px; height: 38px; font-size: 0.7rem; }

    .brand-text strong { font-size: 0.85rem; }

    .top-bar h3 { font-size: 0.95rem; }

    .cal-day { min-height: 46px; }
    .cal-num { font-size: 0.68rem; }

    .calendar-form, .calendar-events-list { padding: 1rem; }

    .alert {
        font-size: 0.8rem;
        padding: 0.75rem 0.9rem;
    }
}

/* ── Landscape Handy ── */
@media (max-width: 900px) and (orientation: landscape) {
    .empty-state { min-height: auto; padding: 2rem 1rem; }
    .content-wrapper { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
    .fab { bottom: calc(0.85rem + env(safe-area-inset-bottom)); }
}
