:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #dbe1e7;
    --text: #1f2933;
    --muted: #66727f;
    --sidebar: #202a33;
    --sidebar-text: #dfe6ec;
    --primary: #d96718;
    --primary-hover: #b84f0d;
    --success: #138a5b;
    --danger: #c73a45;
    --warning: #b77905;
    --blue: #286da8;
    --radius: 6px;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 15px;
}

/* Registration and platform settings controls stay compact and inline. */
.settings-form label.checkbox-label,
.settings-options label.checkbox-label,
.form-grid label.checkbox-label { display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: fit-content; min-height: 32px; }
.settings-form label.checkbox-label > input[type="checkbox"],
.settings-options label.checkbox-label > input[type="checkbox"],
.form-grid label.checkbox-label > input[type="checkbox"] { width: 18px; min-width: 18px; height: 18px; min-height: 18px; margin: 0; padding: 0; flex: 0 0 18px; }
.required-field::after { content: ' *'; color: var(--danger); font-weight: 700; }

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
button, a, input, select, summary { outline-offset: 3px; }

.app-page { display: flex; flex-direction: row; min-height: 100vh; }
.sidebar { order: 0; flex: 0 0 224px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-text); border-right: 1px solid #111a21; }
.brand { min-height: 72px; display: flex; gap: 11px; align-items: center; padding: 14px 18px; color: #fff; border-bottom: 1px solid #35414b; }
.brand:hover { text-decoration: none; background: #293640; }
.brand-mark { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 800; }
.brand strong, .brand small { display: block; letter-spacing: 0; }
.brand small { margin-top: 2px; color: #aeb9c2; font-size: 12px; }
.nav { display: grid; gap: 3px; padding: 14px 10px; }
.nav a { color: var(--sidebar-text); padding: 10px 12px; border-radius: 4px; }
.nav a:hover { background: #34424d; color: #fff; text-decoration: none; }
.logout-form { margin-top: auto; padding: 14px; }
.logout-form .button { width: 100%; color: #fff; border-color: #52606b; }

.main { order: 1; flex: 1 1 auto; min-width: 0; padding: 22px 26px 36px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.topbar h1 { margin: 0; font-size: 25px; line-height: 1.2; letter-spacing: 0; }
.account { text-align: right; }
.account strong, .account small { display: block; }
.account small { color: var(--muted); }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { min-height: 92px; display: flex; flex-direction: column; justify-content: center; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid #7a8792; border-radius: var(--radius); color: var(--text); }
.metric:hover { border-color: #aeb8c1; box-shadow: 0 3px 12px rgba(31, 41, 51, .08); text-decoration: none; }
.metric span { color: var(--muted); }
.metric strong { font-size: 27px; line-height: 1.1; margin-top: 5px; }
.metric-trial { border-top-color: var(--warning); }
.metric-active { border-top-color: var(--success); }
.metric-warning { border-top-color: var(--danger); }
.metrics-health { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.plan-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 16px; }
.plan-summary-card { display: grid; gap: 3px; min-height: 92px; padding: 14px; border: 1px solid var(--border); border-left: 4px solid var(--blue); border-radius: var(--radius); color: var(--text); background: #fbfcfd; }
.plan-summary-card:hover { border-color: var(--blue); box-shadow: 0 3px 12px rgba(31, 41, 51, .08); text-decoration: none; }
.plan-summary-card strong { font-size: 27px; line-height: 1.1; }
.plan-summary-card small { color: var(--muted); }

.split, .detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.section-block { margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tenant-settings-list { display: grid; gap: 14px; }
.tenant-category > summary { cursor: pointer; list-style: none; padding: 16px; font-size: 17px; font-weight: 700; color: var(--text); }
.tenant-category > summary::-webkit-details-marker { display: none; }
.tenant-category > summary::after { content: '▾'; float: right; color: var(--muted); }
.tenant-category[open] > summary { border-bottom: 1px solid var(--border); }
.tenant-category[open] > summary::after { content: '▴'; }
.tenant-category-body { padding: 16px; }
.tenant-category-body > .form-grid, .tenant-category-body > .details { margin: 0; }
.tenant-category-body .section-note { margin: 0 0 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.section-heading h2 { margin: 0; font-size: 17px; letter-spacing: 0; }
.section-note { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid #e7ebef; text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: #46515b; background: #fafbfc; font-size: 12px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.block { display: block; color: var(--muted); font-weight: 400; }
.table-action { font-weight: 600; }

.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 16px; }
.filters, .inline-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
label { display: grid; gap: 5px; color: #3d4852; font-size: 13px; font-weight: 600; }
label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 7px; width: fit-content; min-height: 28px; }
input, select { min-height: 40px; width: 100%; border: 1px solid #bdc7d0; border-radius: 4px; padding: 8px 10px; background: #fff; color: var(--text); }
input[type="checkbox"],
label.checkbox-label input[type="checkbox"],
label.checkbox input[type="checkbox"] { appearance: auto; width: 14px !important; min-width: 14px !important; max-width: 14px !important; height: 14px !important; min-height: 14px !important; max-height: 14px !important; margin: 0 !important; padding: 0 !important; flex: 0 0 14px !important; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40, 109, 168, .14); }
.filters label:first-of-type { width: min(390px, 65vw); }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 4px; padding: 8px 14px; cursor: pointer; font-weight: 650; text-align: center; }
.button:hover { text-decoration: none; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-hover); }
.button-success { background: var(--success); color: #fff; }
.button-danger { background: var(--danger); color: #fff; }
.button-quiet { background: transparent; border-color: #aeb8c1; color: var(--text); }
.button-small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.page-actions { margin-bottom: 12px; }

.notice { margin-bottom: 16px; border: 1px solid; border-radius: var(--radius); padding: 11px 14px; }
.notice-success { background: #e9f7f0; border-color: #a7d8c3; color: #0b6541; }
.notice-error { background: #fcecee; border-color: #e8afb5; color: #8f2330; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; background: #e7ebef; color: #3d4852; font-size: 12px; font-weight: 700; }
.badge-trial, .badge-pending { background: #fff0c7; color: #795003; }
.badge-active, .badge-completed { background: #d9f2e7; color: #0c6843; }
.badge-sent { background: #d9f2e7; color: #0c6843; }
.badge-suspended, .badge-failed { background: #f9dce0; color: #922a36; }
.badge-processing { background: #dcebf8; color: #1f5e91; }
.badge-cancelled { background: #e7ebef; color: #505b65; }
.badge-healthy { background: #d9f2e7; color: #0c6843; }
.badge-degraded { background: #fff0c7; color: #795003; }
.badge-down { background: #f9dce0; color: #922a36; }
.badge-unknown { background: #e7ebef; color: #505b65; }
.collapsible-block summary { display: flex; justify-content: space-between; gap: 16px; padding: 15px 16px; cursor: pointer; font-weight: 700; }
.collapsible-block[open] summary { border-bottom: 1px solid var(--border); }
.collapsible-block summary span { color: var(--muted); font-size: 13px; font-weight: 500; }

.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 16px; }
.form-grid-wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-actions { display: flex; align-items: end; }
.settings-form { display: grid; gap: 16px; padding: 16px; }
.settings-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: #fbfcfd; }
.settings-card h3 { margin: 0 0 12px; font-size: 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.settings-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 18px; }
.settings-fieldset { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.settings-fieldset legend { padding: 0 6px; font-weight: 700; }
.plan-row .plan-features,
.plan-create-form .plan-features,
.plan-edit-form .plan-features { grid-column: 1 / -1; width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.plan-features legend { padding: 0 6px; font-weight: 700; }
.plan-features .checkbox-label { display: flex; align-items: center; gap: 6px; min-height: 24px; white-space: normal; }
.settings-form .checkbox-label { min-height: 40px; align-items: center; }
.settings-email-item { margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius); background: #fbfcfd; }
.field-group { min-width: 0; }
.field-label { display: block; margin-bottom: 7px; font-weight: 650; color: var(--text); }
.email-test-row { display: flex; align-items: end; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.email-test-row label { flex: 1 1 320px; }
.email-image-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: #fafafa; }
.email-image-fields { display: none; }
.email-image-fields small { grid-column: 1 / -1; color: var(--muted); }
.email-library-upload { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.email-library-upload label { flex: 1 1 320px; }
.email-library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.email-library-item { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: 12px; }
.email-library-item img { width: 100%; height: 90px; object-fit: contain; background: #f8fafc; }
.settings-file-grid img.brand-preview { display: block !important; box-sizing: border-box; width: 220px !important; height: 90px !important; max-width: 220px !important; max-height: 90px !important; object-fit: contain !important; object-position: center; margin-top: 8px; border: 1px solid #d7dee7; padding: 6px; background: #fff; }
.settings-file-grid img.brand-preview-icon { width: 64px !important; height: 64px !important; max-width: 64px !important; max-height: 64px !important; }
.email-library-url { width: 100%; min-width: 0; box-sizing: border-box; padding: 6px 7px; border: 1px solid var(--border); border-radius: 4px; background: #f8fafc; color: var(--muted); font-size: 11px; }
.trumbowyg-editor img { max-width: 100%; height: auto; }
.email-editor-media-tools { display: none; align-items: end; gap: 10px; flex-wrap: wrap; padding: 10px 0; }
.email-editor-media-tools label { min-width: 170px; flex: 1 1 190px; }
@media (max-width: 760px) { .email-library-upload { align-items: stretch; flex-direction: column; } .email-editor-media-tools { align-items: stretch; flex-direction: column; } }
@media (max-width: 760px) { .email-test-row { align-items: stretch; flex-direction: column; } }
@media (max-width: 760px) { .email-image-fields { grid-template-columns: 1fr; } .email-image-fields small { grid-column: auto; } }
.settings-email-item > summary { cursor: pointer; padding: 13px 15px; font-weight: 700; }
.settings-email-item .settings-card { border: 0; border-top: 1px solid var(--border); border-radius: 0; }
.email-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 7px; border: 1px solid var(--border); border-bottom: 0; background: #edf2f5; }
.email-toolbar button { min-width: 30px; height: 28px; padding: 2px 8px; border: 1px solid #c9d3dc; background: #fff; color: #203047; cursor: pointer; }
.email-editor { min-height: 170px; padding: 12px; border: 1px solid var(--border); background: #fff; outline: none; }
.email-tool-full { min-width: 34px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-editor-fullscreen { position: fixed; inset: 16px; z-index: 1000; min-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.email-source { margin-top: 8px; min-height: 76px; font-family: Consolas, monospace; font-size: 12px; }
.campaign-selection { position: relative; display: inline-block; vertical-align: top; width: calc(33.333% - 12px); margin: 10px 12px 10px 0; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.campaign-selection[hidden] { display: none !important; }
.campaign-selection > summary { cursor: pointer; min-height: 40px; box-sizing: border-box; padding: 11px 32px 11px 12px; font-weight: 500; list-style: none; color: var(--text, #203047); position: relative; }
.campaign-selection > summary::-webkit-details-marker { display: none; }
.campaign-selection > summary:after { content: '▾'; position: absolute; right: 12px; color: var(--muted); }
.campaign-selection[open] > summary:after { content: '▴'; }
.campaign-selection-list { position: absolute; z-index: 30; top: calc(100% + 3px); left: -1px; right: -1px; max-height: 220px; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); background: #fff; box-shadow: 0 8px 18px rgba(32,48,71,.18); display: grid; grid-template-columns: 1fr; gap: 8px; }
.campaign-selection > .settings-options { position: absolute; z-index: 30; top: calc(100% + 3px); left: -1px; right: -1px; max-height: 220px; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); background: #fff; box-shadow: 0 8px 18px rgba(32,48,71,.18); display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (max-width: 700px) { .campaign-selection { display: block; width: 100%; margin-right: 0; } }
.tenant-category > summary { cursor: pointer; padding: 14px 16px; font-weight: 700; }
.tenant-category > summary::-webkit-details-marker { display: none; }
.tenant-category > summary:before { content: '▸'; display: inline-block; width: 20px; }
.tenant-category[open] > summary:before { content: '▾'; }
.tenant-category > .section-block { margin: 0; border: 0; border-radius: 0; }
.checkbox-label { display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: fit-content; min-height: 32px; }
.checkbox-label input[type="checkbox"] { width: 18px; min-width: 18px; height: 18px; min-height: 18px; margin: 0; padding: 0; flex: 0 0 18px; }
.required-legend { margin: 12px 16px 0; color: var(--muted); font-size: 13px; }
.required-field::after { content: ' *'; color: var(--danger); font-weight: 700; }
.inline-form { padding: 14px 16px; border-top: 1px solid var(--border); }
.inline-form label:first-of-type { width: min(420px, 70vw); }
.checkbox { display: flex; grid-auto-flow: column; align-items: center; justify-content: start; gap: 7px; min-height: 40px; }
.checkbox input { width: 17px; min-height: 17px; height: 17px; }
.details { margin: 0; padding: 7px 16px 14px; }
.details div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 14px; padding: 9px 0; border-bottom: 1px solid #edf0f2; }
.details div:last-child { border-bottom: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.lifecycle-details { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 12px; padding: 0; }
.lifecycle-details div { display: block; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fafbfc; }
.lifecycle-details dt { margin-bottom: 3px; font-size: 12px; }
.lifecycle-details dd { overflow-wrap: anywhere; }
.details.lifecycle-details { grid-column: 1 / -1 !important; width: 100%; min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 0; }
.details.lifecycle-details > div { display: block; min-width: 0; padding: 10px 12px; }

.plan-list { display: grid; }
.plans-table th, .plans-table td { white-space: normal; }
.plans-table td.plan-actions { min-width: 260px; white-space: nowrap; }
.inline-action { display: inline; }
.plan-edit-row > td { padding: 0; background: #fafbfc; }
.plan-edit-row details summary { padding: 11px 16px; cursor: pointer; color: var(--blue); font-weight: 650; }
.plan-edit-form { border-top: 1px solid var(--border); }
.plan-filters { align-items: end; }
.plan-filters label { min-width: 190px; }
.plan-filters label:first-of-type { width: min(380px, 50vw); }
.confirmation-content { max-width: 720px; display: grid; gap: 12px; padding: 20px 16px 24px; }
.confirmation-content p { margin: 0; }
.plan-row { display: grid; grid-template-columns: 100px 1.3fr repeat(4, minmax(110px, .7fr)) 95px 85px; align-items: end; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.plan-row:last-child { border-bottom: 0; }
.plan-code { min-height: 40px; display: flex; align-items: center; }
.block-value { display: block; margin-top: 4px; }
.plan-row-readonly { align-items: center; }
.create-panel summary { cursor: pointer; padding: 15px 16px; font-size: 17px; font-weight: 700; }
.queue-progress-row td { padding: 0 14px 12px; background: #fafbfc; }
.queue-progress-row details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 8px 0; }
.progress-track { height: 8px; overflow: hidden; border-radius: 99px; background: #e8edf1; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--success); }
.progress-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 16px; margin: 10px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 12px; }
.progress-list li { display: flex; gap: 6px; align-items: center; min-width: 0; }
.progress-list li.is-complete { color: var(--success); }
.progress-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.create-panel[open] summary { border-bottom: 1px solid var(--border); }
.error-block { padding: 24px; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: #edf1f4; }
.login-shell { width: min(430px, 100%); }
.login-help { margin: 18px 0 0; text-align: center; font-size: 14px; }
.login-help a { color: var(--primary); text-decoration: none; }
.login-help a:hover, .login-help a:focus { text-decoration: underline; }
.login-panel { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--primary); border-radius: var(--radius); padding: 28px; box-shadow: 0 14px 35px rgba(31, 41, 51, .12); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-brand strong, .login-brand small { display: block; }
.login-brand small { color: var(--muted); }
.login-panel h1 { margin: 0 0 20px; font-size: 23px; letter-spacing: 0; }

@media (max-width: 1120px) {
    .metrics { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
    .plan-row { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .plan-row .plan-features, .plan-create-form .plan-features { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
    .form-grid-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-page { display: block; }
    .sidebar { position: sticky; z-index: 10; height: auto; top: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
    .brand { min-height: 58px; padding: 9px 12px; border: 0; }
    .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
    .nav { display: flex; overflow-x: auto; padding: 8px; scrollbar-width: thin; }
    .nav a { white-space: nowrap; padding: 8px 10px; }
    .logout-form { margin: 0; padding: 8px; }
    .logout-form .button { min-height: 36px; width: auto; }
    .main { padding: 18px 14px 28px; }
    .topbar { align-items: start; }
    .topbar h1 { font-size: 22px; }
    .account { display: none; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split, .detail-grid, .form-grid, .form-grid-wide { grid-template-columns: 1fr; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .filters { align-items: stretch; }
    .filters label, .filters label:first-of-type, .inline-form label:first-of-type { width: 100%; }
    .plan-row { grid-template-columns: 1fr; }
    .plan-row .plan-features, .plan-create-form .plan-features { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    .settings-grid, .settings-options { grid-template-columns: 1fr; }
    .details div { grid-template-columns: 1fr; gap: 3px; }
    .lifecycle-details, .details.lifecycle-details, .progress-list { grid-template-columns: 1fr; }
}
