:root {
    --app-primary: var(--tenant-primary, #2563eb);
    --app-accent: var(--tenant-accent, #0f172a);
    --app-bg: var(--tenant-bg, #f4f7fb);
    --header-height: 68px;
    --sidebar-width: 272px;
    --sidebar-collapsed-width: 84px;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-hover: #eef3f9;
    --text: #172033;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #15803d;
    --success-soft: #f0fdf4;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 4px 14px rgba(15, 23, 42, .07);
    --shadow-md: 0 16px 40px rgba(15, 23, 42, .13);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --transition: .2s ease;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--app-bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--app-bg);
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.no-scroll {
    overflow: hidden;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
.btn {
    appearance: none;
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--app-primary);
    color: #fff !important;
    text-decoration: none;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: transform var(--transition), box-shadow var(--transition), filter var(--transition), background var(--transition);
}

button:hover,
.btn:hover {
    filter: brightness(.96);
    box-shadow: var(--shadow-sm);
}

button:active,
.btn:active {
    transform: translateY(1px);
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .22);
    outline-offset: 2px;
}

button.secondary,
.btn.secondary,
.secondary {
    background: #64748b !important;
    border-color: #64748b !important;
}

button.ghost,
.btn.ghost {
    color: var(--text) !important;
    background: var(--surface) !important;
    border-color: var(--border) !important;
    box-shadow: none;
}

button.danger,
.btn.danger {
    background: var(--danger) !important;
}

button:disabled,
.btn.disabled,
.disabled {
    pointer-events: none;
    opacity: .5;
}

a {
    color: var(--app-primary);
}

h1,
h2,
h3,
h4 {
    margin-top: 0;
    color: var(--text);
    line-height: 1.25;
}

h1 { font-size: clamp(1.65rem, 3vw, 2.25rem); }
h2 { font-size: clamp(1.3rem, 2vw, 1.65rem); }
h3 { font-size: 1.08rem; }

p {
    margin-top: 0;
}

hr {
    margin: 22px 0;
    border: 0;
    border-top: 1px solid var(--border);
}

/* Application shell */
.app-shell {
    min-height: 100vh;
}

.app-header {
    position: fixed;
    z-index: 1100;
    inset: 0 0 auto 0;
    height: var(--header-height);
    display: grid;
    grid-template-columns: minmax(230px, var(--sidebar-width)) minmax(260px, 720px) auto;
    align-items: center;
    gap: 18px;
    padding: 0 18px;
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid rgba(226, 232, 240, .92);
    box-shadow: 0 1px 8px rgba(15, 23, 42, .045);
    backdrop-filter: blur(16px);
}

.header-left,
.header-actions {
    display: flex;
    align-items: center;
}

.header-left {
    min-width: 0;
    gap: 8px;
}

.header-actions {
    justify-content: flex-end;
    gap: 5px;
}

.icon-button {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #475569 !important;
    font-size: 20px;
    box-shadow: none;
}

.icon-button:hover {
    background: var(--surface-hover);
    box-shadow: none;
    filter: none;
}

.hamburger {
    width: 19px;
    display: grid;
    gap: 4px;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.app-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
}

.brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    object-fit: contain;
}

.brand-mark,
.auth-logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: #fff;
    background: linear-gradient(135deg, var(--app-primary), #7c3aed);
    box-shadow: 0 8px 18px rgba(37, 99, 235, .24);
    font-weight: 800;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 18px;
}

.brand-copy {
    min-width: 0;
    display: grid;
    line-height: 1.15;
}

.brand-copy strong {
    overflow: hidden;
    color: #111827;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy small {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 11px;
}

.global-search {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.global-search input {
    width: 100%;
    height: 46px;
    margin: 0;
    padding: 0 52px 0 46px;
    border: 1px solid transparent;
    border-radius: 13px;
    background: #eef3f8;
    color: var(--text);
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.global-search input:focus {
    border-color: var(--border);
    background: #fff;
    box-shadow: 0 6px 22px rgba(15, 23, 42, .09);
    outline: none;
}

.global-search .search-icon {
    position: absolute;
    left: 16px;
    z-index: 1;
    color: #64748b;
    font-size: 23px;
    line-height: 1;
}

.global-search kbd {
    position: absolute;
    right: 13px;
    min-width: 24px;
    padding: 2px 6px;
    border: 1px solid #d7dee8;
    border-bottom-width: 2px;
    border-radius: 6px;
    color: #64748b;
    background: #fff;
    font: 12px/1.4 inherit;
    text-align: center;
}

.user-menu {
    position: relative;
}

.user-menu summary {
    list-style: none;
    cursor: pointer;
}

.user-menu summary::-webkit-details-marker,
.nav-group summary::-webkit-details-marker,
.row-menu summary::-webkit-details-marker {
    display: none;
}

.user-avatar {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--app-primary), #7c3aed);
    box-shadow: 0 0 0 1px var(--border), 0 4px 12px rgba(15, 23, 42, .12);
    font-size: 14px;
    font-weight: 800;
}

.user-avatar.large {
    width: 48px;
    height: 48px;
    border-width: 0;
    font-size: 18px;
}

.user-menu-panel {
    position: absolute;
    z-index: 1500;
    top: calc(100% + 12px);
    right: 0;
    width: min(310px, calc(100vw - 24px));
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.user-card div {
    min-width: 0;
    display: grid;
}

.user-card strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-card small {
    color: var(--text-muted);
}

.user-menu-panel > a,
.menu-signout {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 9px 11px;
    border: 0;
    border-radius: 9px;
    color: var(--text) !important;
    background: transparent;
    text-decoration: none;
    font-weight: 550;
    box-shadow: none;
}

.user-menu-panel > a:hover,
.menu-signout:hover {
    background: var(--surface-hover);
    box-shadow: none;
    filter: none;
}

/* Sidebar */
.app-sidebar {
    position: fixed;
    z-index: 1000;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    padding: 14px 10px 18px;
    border-right: 1px solid var(--border);
    background: #fff;
    transition: width var(--transition), transform var(--transition);
}

.sidebar-scroll {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.compose-button {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    margin: 0 5px 14px;
    padding: 10px 18px;
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, var(--app-primary), #4f46e5);
    box-shadow: 0 9px 20px rgba(37, 99, 235, .2);
    text-decoration: none;
    font-weight: 750;
    transition: transform var(--transition), box-shadow var(--transition);
}

.compose-button:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 13px 24px rgba(37, 99, 235, .26);
}

.compose-icon {
    font-size: 24px;
    font-weight: 400;
}

.sidebar-nav,
.nav-section,
.nav-group-content {
    display: grid;
    gap: 3px;
}

.nav-section-title {
    padding: 10px 14px 6px;
    color: var(--text-soft);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.nav-link,
.nav-group summary {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 7px 12px;
    border-radius: 9px;
    color: #42526a;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover,
.nav-group summary:hover {
    color: #1e293b;
    background: var(--surface-hover);
}

.nav-link.active {
    color: var(--app-primary);
    background: #edf4ff;
    font-weight: 750;
}

.nav-link.active::before {
    position: absolute;
    left: 0;
    width: 3px;
    height: 22px;
    border-radius: 0 4px 4px 0;
    background: var(--app-primary);
    content: "";
}

.nav-link {
    position: relative;
}

.nav-icon {
    width: 22px;
    flex: 0 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    font-size: 17px;
    line-height: 1;
}

.nav-label {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-badge {
    min-width: 25px;
    padding: 1px 7px;
    border-radius: 999px;
    color: #64748b;
    background: #eef2f7;
    font-size: 11px;
    font-weight: 750;
    text-align: center;
}

.unread-badge {
    color: #1d4ed8;
    background: #dbeafe;
}

.danger-badge {
    color: #b91c1c;
    background: #fee2e2;
}

.nav-group {
    margin-top: 5px;
}

.nav-group summary {
    justify-content: space-between;
    list-style: none;
    color: #52627a;
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .055em;
}

.summary-label {
    min-width: 0;
    display: flex;
    flex: 1;
    align-items: center;
    gap: 11px;
}

.chevron {
    transition: transform var(--transition);
}

.nav-group[open] .chevron {
    transform: rotate(180deg);
}

.nav-group-content {
    padding: 3px 0 4px;
}

.folder-link {
    padding-left: calc(12px + (var(--folder-depth, 0) * 12px));
}

.app-content {
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    padding: calc(var(--header-height) + 22px) 24px 30px;
    transition: margin-left var(--transition);
}

.content-frame {
    width: 100%;
    max-width: 1540px;
    margin: 0 auto;
}

.app-footer {
    padding: 24px 8px 4px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}

.sidebar-backdrop {
    display: none;
}

.app-shell.sidebar-collapsed .app-header {
    grid-template-columns: var(--sidebar-collapsed-width) minmax(260px, 720px) auto;
}

.app-shell.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
}

.app-shell.sidebar-collapsed .app-content {
    margin-left: var(--sidebar-collapsed-width);
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .app-sidebar .nav-label,
.app-shell.sidebar-collapsed .app-sidebar .nav-badge,
.app-shell.sidebar-collapsed .app-sidebar .nav-section-title,
.app-shell.sidebar-collapsed .app-sidebar .chevron {
    display: none;
}

.app-shell.sidebar-collapsed .compose-button,
.app-shell.sidebar-collapsed .nav-link,
.app-shell.sidebar-collapsed .nav-group summary {
    justify-content: center;
    padding-right: 8px;
    padding-left: 8px;
}

.app-shell.sidebar-collapsed .compose-button {
    margin-right: 6px;
    margin-left: 6px;
}

.app-shell.sidebar-collapsed .nav-group-content {
    padding: 0;
}

/* Shared page components */
.card,
.page-card {
    padding: clamp(16px, 2.5vw, 24px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.card + .card,
.page-card + .page-card {
    margin-top: 18px;
}

.toolbar,
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.toolbar h1,
.toolbar h2,
.page-header h1,
.page-header h2 {
    margin-bottom: 0;
}

.toolbar-actions,
.page-actions,
.actions,
.compose-actions,
.search-actions,
.bulkbar,
.template-row,
.admin-subnav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.result-count,
.muted,
small {
    color: var(--text-muted);
}

.inline {
    display: inline-flex;
    margin: 0;
}

label {
    display: block;
    color: #334155;
    font-size: 13px;
    font-weight: 650;
}

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
    width: 100%;
    min-height: 40px;
    margin-top: 6px;
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    color: var(--text);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

textarea {
    min-height: 140px;
    resize: vertical;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .11);
    outline: none;
}

input[type="checkbox"],
input[type="radio"] {
    width: 17px;
    height: 17px;
    accent-color: var(--app-primary);
}

.alert,
.ai-notice,
.new-mail-notice {
    margin: 10px 0;
    padding: 11px 13px;
    border: 1px solid transparent;
    border-radius: 10px;
}

.alert.error,
.error {
    color: #991b1b;
    border-color: #fecaca;
    background: var(--danger-soft);
}

.alert.success,
.success {
    color: #166534;
    border-color: #bbf7d0;
    background: var(--success-soft);
}

.alert.warning {
    color: #92400e;
    border-color: #fde68a;
    background: var(--warning-soft);
}

.validation-summary-valid {
    display: none;
}

/* Generic tables */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

table:not(.cke_dialog_ui_table) {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

table:not(.cke_dialog_ui_table) th,
table:not(.cke_dialog_ui_table) td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

table:not(.cke_dialog_ui_table) th {
    color: #64748b;
    background: #f8fafc;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

table:not(.cke_dialog_ui_table) tbody tr:hover {
    background: #fbfdff;
}

table:not(.cke_dialog_ui_table) tbody tr:last-child td {
    border-bottom: 0;
}

/* Mail list */
.mail-page {
    display: grid;
    gap: 13px;
}

.mail-page-header {
    margin-bottom: 0;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.title-row h2 {
    margin: 0;
}

.live-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 999px;
    color: #166534;
    background: #dcfce7;
    font-size: 11px;
    font-weight: 800;
}

.live-status.offline {
    color: #92400e;
    background: #fef3c7;
}

.new-mail-notice {
    position: sticky;
    z-index: 20;
    top: calc(var(--header-height) + 8px);
    margin: 0;
    color: #166534;
    border-color: #86efac;
    background: #f0fdf4;
    box-shadow: var(--shadow-sm);
    font-weight: 750;
}

.advanced-search {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-xs);
}

.advanced-search summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    list-style: none;
    color: #334155;
    cursor: pointer;
    font-weight: 750;
}

.advanced-search summary::after {
    color: #94a3b8;
    content: "⌄";
    transition: transform var(--transition);
}

.advanced-search[open] summary::after {
    transform: rotate(180deg);
}

.search-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
}

.search-grid label {
    padding-top: 12px;
}

.search-grid .check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 29px;
}

.search-grid .check input {
    flex: 0 0 auto;
    margin: 0;
}

.search-actions {
    align-self: end;
    padding-top: 12px;
}

.bulkbar {
    min-height: 50px;
    justify-content: flex-start;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.bulkbar select {
    width: auto;
    min-width: 190px;
    margin: 0;
}

.mail-list-panel {
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: #fff;
    box-shadow: var(--shadow-xs);
}

.mail-list-head,
.mail-row {
    display: grid;
    grid-template-columns: 38px 42px minmax(150px, .8fr) minmax(240px, 2fr) 118px 46px;
    align-items: center;
    gap: 8px;
}

.mail-list-head {
    min-height: 44px;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    color: #64748b;
    background: #f8fafc;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.mail-list-body {
    display: grid;
}

.mail-row {
    position: relative;
    min-height: 60px;
    padding: 7px 12px;
    border-bottom: 1px solid #edf1f6;
    transition: background var(--transition), box-shadow var(--transition);
}

.mail-row:last-child {
    border-bottom: 0;
}

.mail-row:hover {
    z-index: 2;
    background: #f8fbff;
    box-shadow: 0 3px 12px rgba(15, 23, 42, .07);
}

.mail-row.unread {
    background: #f2f7ff;
    color: #0f172a;
    font-weight: 750;
    box-shadow: inset 3px 0 0 var(--app-primary);
}

.mail-row.unread .sender,
.mail-row.unread .subject-link,
.mail-row.unread .mail-date {
    color: #0f172a;
    font-weight: 800;
}

.mail-row.read {
    color: #536178;
}

.unread-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.mail-row .sender,
.mail-row .subject-link {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sender-block {
    min-width: 0;
    display: grid;
}

.sender-block small {
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subject-block {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 7px;
}

.subject-link {
    color: inherit;
    text-decoration: none;
}

.subject-link:hover {
    color: var(--app-primary);
}

.attachment-indicator {
    color: #64748b;
    font-size: 14px;
}

.mail-date {
    color: #64748b;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.star-button {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    color: #f59e0b !important;
    background: transparent !important;
    border: 0;
    box-shadow: none;
    font-size: 21px;
}

.star-button:hover {
    background: #fff7ed !important;
    box-shadow: none;
    filter: none;
}

.row-menu {
    position: relative;
    justify-self: end;
}

.row-menu summary {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #64748b;
    cursor: pointer;
    font-size: 22px;
    list-style: none;
}

.row-menu summary:hover {
    background: #e9eff7;
}

.row-menu-panel {
    position: absolute;
    z-index: 80;
    top: 39px;
    right: 0;
    min-width: 225px;
    padding: 7px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow-md);
}

.row-menu-panel form,
.row-menu-panel .menu-link {
    display: block;
    width: 100%;
    margin: 0;
}

.row-menu-panel button,
.row-menu-panel .menu-link {
    width: 100%;
    min-height: 37px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    color: #334155 !important;
    background: transparent !important;
    text-decoration: none;
    box-shadow: none;
    font-weight: 550;
}

.row-menu-panel button:hover,
.row-menu-panel .menu-link:hover {
    background: var(--surface-hover) !important;
    box-shadow: none;
    filter: none;
}

.row-menu-panel .danger-action {
    color: var(--danger) !important;
}

.row-menu-panel select {
    margin: 4px 0 7px;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 280px;
    padding: 30px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    margin-bottom: 12px;
    border-radius: 50%;
    color: var(--app-primary);
    background: #eef4ff;
    font-size: 28px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 6px 0 18px;
}

/* Message reader */
.message-reader {
    max-width: 1180px;
    margin: 0 auto;
}

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

.message-title-wrap {
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.message-title-wrap h1 {
    margin: 4px 0 0;
    overflow-wrap: anywhere;
    font-size: clamp(1.35rem, 2.5vw, 1.9rem);
    font-weight: 650;
}

.back-button {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 50%;
    color: #475569 !important;
    background: transparent !important;
    box-shadow: none;
    font-size: 21px;
}

.back-button:hover {
    background: var(--surface-hover) !important;
    box-shadow: none;
}

.message-actionbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.message-actionbar button,
.message-actionbar .btn {
    min-height: 36px;
    padding: 7px 10px;
    color: #334155 !important;
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none;
    font-size: 12px;
}

.message-actionbar button:hover,
.message-actionbar .btn:hover {
    background: var(--surface-hover) !important;
    box-shadow: none;
    filter: none;
}

.message-actionbar .delete-action {
    color: var(--danger) !important;
}

.message-sender-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

.sender-avatar {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    font-size: 17px;
    font-weight: 800;
}

.sender-details {
    min-width: 0;
    flex: 1;
}

.sender-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.sender-address {
    overflow: hidden;
    color: #334155;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-time {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 12px;
}

.message-recipients {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.message-recipients details summary {
    cursor: pointer;
}

.recipient-details {
    display: grid;
    gap: 4px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-soft);
    overflow-wrap: anywhere;
}

.ai-message-card {
    margin: 18px 0;
    padding: 16px;
    border: 1px solid #bfdbfe;
    border-radius: 13px;
    background: linear-gradient(135deg, #eff6ff, #f8fbff);
}

.ai-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-message-header h3 {
    margin: 0;
}

.ai-scores {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.ai-scores span {
    padding: 6px 10px;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: #fff;
    font-size: 12px;
}

.ai-reply {
    padding: 12px;
    border: 1px solid #dbeafe;
    border-radius: 9px;
    background: #fff;
    white-space: pre-wrap;
}

.ai-message-card code {
    display: block;
    margin: 4px 0;
    overflow-wrap: anywhere;
}

.attachment-box {
    margin: 18px 0;
}

.attachment-box h3 {
    margin-bottom: 10px;
}

.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.attachment-item {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--text);
    background: #fff;
    text-decoration: none;
}

.attachment-item:hover {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.attachment-icon {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 9px;
    color: var(--app-primary);
    background: #eef4ff;
    font-size: 18px;
}

.attachment-info {
    min-width: 0;
    display: grid;
}

.attachment-name {
    overflow: hidden;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-meta {
    color: var(--text-muted);
    font-size: 11px;
}

.message-body-wrapper {
    min-height: 300px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
}

.mail-body-frame {
    width: 100%;
    min-height: 520px;
    display: block;
    border: 0;
    background: #fff;
}

.plain-body {
    min-height: 300px;
    margin: 0;
    padding: 20px;
    color: #263244;
    background: #fff;
    font-family: "Segoe UI", Arial, sans-serif;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Compose */
.compose {
    max-width: 1050px;
    margin: 0 auto;
}

.compose h2 {
    margin-bottom: 6px;
}

.compose form > label {
    margin-top: 14px;
}

.compose #Body {
    min-height: 360px;
}

.compose-actions {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.draft-status {
    min-height: 22px;
    color: var(--text-muted);
    font-size: 12px;
}

.template-row select {
    flex: 1 1 250px;
    width: auto;
    margin: 0;
}

.schedule-panel {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.cke_chrome {
    overflow: hidden;
    border-color: var(--border-strong) !important;
    border-radius: 10px !important;
    box-shadow: none !important;
}

/* Admin sub-navigation */
.admin-subnav {
    flex-wrap: nowrap;
    margin: 0 0 18px;
    padding: 6px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    scrollbar-width: thin;
}

.admin-subnav .btn {
    min-height: 34px;
    flex: 0 0 auto;
    padding: 7px 10px;
    color: #475569 !important;
    background: transparent !important;
    border: 0;
    box-shadow: none;
    font-size: 12px;
}

.admin-subnav .btn:hover {
    color: var(--app-primary) !important;
    background: #eef4ff !important;
    box-shadow: none;
    filter: none;
}

/* Login / authentication */
.auth-body {
    background: #eef3f9;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(340px, .9fr) minmax(480px, 1.1fr);
}

.auth-brand-panel {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 48px;
    color: #fff;
    background:
        radial-gradient(circle at 12% 15%, rgba(255,255,255,.2), transparent 24%),
        radial-gradient(circle at 88% 78%, rgba(56,189,248,.25), transparent 28%),
        linear-gradient(145deg, #172554, #1d4ed8 55%, #4f46e5);
}

.auth-brand-panel::before,
.auth-brand-panel::after {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 50%;
    content: "";
}

.auth-brand-panel::before {
    width: 420px;
    height: 420px;
    top: -180px;
    right: -150px;
}

.auth-brand-panel::after {
    width: 300px;
    height: 300px;
    bottom: -150px;
    left: -100px;
}

.auth-brand-content {
    position: relative;
    z-index: 1;
    width: min(470px, 100%);
}

.auth-logo,
.auth-logo-mark {
    width: 62px;
    height: 62px;
    margin-bottom: 24px;
    border-radius: 17px;
}

.auth-logo {
    object-fit: contain;
}

.auth-logo-mark {
    background: rgba(255,255,255,.18);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.25), 0 14px 30px rgba(0,0,0,.18);
    font-size: 28px;
}

.auth-brand-content h1 {
    margin-bottom: 13px;
    color: #fff;
    font-size: clamp(2rem, 4vw, 3.15rem);
}

.auth-brand-content > p {
    max-width: 430px;
    color: rgba(255,255,255,.8);
    font-size: 17px;
}

.auth-feature-list {
    display: grid;
    gap: 10px;
    margin-top: 30px;
}

.auth-feature-list span {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255,255,255,.9);
}

.auth-feature-list b {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: rgba(255,255,255,.15);
}

.auth-content {
    min-width: 0;
    display: grid;
    align-content: center;
    padding: 34px clamp(24px, 7vw, 90px);
    background: #f8fafc;
}

.login-card {
    width: min(470px, 100%);
    margin: 0 auto;
    padding: clamp(24px, 5vw, 38px);
    border-radius: 20px;
    box-shadow: 0 20px 55px rgba(15, 23, 42, .12);
}

.login-card h2 {
    margin-bottom: 7px;
    font-size: 1.7rem;
}

.login-card form > label {
    margin-top: 16px;
}

.login-card form > button {
    width: 100%;
    min-height: 44px;
    margin-top: 20px;
}

.sso-list {
    display: grid;
    gap: 8px;
}

.auth-footer {
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}

/* Existing utility classes */
.meta {
    margin: 5px 0;
    color: #475569;
}

.attachments {
    line-height: 1.8;
}

.attachments span {
    color: var(--text-muted);
    font-size: 12px;
}

.empty {
    padding: 30px !important;
    color: var(--text-muted);
    text-align: center !important;
}

/* Responsive */
@media (max-width: 1180px) {
    .app-header {
        grid-template-columns: 230px minmax(220px, 1fr) auto;
    }

    .search-grid {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }

    .mail-list-head,
    .mail-row {
        grid-template-columns: 36px 38px minmax(140px, .75fr) minmax(210px, 1.7fr) 108px 42px;
    }
}

@media (max-width: 900px) {
    :root {
        --header-height: 62px;
    }

    .app-header {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        padding: 0 10px;
    }

    .brand-copy,
    .global-search kbd,
    .header-action {
        display: none;
    }

    .global-search input {
        height: 42px;
    }

    .app-sidebar,
    .app-shell.sidebar-collapsed .app-sidebar {
        width: min(310px, 88vw);
        transform: translateX(-105%);
        box-shadow: var(--shadow-md);
    }

    .app-shell.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell.sidebar-open .sidebar-backdrop {
        position: fixed;
        z-index: 900;
        inset: var(--header-height) 0 0 0;
        display: block;
        width: auto;
        min-height: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgba(15, 23, 42, .42);
        box-shadow: none;
        backdrop-filter: blur(2px);
    }

    .app-shell.sidebar-collapsed .app-sidebar .nav-label,
    .app-shell.sidebar-collapsed .app-sidebar .nav-badge,
    .app-shell.sidebar-collapsed .app-sidebar .nav-section-title,
    .app-shell.sidebar-collapsed .app-sidebar .chevron {
        display: initial;
    }

    .app-shell.sidebar-collapsed .compose-button,
    .app-shell.sidebar-collapsed .nav-link,
    .app-shell.sidebar-collapsed .nav-group summary {
        justify-content: flex-start;
        padding-right: 12px;
        padding-left: 12px;
    }

    .app-content,
    .app-shell.sidebar-collapsed .app-content {
        margin-left: 0;
        padding: calc(var(--header-height) + 16px) 16px 24px;
    }

    .search-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }

    .mail-list-head {
        display: none;
    }

    .mail-row {
        grid-template-columns: 30px 34px minmax(0, 1fr) 40px;
        gap: 6px;
        min-height: 70px;
        padding: 8px 10px;
    }

    .mail-row .sender-block {
        grid-column: 3;
        grid-row: 1;
        padding-right: 80px;
    }

    .mail-row .subject-block {
        grid-column: 3;
        grid-row: 2;
    }

    .mail-row .mail-date {
        position: absolute;
        top: 10px;
        right: 52px;
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mail-row .row-menu {
        grid-column: 4;
        grid-row: 1 / span 2;
    }

    .mail-row > .selection-cell {
        grid-row: 1 / span 2;
    }

    .mail-row > .star-cell {
        grid-row: 1 / span 2;
    }

    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-brand-panel {
        display: none;
    }

    .auth-content {
        min-height: 100vh;
        padding: 24px;
    }
}

@media (max-width: 640px) {
    .header-left {
        gap: 2px;
    }

    .brand-mark,
    .brand-logo {
        width: 34px;
        height: 34px;
    }

    .global-search input {
        padding-left: 38px;
    }

    .global-search .search-icon {
        left: 12px;
    }

    .app-content {
        padding-right: 10px;
        padding-left: 10px;
    }

    .card,
    .page-card {
        padding: 15px;
        border-radius: 14px;
    }

    .toolbar,
    .page-header,
    .message-topline,
    .sender-line,
    .ai-message-header {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-actions,
    .page-actions {
        width: 100%;
    }

    .toolbar-actions > *,
    .page-actions > * {
        flex: 1 1 auto;
    }

    .search-grid {
        grid-template-columns: 1fr;
    }

    .search-grid .check {
        padding-top: 5px;
    }

    .search-actions {
        padding-top: 3px;
    }

    .bulkbar {
        align-items: stretch;
        flex-direction: column;
    }

    .bulkbar select {
        width: 100%;
    }

    .mail-row {
        grid-template-columns: 28px 32px minmax(0, 1fr) 36px;
    }

    .mail-row .sender-block {
        padding-right: 62px;
    }

    .mail-row .mail-date {
        right: 45px;
        max-width: 65px;
        font-size: 10px;
    }

    .row-menu-panel {
        position: fixed;
        right: 10px;
        bottom: 10px;
        top: auto;
        left: 10px;
        min-width: 0;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 16px;
    }

    .pager {
        gap: 7px;
    }

    .pager .btn {
        padding: 8px 10px;
    }

    .message-actionbar {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .message-actionbar > * {
        flex: 0 0 auto;
    }

    .message-time {
        margin-top: 2px;
    }

    .attachment-grid {
        grid-template-columns: 1fr;
    }

    .template-row {
        align-items: stretch;
        flex-direction: column;
    }

    .template-row select {
        width: 100%;
    }

    .admin-subnav {
        margin-right: -4px;
        margin-left: -4px;
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 16px;
    }
}

@media print {
    .app-header,
    .app-sidebar,
    .sidebar-backdrop,
    .message-actionbar,
    .message-topline .back-button,
    .app-footer,
    .admin-subnav {
        display: none !important;
    }

    .app-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .card,
    .message-body-wrapper {
        border: 0 !important;
        box-shadow: none !important;
    }

    .mail-body-frame {
        min-height: 900px !important;
    }
}
