.core-page {
    width: min(1180px, 100%);
    margin: 0 auto;
    color: var(--shell-text);
}

.core-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.core-page-header h1,
.core-page-header h2 {
    margin: 3px 0 0;
    color: var(--shell-text);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.7rem, 3vw, 2.25rem);
    line-height: 1.1;
}

.core-page-header p {
    max-width: 680px;
    margin: 8px 0 0;
    color: var(--shell-muted);
    line-height: 1.5;
}

.core-page-header.is-centered {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.core-page-header.is-centered > div {
    width: 100%;
}

.core-page-header.is-centered p {
    margin-right: auto;
    margin-left: auto;
}

.core-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
}

.core-grid > .is-wide {
    grid-column: 1 / -1;
}

.core-card {
    min-width: 0;
    padding: clamp(18px, 2.5vw, 26px);
    border: 1px solid var(--ui-card-border);
    border-radius: var(--ui-card-radius);
    background: var(--ui-card-background);
    box-shadow: var(--ui-card-shadow);
}

.core-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.core-card-header h2,
.core-card-header h3 {
    margin: 0;
    color: var(--shell-text);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.3rem;
}

.core-card-header p,
.core-helper {
    margin: 5px 0 0;
    color: var(--shell-muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.core-form {
    display: grid;
    gap: 14px;
}

.core-form .field {
    display: grid;
    gap: 6px;
}

.core-form label {
    color: var(--shell-text-soft);
    font-size: 0.84rem;
    font-weight: 750;
}

body.app-shell #centre .core-form :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--ui-form-control-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-form-control-background);
    color: var(--ui-form-control-text);
}

body.app-shell #centre .core-form textarea {
    min-height: 130px;
    resize: vertical;
    line-height: 1.5;
}

.core-form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

body.app-shell #centre :is(.button, button.button) {
    min-height: var(--ui-control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--ui-button-primary-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-button-primary-background);
    color: var(--ui-button-primary-text);
    font-weight: 720;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
}

body.app-shell #centre :is(.button-secondary, button.button-secondary) {
    border-color: var(--ui-button-secondary-border);
    background: var(--ui-button-secondary-background);
    color: var(--ui-button-secondary-text);
}

body.app-shell #centre :is(.button-quiet, button.button-quiet) {
    border-color: transparent;
    background: transparent;
    color: var(--ui-button-quiet-text);
}

body.app-shell #centre :is(.button-danger, button.button-danger) {
    border-color: var(--ui-button-danger-border);
    background: var(--ui-button-danger-background);
    color: var(--ui-button-danger-text);
}

body.app-shell #centre :is(.button-small, button.button-small) {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.82rem;
}

body.app-shell #centre :is(.button, button.button):disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.share-key {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
    padding: 14px 16px;
    border: 1px solid #cde0de;
    border-radius: 14px;
    background: var(--shell-mint-soft);
}

.share-key span {
    display: grid;
    gap: 3px;
}

.share-key small {
    color: var(--shell-muted);
}

.share-key code {
    color: var(--shell-teal-dark);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.96rem;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.account-page .share-key {
    position: relative;
    width: 100%;
    max-width: none;
    min-height: 84px;
    box-sizing: border-box;
    justify-content: center;
    margin-right: auto;
    margin-left: auto;
    padding-right: 150px;
    padding-left: 150px;
    text-align: center;
}

.account-page .share-key span {
    justify-items: center;
}

.account-page .share-key .button {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
}

:is(.account-page, .mailbox-page, .support-page) .core-card-header {
    justify-content: center;
    text-align: center;
}

:is(.account-page, .mailbox-page, .support-page) .core-card-header > div {
    width: 100%;
}

:is(.account-page, .mailbox-page, .support-page) .core-card-header p {
    margin-right: auto;
    margin-left: auto;
}

.module-order-list {
    display: grid;
    gap: 9px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.module-order-item {
    display: grid;
    grid-template-columns: auto 14px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    padding: 8px 10px;
    border: 1px solid var(--shell-line);
    border-left: 5px solid var(--module-category, var(--shell-teal));
    border-radius: 12px;
    background: color-mix(in srgb, var(--module-category, var(--shell-teal)) 6%, var(--shell-surface-soft));
    cursor: grab;
    transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.module-order-item:active {
    cursor: grabbing;
}

.module-order-item.is-dragging {
    opacity: 0.55;
    border-color: var(--shell-teal);
    box-shadow: 0 10px 24px rgba(23, 42, 51, 0.12);
}

.module-drag-handle {
    color: #789096;
    font-size: 1.15rem;
    letter-spacing: -0.18em;
    user-select: none;
}

.module-order-color {
    width: 12px;
    height: 12px;
    display: block;
    border: 2px solid color-mix(in srgb, var(--module-category, var(--shell-teal)) 72%, var(--shell-text));
    border-radius: 50%;
    background: var(--module-category, var(--shell-teal));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--module-category, var(--shell-teal)) 14%, transparent);
}

.module-order-name {
    min-width: 0;
    display: grid;
    gap: 2px;
    text-align: left;
}

.module-order-name strong {
    color: var(--shell-text);
    font-size: 0.94rem;
    font-weight: 720;
}

.module-order-name small {
    color: color-mix(in srgb, var(--module-category, var(--shell-teal)) 72%, var(--shell-muted));
    font-size: 0.72rem;
    font-weight: 680;
}

.module-order-actions {
    display: flex;
    gap: 5px;
}

body.app-shell #centre .module-order-actions button {
    width: 34px;
    min-height: 34px;
    padding: 0;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--ui-table-border);
    border-radius: var(--ui-table-radius);
}

