:root {
    color-scheme: light;
    --navy: #102f4c;
    --header-blue: #1f6dc8;
    --navy-deep: #0b2238;
    --gold: #f2ca6b;
    --action-blue: #175bc1;
    --cyan: #19bce5;
    --selected: #eaf2ff;
    --cream: #f2f5f9;
    --paper: #fffcf5;
    --ink: #102f4c;
    --muted: #50647b;
    --danger: #ab3038;
    --success: #24644a;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 15% 10%, rgba(244, 201, 93, .25), transparent 28rem),
        linear-gradient(145deg, var(--cream), #edf3f6);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: min(100%, 34rem);
    padding: clamp(1.5rem, 5vw, 3rem);
    border: 1px solid rgba(16, 47, 76, .14);
    border-radius: 1.5rem;
    background: rgba(255, 253, 248, .96);
    box-shadow: 0 1.5rem 4rem rgba(11, 34, 56, .16);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 4rem;
    height: 4rem;
    border-radius: 1.15rem;
    overflow: hidden;
    color: transparent;
    background: #fff url("icons/morga-icon-64.png") center / cover no-repeat;
    box-shadow: 0 .3rem 1rem rgba(11, 34, 56, .18);
    font-weight: 800;
    letter-spacing: -.04em;
}

.eyebrow {
    margin: 1.5rem 0 .35rem;
    color: var(--navy);
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

h1 {
    margin: 0 0 1.5rem;
    color: var(--navy-deep);
    font-size: clamp(2rem, 7vw, 3rem);
    line-height: 1.05;
}

form { display: grid; gap: .75rem; }
label { margin-top: .35rem; font-weight: 700; }

input {
    width: 100%;
    min-height: 3.25rem;
    border: 1px solid #aeb8c0;
    border-radius: .8rem;
    padding: .75rem 1rem;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

select, textarea {
    width: 100%; min-height: 3.1rem; border: 1px solid #aeb8c0; border-radius: .8rem;
    padding: .7rem .9rem; color: var(--ink); background: #fff; font: inherit;
}

input:focus-visible, .button:focus-visible {
    outline: 3px solid rgba(244, 201, 93, .8);
    outline-offset: 3px;
}

.help, .status { color: var(--muted); line-height: 1.55; }
.help { margin: -.2rem 0 .3rem; font-size: .92rem; }
.status.success { color: var(--success); }
.status.error { color: var(--danger); }

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 3.25rem;
    margin-top: .75rem;
    border: 0;
    border-radius: 999px;
    padding: .8rem 1.4rem;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button.primary { color: #fff; background: var(--action-blue); }
.button.secondary { color: #fff; background: var(--navy); }
.button:disabled { cursor: wait; opacity: .65; }
.hidden { display: none !important; }

.portal-shell { width: min(100% - 2rem, 62rem); margin: 0 auto; padding: clamp(1.5rem, 5vw, 4rem) 0; }
.portal-header { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.5rem; }
.portal-header .eyebrow, .portal-header h1 { margin: 0; }
.language-switcher { display: grid; gap: .3rem; margin-left: auto; color: var(--navy); font-size: .82rem; font-weight: 750; }
.language-switcher select { min-height: 2.5rem; border: 1px solid rgba(16, 47, 76, .25); border-radius: 999px; padding: .45rem 2rem .45rem .85rem; color: var(--navy); background: var(--paper); font: inherit; }
.auth-language { float: right; margin-top: -4rem; }
.portal-card { padding: clamp(1.35rem, 4vw, 2.5rem); border: 1px solid rgba(16, 47, 76, .14); border-radius: 1.5rem; background: rgba(255, 253, 248, .97); box-shadow: 0 1.5rem 4rem rgba(11, 34, 56, .14); }
h2 { margin: 0 0 .5rem; color: var(--navy-deep); font-size: clamp(1.6rem, 4vw, 2.2rem); }
h3 { margin-top: 2rem; color: var(--navy-deep); }
.intro { margin: 0 0 1.5rem; color: var(--muted); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1.5rem; }
.tab { min-height: 2.9rem; border: 1px solid rgba(16, 47, 76, .25); border-radius: 999px; padding: .6rem .8rem; color: var(--navy); background: transparent; font: inherit; font-weight: 750; cursor: pointer; }
.tab.active { border-color: var(--gold); background: var(--gold); }
.auth-form { max-width: 34rem; }
.account-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.account-heading .eyebrow { margin-top: 0; }
.button.compact { min-height: 2.75rem; margin-top: 0; }
.account-data { display: grid; gap: .75rem; margin: 1.5rem 0; }
.account-data div { display: grid; grid-template-columns: minmax(7rem, .35fr) 1fr; gap: 1rem; }
.account-data dt { color: var(--muted); font-weight: 700; }
.account-data dd { margin: 0; overflow-wrap: anywhere; }
.device-list { display: grid; gap: .75rem; padding: 0; list-style: none; }
.device-list li { display: grid; gap: .2rem; padding: 1rem; border-radius: 1rem; background: var(--cream); }
.device-list span { color: var(--muted); font-size: .92rem; }

.download-card { max-width: 46rem; margin: 0 auto; }
.download-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.25rem; }
.download-heading .intro { margin: .35rem 0 0; }
.download-links { display: grid; gap: .8rem; margin-top: 1.5rem; }
.download-link {
    display: grid; grid-template-columns: 3rem minmax(0, 1fr); align-items: center; gap: 1rem;
    min-height: 5rem; border: 1px solid rgba(16, 47, 76, .2); border-radius: 1rem; padding: .85rem 1.15rem;
    color: var(--navy-deep); background: #fff; text-decoration: none; box-shadow: 0 .2rem .75rem rgba(11, 34, 56, .06);
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.download-link:hover { transform: translateY(-2px); border-color: var(--gold); box-shadow: 0 .5rem 1.2rem rgba(11, 34, 56, .1); }
.download-link:focus-visible { outline: 3px solid rgba(244, 201, 93, .8); outline-offset: 3px; }
.download-link strong, .download-link small { display: block; }
.download-link strong { font-size: 1.05rem; }
.download-link small { margin-top: .2rem; color: var(--muted); }
.download-platform { display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: .85rem; color: #fff; background: var(--navy); font-size: 1.35rem; font-weight: 900; }
.android-platform { color: var(--navy-deep); background: var(--gold); }
.web-access-link { border-color: rgba(244, 201, 93, .75); background: #fff9e9; }

/* Authenticated mail and calendar workspace */
.webapp { min-height: 100vh; background: #e9eef1; }
.app-topbar {
    position: fixed; z-index: 20; inset: 0 0 auto 0; height: 4.75rem; display: flex; align-items: center;
    gap: 1rem; padding: .65rem 1.25rem; color: #fff; background: var(--header-blue); box-shadow: 0 1px 8px rgba(0,0,0,.24);
}
.app-brand { display: flex; align-items: center; gap: .7rem; min-width: 12.5rem; font-size: 1.2rem; }
.mini-brand { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; overflow: hidden; border-radius: .8rem; color: transparent; background: #fff url("icons/morga-icon-64.png") center / cover no-repeat; box-shadow: 0 .15rem .5rem rgba(0,0,0,.28); font-weight: 900; }
.account-picker { display: grid; grid-template-columns: auto minmax(12rem, 22rem); align-items: center; gap: .55rem; margin: 0; font-size: .78rem; }
.account-picker select { min-height: 2.7rem; border-color: rgba(255,255,255,.3); color: #fff; background: #173b5d; }
.account-picker select option, .app-language select option { color: var(--ink); background: #fff; }
.sync-indicator { margin-left: auto; color: #fff; font-size: .78rem; }
.app-language { margin: 0; color: #fff; }
.app-language span { display: none; }
.app-language select { min-width: 8rem; color: #fff; background: #173b5d; }
.app-sidebar {
    position: fixed; z-index: 12; inset: 4.75rem auto 0 0; width: 14rem; display: flex; flex-direction: column;
    padding: 1.25rem .8rem; color: #fff; background: var(--navy); box-shadow: 2px 0 10px rgba(11,34,56,.16);
}
.primary-nav { display: grid; gap: .45rem; }
.nav-button { display: flex; align-items: center; gap: .9rem; min-height: 3.2rem; border: 0; border-radius: .8rem; padding: .7rem 1rem; color: #d9e4eb; background: transparent; font: inherit; font-weight: 750; text-align: left; cursor: pointer; }
.nav-button span:first-child { width: 1.5rem; font-size: 1.25rem; text-align: center; }
.nav-button:hover, .nav-button.active { color: #fff; background: rgba(244,201,93,.18); }
.nav-button.active { box-shadow: inset 3px 0 var(--gold); }
.sidebar-user { display: grid; gap: .25rem; margin-top: auto; padding: 1rem .7rem; border-top: 1px solid rgba(255,255,255,.15); overflow: hidden; }
.sidebar-user span { color: #adc0cc; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; }
.app-content { min-height: 100vh; margin-left: 14rem; padding-top: 4.75rem; }
.app-view { min-height: calc(100vh - 4.75rem); }
.mail-layout { display: grid; grid-template-columns: 15rem minmax(20rem, 25rem) minmax(25rem, 1fr); }
.folder-pane, .message-pane, .reader-pane { min-height: calc(100vh - 4.75rem); background: var(--paper); }
.folder-pane, .message-pane { border-right: 1px solid #d8dee2; }
.pane-heading { min-height: 6.4rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1.25rem; border-bottom: 1px solid #dde2e5; }
.pane-heading h2, .calendar-toolbar h2, .settings-heading h2 { margin: .15rem 0 0; font-size: 1.45rem; }
.overline { color: #6a7882; font-size: .72rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.icon-button { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; flex: 0 0 auto; border: 1px solid #c8d0d6; border-radius: 50%; color: var(--navy); background: #fff; font: 700 1.25rem/1 sans-serif; cursor: pointer; }
.icon-button:hover { border-color: var(--gold); background: #fff9e9; }
.icon-button.active { border-color: var(--gold); background: #fff1bd; }
.icon-button.danger { color: var(--danger); }
.command-icon { width: 1.25rem; height: 1.25rem; display: block; }
.toolbar { display: flex; gap: .5rem; }
.compose-button { display: flex; align-items: center; justify-content: center; gap: .55rem; width: calc(100% - 2rem); min-height: 3rem; margin: 1rem; border: 0; border-radius: 999px; color: var(--navy-deep); background: var(--gold); font: inherit; font-weight: 850; }
.compose-button:disabled, .reader-footer button:disabled, .invitation-actions button:disabled { opacity: .58; cursor: not-allowed; }
.folder-list, .message-list, .account-list { margin: 0; padding: 0; list-style: none; }
.folder-list { max-height: calc(100vh - 15rem); overflow: auto; }
.folder-item button { width: 100%; display: grid; grid-template-columns: 1.5rem 1fr auto; gap: .65rem; align-items: center; min-height: 2.85rem; border: 0; padding: .55rem 1.15rem; color: #32434d; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.folder-item button:hover, .folder-item.active button { color: var(--navy-deep); background: #edf3f5; }
.folder-item.active button { box-shadow: inset 3px 0 var(--gold); font-weight: 800; }
.folder-item.drop-target button { color: var(--navy-deep); background: #fff1bd; box-shadow: inset 4px 0 var(--gold); }
.folder-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-role { color: #84939c; font-size: .73rem; }
.inline-status { margin: 1rem; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.message-pane { min-width: 0; }
.mailbox-heading-copy { min-width: 0; flex: 1; }
.folder-select-label { display: grid; grid-template-columns: auto minmax(8rem, 15rem); align-items: center; gap: .45rem; margin-top: .45rem; color: var(--muted); font-size: .72rem; }
.folder-select-label select { min-height: 2.25rem; padding: .25rem 1.8rem .25rem .55rem; border-radius: .55rem; font-size: .78rem; }
.message-list { height: calc(100vh - 11.15rem); overflow: auto; }
.selection-toolbar { display: grid; grid-template-columns: auto minmax(10rem,1fr) repeat(4,auto); align-items: end; gap: .55rem; padding: .7rem .8rem; border-bottom: 1px solid #d8dee2; background: #edf3f5; }
.selection-toolbar > strong { align-self: center; white-space: nowrap; }
.selection-toolbar label { display: grid; gap: .2rem; margin: 0; color: var(--muted); font-size: .72rem; }
.selection-toolbar select { min-height: 2.25rem; padding: .3rem 1.8rem .3rem .55rem; border-radius: .55rem; font-size: .8rem; }
.selection-toolbar .small-button { min-height: 2.25rem; white-space: nowrap; }
.icon-text-button { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
.message-pane.selection-active .message-list { height: calc(100vh - 15.8rem); }
.message-row { display: grid; grid-template-columns: 2.6rem minmax(0,1fr); gap: .8rem; min-height: var(--mail-row-height, 84px); padding: .75rem 1rem; border-bottom: 1px solid #e0e4e6; background: #fff; cursor: pointer; }
.message-row:hover, .message-row.active { background: #f8f2e5; }
.message-row.selected { background: #fff1bd; box-shadow: inset 4px 0 var(--gold); }
.message-row.dragging { opacity: .48; }
.message-row.unread .message-subject, .message-row.unread .message-sender { font-weight: 850; }
.sender-avatar { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; align-self: center; border-radius: 50%; color: #fff; background: var(--navy); font-weight: 850; }
.message-copy { min-width: 0; display: grid; align-content: center; gap: .15rem; }
.message-line { display: flex; gap: .5rem; align-items: baseline; min-width: 0; }
.message-subject, .message-sender, .message-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.15rem; }
.message-subject { flex: 1; color: #17212a; }
.message-time { flex: 0 0 auto; color: #75848e; font-size: .76rem; }
.message-sender { color: #394a55; font-size: .9rem; }
.message-preview { color: #74818a; font-size: .84rem; }
.empty-state { display: grid; place-items: center; min-height: 12rem; padding: 2rem; color: var(--muted); text-align: center; }
.reader-pane { min-width: 0; overflow: auto; }
.empty-reader { min-height: calc(100vh - 4.75rem); display: grid; place-content: center; justify-items: center; padding: 2rem; color: #7c8a93; text-align: center; }
.empty-reader > span { font-size: 3rem; opacity: .45; }
.empty-reader h2 { margin: 1rem 0 .35rem; color: #53636d; }
.empty-reader p { margin: 0; }
.reader-content { min-height: calc(100vh - 4.75rem); padding: clamp(1.5rem,3vw,3rem); }
.reader-header { display: flex; justify-content: space-between; gap: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid #e0e4e6; }
.reader-header h1 { max-width: 48rem; margin: .35rem 0 1rem; font-size: clamp(1.6rem,3vw,2.25rem); }
.reader-actions { display: flex; gap: .5rem; }
.reader-body { max-width: 55rem; padding: 2rem 0; color: #273640; font-size: calc(1rem * var(--reading-text-scale, 1)); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-body.html-message { max-width: none; white-space: normal; }
.external-image-controls { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 55rem; margin-bottom: .75rem; padding: .7rem .85rem; border-radius: .65rem; color: var(--muted); background: #f0f4f6; font-size: .82rem; }
.mail-html-frame { display: block; width: 100%; height: min(72rem,65vh); min-height: 26rem; border: 1px solid #dce2e5; border-radius: .7rem; background: #fff; }
.reader-footer { position: sticky; bottom: 0; display: flex; gap: .7rem; padding: 1rem 0; background: linear-gradient(transparent, var(--paper) 25%); }
.reader-footer button, .invitation-actions button { min-height: 2.75rem; border: 1px solid #c4cdd2; border-radius: 999px; padding: .6rem 1rem; color: var(--navy); background: #fff; font: inherit; font-weight: 750; }
.invitation-card { max-width: 50rem; margin: 1.5rem 0 0; padding: 1.2rem; border-left: 4px solid var(--gold); border-radius: .8rem; background: #fff7df; }
.invitation-card h3 { margin: .35rem 0; }
.invitation-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 .5rem; }
.attachments ul { display: grid; gap: .5rem; padding: 0; list-style: none; }
.attachments li { padding: .8rem 1rem; border: 1px solid #d6dcdf; border-radius: .7rem; }
.muted { color: var(--muted); }

.mail-compose-dialog { width: min(46rem,calc(100vw - 2rem)); max-height: calc(100vh - 2rem); border: 0; border-radius: 1.1rem; padding: 0; color: var(--ink); background: var(--paper); box-shadow: 0 1.5rem 5rem rgba(11,34,56,.35); }
.mail-compose-dialog::backdrop { background: rgba(7,27,45,.58); }
.mail-compose-dialog form { gap: .75rem; padding: 1.25rem; }
.mail-compose-dialog header, .mail-compose-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.mail-compose-dialog header { padding-bottom: .75rem; border-bottom: 1px solid #d8dee2; }
.mail-compose-dialog header h2 { margin: .1rem 0 0; }
.mail-compose-dialog label { display: grid; gap: .3rem; margin: 0; }
.mail-compose-dialog textarea { min-height: 18rem; resize: vertical; line-height: 1.45; }
.mail-compose-dialog footer { justify-content: flex-end; padding-top: .25rem; }

.calendar-view, .settings-view { padding: clamp(1rem,3vw,2rem); background: #f3f5f6; }
.calendar-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.text-button { min-height: 2.7rem; border: 1px solid #c8d0d6; border-radius: 999px; padding: .5rem 1rem; color: var(--navy); background: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.calendar-week { display: grid; grid-template-columns: repeat(7,minmax(8rem,1fr)); min-height: calc(100vh - 11rem); border: 1px solid #d4dade; border-radius: 1rem; overflow: auto; background: #fff; }
.calendar-day { min-width: 8rem; border-right: 1px solid #dfe4e7; background: var(--calendar-day-tint,#fff); }
.calendar-day:last-child { border-right: 0; }
.calendar-day-header { position: sticky; top: 0; z-index: 2; padding: 1rem .75rem; border-bottom: 1px solid #dfe4e7; background: var(--calendar-day-tint,#f8fafb); text-align: center; }
.calendar-day.today .calendar-day-header { color: var(--navy-deep); font-weight: 800; }
.calendar-events { display: grid; gap: .55rem; padding: .65rem; }
.calendar-event { padding: .75rem; border-left: 4px solid var(--navy); border-radius: .55rem; background: #eaf1f5; font-size: .82rem; }
.calendar-event strong, .calendar-event span { display: block; }
.calendar-event span { margin-top: .2rem; color: #5f6e77; }

.settings-view { max-width: 86rem; margin: 0 auto; }
.settings-heading { margin-bottom: 1rem; }
.settings-tabs { display: flex; gap: .4rem; margin-bottom: 1rem; border-bottom: 1px solid #ccd4d9; }
.settings-tab { border: 0; border-bottom: 3px solid transparent; padding: .8rem 1.2rem; color: #5b6972; background: transparent; font: inherit; font-weight: 800; cursor: pointer; }
.settings-tab.active { border-color: var(--gold); color: var(--navy); }
.settings-card { margin-bottom: 1rem; padding: 1.35rem; border: 1px solid #d5dcdf; border-radius: 1rem; background: #fff; box-shadow: 0 .5rem 1.8rem rgba(11,34,56,.06); }
.settings-card h3 { margin: 0 0 .45rem; }
.settings-card p { color: var(--muted); }
.calendar-color-form input[type="color"] { width: 100%; min-height: 3rem; padding: .25rem; cursor: pointer; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.account-list { display: grid; gap: .6rem; margin-top: 1rem; }
.account-list li { display: flex; align-items: center; gap: 1rem; padding: .85rem 1rem; border-radius: .75rem; background: #f2f5f6; }
.account-list li > div { min-width: 0; flex: 1; }
.account-list span { display: block; color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; }
.small-button { border: 1px solid #c8d0d6; border-radius: 999px; padding: .45rem .8rem; color: var(--navy); background: #fff; font: inherit; font-size: .8rem; font-weight: 750; cursor: pointer; }
.small-button.danger { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.form-grid label { display: grid; gap: .4rem; margin: 0; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 1rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.mobile-only { display: none; }

@media (max-width: 40rem) {
    .download-heading { display: grid; }
    .download-heading .button { justify-self: start; }
    .portal-header { align-items: flex-start; flex-wrap: wrap; }
    .portal-header .language-switcher { width: 100%; margin-left: 0; }
    .language-switcher select { width: 100%; }
    .auth-language { float: none; margin: 1rem 0 0; }
    .tabs { grid-template-columns: 1fr; }
    .account-heading { align-items: stretch; flex-direction: column; }
    .account-data div { grid-template-columns: 1fr; gap: .2rem; }
}

@media (max-width: 78rem) {
    .mail-layout { grid-template-columns: 13rem minmax(19rem,24rem) minmax(22rem,1fr); }
    .app-sidebar { width: 5rem; }
    .app-sidebar .nav-button span:last-child, .sidebar-user { display: none; }
    .app-sidebar .nav-button { justify-content: center; padding: .7rem; }
    .app-content { margin-left: 5rem; }
    .app-brand { min-width: auto; }
    .app-brand strong { display: none; }
}

@media (max-width: 62rem) {
    .mail-layout { grid-template-columns: 13rem minmax(19rem,1fr); }
    .reader-pane { position: fixed; z-index: 15; inset: 4.75rem 0 0 5rem; display: none; }
    .reader-pane.open { display: block; }
    .calendar-week { grid-template-columns: 1fr; }
    .calendar-day { border-right: 0; border-bottom: 1px solid #dfe4e7; }
    .settings-grid { grid-template-columns: 1fr; }
    .sync-indicator { display: none; }
    .selection-toolbar { grid-template-columns: minmax(8rem,1fr) repeat(3,auto); }
    .selection-toolbar > strong { grid-column: 1 / -1; }
    .selection-toolbar #selection-exit { grid-column: 1 / -1; justify-self: end; }
}

@media (max-width: 44rem) {
    .app-topbar { height: 4.25rem; padding: .5rem .65rem; }
    .mobile-only { display: grid; }
    .app-brand { display: none; }
    .account-picker { grid-template-columns: minmax(0,1fr); flex: 1; }
    .account-picker span, .app-language { display: none; }
    .account-picker select { min-width: 0; }
    .app-topbar .button { min-height: 2.6rem; padding: .5rem .8rem; font-size: .78rem; }
    .app-sidebar { inset: 4.25rem auto 0 -15rem; width: 14rem; transition: left .2s ease; }
    .app-sidebar.open { left: 0; }
    .app-sidebar .nav-button span:last-child, .sidebar-user { display: initial; }
    .app-sidebar .nav-button { justify-content: flex-start; padding: .7rem 1rem; }
    .app-content { margin-left: 0; padding-top: 4.25rem; }
    .app-view { min-height: calc(100vh - 4.25rem); }
    .mail-layout { grid-template-columns: 1fr; }
    .folder-pane { position: fixed; z-index: 14; inset: 4.25rem auto 0 0; width: min(88vw,19rem); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 1rem 0 2rem rgba(11,34,56,.22); }
    .folder-pane.open { transform: translateX(0); }
    .message-pane { border: 0; }
    .reader-pane { inset: 4.25rem 0 0 0; }
    .pane-heading { min-height: 5.4rem; }
    .message-list { height: calc(100vh - 9.65rem); }
    .selection-toolbar { grid-template-columns: 1fr 1fr; align-items: stretch; }
    .selection-toolbar > strong, .selection-toolbar label, .selection-toolbar #selection-exit { grid-column: 1 / -1; }
    .selection-toolbar .small-button { white-space: normal; }
    .message-pane.selection-active .message-list { height: calc(100vh - 24rem); }
    .calendar-toolbar { align-items: flex-start; flex-direction: column; }
    .calendar-view, .settings-view { padding: 1rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .wide { grid-column: auto; }
    .card-heading { flex-direction: column; }
    .settings-tabs { overflow-x: auto; }
}

/* Database workspace: calendar/contact records only. */
.database-app .app-topbar { display:flex; gap:.8rem; }
.database-app .app-brand { margin-right:auto; min-width:8rem; }
.database-app .nav-button { position:relative; }
.database-app .nav-button.active { background:rgba(255,255,255,.12); box-shadow:none; }
.database-app .nav-button.active::before { content:"";position:absolute;inset:0 auto 0 0;width:28px;border:3px solid var(--gold);border-right:0;border-radius:12px 0 0 12px;mask-image:linear-gradient(to right,#000,transparent);pointer-events:none; }
.db-view { padding:1.25rem; }
.db-toolbar { display:flex;justify-content:space-between;align-items:center;gap:1rem;flex-wrap:wrap;margin-bottom:1rem; }
.db-toolbar h2 { margin:0; }
.db-toolbar .button { margin:0; }
.db-filters { display:flex;gap:.8rem;align-items:end;flex-wrap:wrap;margin-bottom:1rem; }
.db-filters label { display:grid;gap:.35rem;flex:1;min-width:12rem; }
.db-filters .button { min-height:3.1rem;margin:0; }
.db-status { margin:0;padding:.5rem 1.25rem; }
.db-status:empty { display:none; }
.db-unlock { margin:1.25rem;max-width:40rem; }
.sidebar-download { color:#fff;margin-top:1.5rem;text-align:left; }
.db-calendar-week { display:grid;grid-template-columns:repeat(7,minmax(120px,1fr));overflow-x:auto;gap:1px;background:var(--line,#dce3ec);border:1px solid #dce3ec;border-radius:12px; }
.db-calendar-day { min-height:360px;background:var(--paper);padding:.6rem; }
.db-calendar-day h3 { font-size:.9rem;margin:.3rem 0 1rem; }
.db-event { display:grid;gap:.4rem;width:100%;text-align:left;padding:.7rem;margin-bottom:.6rem;background:var(--selected);color:var(--ink);border:1px solid #ccd9ec;border-left:3px solid var(--action-blue);border-radius:9px;font:inherit;cursor:pointer;overflow-wrap:anywhere; }
.db-event span,.db-event small { font-size:.78rem;color:var(--muted); }
.db-contacts-layout { display:grid;grid-template-columns:minmax(220px,1fr) minmax(280px,2fr);border:1px solid #dce3ec;border-radius:12px;background:var(--paper);overflow:hidden; }
.db-contact-list { list-style:none;margin:0;padding:0;max-height:70vh;overflow-y:auto;border-right:1px solid #dce3ec; }
.db-contact-button { display:flex;align-items:center;gap:.6rem;width:100%;padding:1rem;text-align:left;border:0;border-bottom:1px solid #dce3ec;background:transparent;color:var(--ink);font:inherit;cursor:pointer;overflow-wrap:anywhere; }
.db-contact-label { display:grid;gap:.4rem;min-width:0; }
.db-contact-avatar { position:relative;flex:none;display:grid;place-items:center;width:2.25rem;height:2.25rem;border-radius:50%;overflow:hidden;background:var(--selected); }
.db-contact-avatar img { position:absolute;inset:0;width:100%;height:100%;object-fit:cover;opacity:0; }
.db-contact-avatar img.ready { opacity:1; }
.db-contact-button:hover { background:var(--selected); }
.db-contact-button span { font-size:.85rem;color:var(--muted); }
.db-contact-detail { padding:1.25rem;min-height:300px;overflow-wrap:anywhere; }
.db-contact-detail dt { margin-top:1rem;font-weight:700;color:var(--action-blue); }
.db-contact-detail dd { margin:.3rem 0;white-space:pre-wrap; }
.db-dialog { width:min(95vw,720px);max-height:92vh;overflow:auto;border:1px solid #dce3ec;border-radius:18px;padding:1.5rem;background:var(--paper);color:var(--ink);box-shadow:0 20px 80px #102f4c55; }
.db-dialog::backdrop { background:#102f4c88; }
.db-dialog .db-toolbar { margin:0; }
.db-dialog label { display:grid;gap:.4rem; }
#contact-fields { display:grid;gap:.75rem;margin:.75rem 0; }
#contact-fields fieldset { display:grid;gap:.35rem;min-width:0;margin:0;padding:.75rem;border:1px solid #dce3ec;border-radius:8px; }
#contact-fields legend { max-width:100%;overflow-wrap:anywhere; }
#contact-fields fieldset button { justify-self:start; }
.contact-component { display:grid;gap:.35rem; }
.contact-component-row { display:flex;align-items:end;gap:.4rem; }
.contact-component-row label { flex:1;min-width:0; }
#contact-toggle-mode { margin-top:.75rem; }
.db-dialog .db-check { display:flex;align-items:center;gap:.6rem; }
.db-check input { width:auto;min-height:1rem; }
.db-dialog footer { margin-top:1rem!important; }
.db-dialog .danger { color:var(--danger);background:#fbecec; }
#event-files { list-style:none;margin:0;padding:0; }
#event-files li { display:flex;align-items:center;justify-content:space-between;gap:.5rem; }
#contact-vcard { margin-top:.7rem;font-family:ui-monospace,monospace;font-size:.85rem; }
.sr-only { position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap; }
@media(max-width:900px){.db-calendar-week{grid-template-columns:repeat(7,minmax(125px,1fr));}.database-app .sync-indicator{display:none;}}
@media(max-width:704px){.database-app .app-topbar{gap:.4rem;padding:.5rem;}.database-app .app-brand{min-width:0;}.database-app .app-brand strong{display:none;}.database-app .app-language select{min-width:5rem;}.db-view{padding:.8rem;}.db-contacts-layout{grid-template-columns:1fr;}.db-contact-list{max-height:35vh;border-right:0;border-bottom:1px solid #dce3ec;}.db-toolbar{gap:.6rem;}.db-dialog{padding:1rem;}}

.database-app .sidebar-download { background:transparent;border:1px solid #ffffff55;border-radius:10px;color:#fff;padding:.65rem;text-align:center; }
.db-event strong { min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.db-event small { overflow-wrap:normal; }

@media(max-width:704px){.database-app .app-brand{display:flex;}.database-app .app-language{display:grid;}.database-app .mini-brand{width:2rem;height:2rem;}.database-app .app-topbar .button{padding:.6rem;}.database-app .app-language{margin-left:0;}}

/* Notes keeps the shared notebook / section / page relationship on every screen. */
.notes-tabs{display:flex;gap:4px;overflow-x:auto;padding:8px 0}.notes-tabs .nav-button{width:auto;flex-shrink:0}
.notes-layout{display:grid;grid-template-columns:minmax(0,1fr) 210px;gap:12px;min-height:55vh}
.notes-editor{min-width:0;display:flex;flex-direction:column;gap:10px}.notes-editor textarea{min-height:280px;resize:vertical;width:100%}
.notes-pages{border-left:1px solid var(--border,#ccd5d7);padding-left:8px;display:flex;flex-direction:column;gap:5px;overflow:auto}
.notes-item{display:flex;align-items:center;gap:6px;padding:3px 0;flex-wrap:wrap}.notes-item input[type=text],.notes-item input:not([type]){flex:1;min-width:80px}.notes-item span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.notes-item small{font-size:11px}.notes-due{color:#a06400}
@media(max-width:650px){.notes-layout{grid-template-columns:minmax(0,1fr) 100px;gap:5px}.notes-pages{padding-left:3px}.notes-pages button{font-size:12px;padding:7px 4px}.notes-editor .toolbar{flex-wrap:wrap}}

#notes-workspace>.db-toolbar select{width:auto;flex:1;min-width:140px}
.notes-item input[type=checkbox]{width:20px;height:20px;min-height:20px;padding:0;margin:0;flex:0 0 20px}
.notes-tabs .nav-button,.notes-pages .nav-button{color:#17324d;background:#e1eaf0;border-radius:10px}
.notes-tabs .nav-button.active,.notes-pages .nav-button.active{color:#102c42;background:#cddce8}
.notes-editor .db-check input[type=checkbox]{width:18px;height:18px;min-height:18px}
.edit-action::before{content:"✎" / "";margin-inline-end:.35em}
.notes-filter-results { display:grid;gap:1.4rem;max-width:72ch;margin:1.25rem auto; }
.notes-filter-card {
    position:relative;display:grid;gap:.35rem;min-width:0;padding:1.1rem;
    border:1px solid #aebfcd;border-radius:10px;background:var(--paper);color:var(--ink);
    text-align:start;cursor:pointer;overflow-wrap:anywhere;
}
.notes-filter-card:hover { background:var(--selected); }
.notes-filter-card:focus-visible { outline:2px solid var(--action-blue);outline-offset:3px; }
.notes-filter-preview { white-space:pre-line;color:var(--muted); }
.notes-filter-section,.notes-filter-book {
    position:absolute;left:50%;max-width:85%;padding:0 .4rem;
    background:var(--paper);color:var(--muted);font-size:.8rem;
    white-space:nowrap;text-overflow:ellipsis;overflow:hidden;
}
.notes-filter-section { top:0;transform:translate(-50%,-50%); }
.notes-filter-book { bottom:0;transform:translate(-50%,50%); }
.notes-read-frame {
    min-width:0;border:1px solid #aebfcd;border-radius:10px;
    background:var(--paper);overflow:hidden;
}
.notes-read-frame > .db-toolbar,.notes-read-frame > .notes-due { padding:.5rem .75rem; }
.notes-read-frame > .db-toolbar { border-bottom:1px solid #dce3ec; }
.notes-read-body { min-height:12rem;cursor:text; }
.notes-read-body .morga-rich-toolbar { display:none; }
.notes-read-actions { display:flex;justify-content:flex-end; }
.notes-conflict-preview { white-space:pre-wrap;overflow-wrap:anywhere;max-height:10rem;overflow:auto; }
.original-pending-row{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center;padding:.6rem 0;border-bottom:1px solid #b8c5d2}
.original-pending-row .toolbar{margin-left:auto}
.original-conflict-dialog{width:min(72rem,94vw)}
.original-comparison{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem;margin:1rem 0}
.original-comparison-side{min-width:0;border:1px solid #b8c5d2;border-radius:.5rem;padding:.75rem}
.original-comparison-side summary{cursor:pointer;padding:.4rem 0}
.original-event-preview{border-bottom:1px solid #b8c5d2;padding:.5rem 0}
.original-event-preview h4{margin:.25rem 0}
.original-preview-text,.original-raw-preview{white-space:pre-wrap;overflow-wrap:anywhere}
.original-raw-preview{max-height:20rem;overflow:auto;font-size:.85rem}
@media(max-width:650px){.original-comparison{grid-template-columns:1fr}.original-conflict-dialog .toolbar{flex-wrap:wrap}}

@media(max-width:650px){.app-sidebar:not(.open){visibility:hidden}.app-sidebar.open{visibility:visible}}