body.app-shell #centre table.core-table {
    width: 100%;
    min-width: 620px;
    margin: 0;
    overflow: visible;
    border: 0;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 0;
    background: var(--ui-table-background);
    text-align: left;
}

body.app-shell #centre table.core-table :is(th, td) {
    padding: 11px 12px;
    border: 0;
    border-bottom: 1px solid var(--ui-table-border);
    color: var(--shell-text);
    vertical-align: middle;
}

body.app-shell #centre table.core-table th {
    background: var(--ui-table-header-background);
    color: var(--ui-table-header-text);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

body.app-shell #centre table.core-table tbody tr:nth-child(2n) td {
    background: var(--ui-table-row-alt-background);
}

body.app-shell #centre table.core-table tbody tr:last-child td {
    border-bottom: 0;
}

.status-badge,
.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 25px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #e8f2f1;
    color: var(--shell-teal-dark);
    font-size: 0.76rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-badge.is-warning {
    background: var(--shell-warning-soft);
    color: var(--shell-warning);
}

.status-badge.is-success {
    background: var(--shell-success-soft);
    color: var(--shell-success);
}

.status-badge.is-muted {
    background: #edf0f0;
    color: #657176;
}

.status-badge.is-danger {
    background: #fae8ea;
    color: #963845;
}

.empty-state.compact {
    min-height: 0;
    padding: 28px 18px;
    border: 1px dashed var(--ui-color-border-strong);
    border-radius: 13px;
    background: var(--ui-color-surface-soft);
    color: var(--ui-color-text-muted);
    text-align: center;
}

.conversation-list {
    display: grid;
    gap: 10px;
}

.conversation-item {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 9px 10px 9px 16px;
    border: 1px solid var(--shell-line);
    border-left: 4px solid var(--ui-color-border-strong);
    border-radius: 13px;
    background: linear-gradient(105deg, var(--ui-color-surface) 0%, var(--ui-color-surface-soft) 100%);
    box-shadow: 0 3px 10px rgba(23, 42, 51, 0.035);
    transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.conversation-item.has-unread {
    border-color: var(--ui-color-accent);
    border-left-color: var(--shell-teal);
    background: linear-gradient(105deg, var(--ui-color-surface-soft) 0%, var(--ui-color-surface) 100%);
}

.conversation-item:hover,
.conversation-item:focus-within {
    transform: translateY(-1px);
    border-color: var(--ui-color-accent);
    border-left-color: var(--shell-teal);
    background: var(--ui-color-surface-soft);
    box-shadow: 0 8px 20px rgba(23, 42, 51, 0.075);
}

body.app-shell #centre button.conversation-main {
    width: 100%;
    min-width: 0;
    min-height: 62px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 12px;
    margin: 0 !important;
    padding: 7px 9px !important;
    border: 0 !important;
    border-radius: 9px !important;
    background: transparent !important;
    background-image: none !important;
    color: var(--shell-text) !important;
    box-shadow: none !important;
    text-shadow: none !important;
    text-align: left;
    transform: none !important;
}

body.app-shell #centre button.conversation-main:hover,
body.app-shell #centre button.conversation-main:focus-visible {
    top: auto;
    background: var(--ui-color-surface-muted) !important;
    color: var(--shell-text) !important;
    transform: none !important;
}

body.app-shell #centre button.conversation-main:hover .conversation-subject,
body.app-shell #centre button.conversation-main:focus-visible .conversation-subject {
    color: var(--shell-teal-dark);
}

.conversation-subject {
    min-width: 0;
    color: var(--shell-text);
    font-size: 0.98rem;
    font-weight: 800;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.mailbox-page .conversation-item .count-badge {
    border: 1px solid color-mix(in srgb, var(--ui-color-primary) 42%, var(--ui-color-border));
    background: var(--ui-color-primary-subtle);
    color: var(--ui-color-primary-hover);
}

.conversation-meta,
.conversation-people {
    grid-column: 1 / -1;
    color: var(--shell-muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

.conversation-people {
    color: var(--shell-text-soft);
    font-weight: 650;
}

.conversation-item > .button {
    justify-self: end;
    margin: 0 !important;
    white-space: nowrap;
}

.mailbox-page .conversation-item > .button-danger,
.support-page .conversation-item > .button-danger {
    border-color: var(--ui-button-danger-background) !important;
    background: var(--ui-button-danger-background) !important;
    color: var(--ui-button-danger-text) !important;
}

.mailbox-page .conversation-item > .button-danger:hover,
.support-page .conversation-item > .button-danger:hover {
    border-color: var(--ui-button-danger-hover-background) !important;
    background: var(--ui-button-danger-hover-background) !important;
}

.conversation-window {
    overflow: hidden;
    border: 1px solid var(--shell-line);
    border-radius: 18px;
    background: var(--shell-surface);
    box-shadow: 0 8px 24px rgba(23, 42, 51, 0.055);
}

.message-stream {
    height: clamp(340px, 58vh, 640px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: clamp(16px, 3vw, 28px);
    background: linear-gradient(180deg, var(--ui-color-surface-subtle), var(--ui-color-surface-soft));
}

.message-row {
    max-width: min(76%, 720px);
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 8px;
    align-items: end;
}

.message-row.is-self {
    align-self: flex-end;
    grid-template-columns: minmax(0, 1fr) 38px;
}

.message-row.is-other {
    align-self: flex-start;
}

.message-avatar {
    width: 38px;
    height: 38px;
    border: 1px solid var(--ui-color-border-strong);
    border-radius: 50%;
    background: var(--ui-color-surface);
    object-fit: cover;
}

.message-bubble {
    min-width: 0;
    padding: 11px 13px 8px;
    border: 1px solid #cfdfdd;
    border-radius: 15px 15px 15px 4px;
    background: var(--ui-color-surface, #ffffff);
    color: var(--shell-text);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.message-row.is-self .message-bubble {
    grid-column: 1;
    grid-row: 1;
    border-color: var(--shell-teal-dark);
    border-radius: 15px 15px 4px 15px;
    background: var(--shell-teal-dark);
    color: var(--ui-color-text-on-brand, #ffffff);
}

.message-row.is-self .message-avatar {
    grid-column: 2;
}

.message-author {
    display: block;
    margin-bottom: 4px;
    font-size: 0.75rem;
    font-weight: 800;
}

.message-date {
    display: block;
    margin-top: 5px;
    color: inherit;
    font-size: 0.68rem;
    opacity: 0.7;
    text-align: right;
}

.message-composer {
    padding: 15px;
    border-top: 1px solid var(--shell-line);
    background: var(--ui-color-surface, #ffffff);
}

.message-composer .core-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

body.app-shell #centre .message-composer textarea {
    min-height: 76px;
}

.danger-zone {
    border-color: color-mix(in srgb, var(--ui-color-danger) 45%, var(--ui-color-border));
    background: var(--ui-color-danger-soft);
}

.danger-zone .core-card-header h2 {
    color: var(--shell-danger);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-field input {
    width: 18px;
    height: 18px;
    accent-color: var(--shell-teal);
}

.recipient-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--ui-color-border);
    border-radius: 11px;
    background: var(--ui-color-surface-soft);
}

.recipient-trigger img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.recipient-count {
    color: var(--shell-muted);
    font-size: 0.8rem;
}

.legal-page {
    max-width: 940px;
}

.legal-article {
    display: grid;
    gap: 0;
}

.legal-article section {
    padding: 22px 0;
    border-bottom: 1px solid var(--shell-line);
}

.legal-article section:first-child {
    padding-top: 0;
}

.legal-article section:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.legal-article h2 {
    margin: 0 0 10px;
    font-size: 1.2rem;
}

.legal-article p {
    margin: 0 0 9px;
    color: var(--shell-text-soft);
    line-height: 1.68;
}

.legal-article p:last-child {
    margin-bottom: 0;
}

.password-change-page {
    max-width: 720px;
}

.access-denied-page {
    max-width: 680px;
    padding-top: clamp(18px, 5vh, 58px);
}

.access-denied-card {
    text-align: center;
}

.access-denied-card h1 {
    margin: 5px 0 10px;
    color: var(--shell-text);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.65rem, 4vw, 2.2rem);
}

.access-denied-card p {
    max-width: 500px;
    margin: 0 auto 22px;
    color: var(--shell-muted);
    line-height: 1.55;
}

.access-denied-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    margin: 0 auto 15px;
    border-radius: 18px;
    background: #fae8ea;
    color: var(--shell-danger);
    font-size: 1.7rem;
    font-weight: 850;
}

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

    .core-grid > .is-wide {
        grid-column: auto;
    }

    .core-page-header,
    .share-key {
        align-items: stretch;
        flex-direction: column;
    }

    .account-page .share-key {
        align-items: center;
        min-height: 0;
        padding-right: 16px;
        padding-left: 16px;
    }

    .account-page .share-key .button {
        position: static;
        transform: none;
    }

    .conversation-item {
        grid-template-columns: 1fr;
    }

    .conversation-item > .button-danger {
        justify-self: start;
    }

    .message-row {
        max-width: 92%;
    }

    .message-composer .core-form {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .core-card {
        padding: 16px;
        border-radius: 14px;
    }

    .module-order-item {
        grid-template-columns: auto 14px minmax(0, 1fr);
    }

    .module-order-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .message-row {
        max-width: 100%;
        grid-template-columns: 30px minmax(0, 1fr);
    }

    .message-row.is-self {
        grid-template-columns: minmax(0, 1fr) 30px;
    }

    .message-avatar {
        width: 30px;
        height: 30px;
    }
}
