/*
 * MXT shared interface theme
 *
 * Shared palette loaded before the current React feature styles (after local
 * CSS in retained pages). Every rule is opt-in through body.mxt-ui; authored
 * documents and editor-internal themes keep their own presentation contract.
 */

body.mxt-ui {
  --mxt-brand: #0b5fff;
  --mxt-brand-strong: #084bc6;
  --mxt-brand-soft: #eaf2ff;
  /* Foreground belongs to the filled surface, not to the surrounding page. */
  --mxt-on-brand: #ffffff;
  --mxt-accent: #08758a;
  --mxt-accent-soft: #e5f7fa;
  --mxt-canvas: #f5f8ff;
  --mxt-surface: #ffffff;
  --mxt-surface-muted: #f0f6ff;
  --mxt-text: #0b1846;
  --mxt-muted: #53627c;
  --mxt-line: #dce6f5;
  --mxt-control-border: #7588a8;
  --mxt-control-height: 44px;
  --mxt-control-font-size: 16px;
  --mxt-control-line-height: 24px;
  --mxt-control-padding-block: 8px;
  --mxt-control-padding-inline: 12px;
  --mxt-select-padding-end: 40px;
  --mxt-select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%2353627c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --mxt-focus: #0b5fff;
  --mxt-success: #147d60;
  --mxt-warning: #925700;
  --mxt-danger: #c7364b;
  --mxt-danger-soft: #fff3f5;
  --mxt-radius: 12px;
  --mxt-radius-sm: 8px;
  --mxt-shadow: 0 4px 20px rgba(37, 82, 145, .05);
  --mxt-ink: var(--mxt-text);
  --mxt-soft: var(--mxt-surface-muted);
  --mxt-line-strong: var(--mxt-control-border);
  --mxt-font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;

  /* Compatibility aliases used by the existing independent modules. */
  --mxt-text-muted: var(--mxt-muted);
  --mxt-border: var(--mxt-line);
  --mxt-link: var(--mxt-brand);
  --mxt-error: var(--mxt-danger);
  --mxt-bad: var(--mxt-danger);
  --capture-primary: var(--mxt-brand);
  --capture-primary-dark: var(--mxt-brand-strong);
  --capture-accent: var(--mxt-brand);
  --capture-bg: var(--mxt-canvas);
  --capture-card: var(--mxt-surface);
  --capture-text: var(--mxt-text);
  --capture-muted: var(--mxt-muted);
  --capture-border: var(--mxt-line);
  --capture-shadow: var(--mxt-shadow);
  --bg: var(--mxt-canvas);
  --canvas: var(--mxt-canvas);
  --bg-color: var(--mxt-canvas);
  --bg-base: var(--mxt-canvas);
  --bg-primary: var(--mxt-canvas);
  --surface: var(--mxt-surface);
  --card-bg: var(--mxt-surface);
  --bg-white: var(--mxt-surface);
  --bg-card: var(--mxt-surface);
  --surface-muted: var(--mxt-surface-muted);
  --bg-muted: var(--mxt-surface-muted);
  --bg-secondary: var(--mxt-surface-muted);
  --bg-hover: var(--mxt-brand-soft);
  --text: var(--mxt-text);
  --text-color: var(--mxt-text);
  --text-primary: var(--mxt-text);
  --text-secondary: var(--mxt-muted);
  --text-light: var(--mxt-muted);
  --text-muted: var(--mxt-muted);
  --muted: var(--mxt-muted);
  --line: var(--mxt-line);
  --border: var(--mxt-line);
  --border-color: var(--mxt-line);
  --primary: var(--mxt-brand);
  --primary-color: var(--mxt-brand);
  --primary-light: #3981ff;
  --primary-lighter: #8dbbff;
  --primary-hover: var(--mxt-brand-strong);
  --primary-strong: var(--mxt-brand-strong);
  --accent: var(--mxt-brand);
  --accent-hover: var(--mxt-brand-strong);
  --accent-strong: var(--mxt-brand-strong);
  --soft: var(--mxt-brand-soft);
  --focus: var(--mxt-focus);
  --shadow: var(--mxt-shadow);

  min-height: 100vh;
  margin: 0;
  color: var(--mxt-text);
  background: var(--mxt-canvas);
  font-family: var(--mxt-font);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="dark"] body.mxt-ui {
  /* Optional aliases for legacy literal colors; fallbacks keep light mode intact. */
  --mxt-theme-surface: var(--mxt-surface);
  --mxt-theme-soft: var(--mxt-surface-muted);
  --mxt-theme-ink: var(--mxt-text);
  --mxt-theme-muted: var(--mxt-muted);
  --mxt-theme-line: var(--mxt-line);
  --mxt-theme-link: var(--mxt-brand);
  --mxt-theme-info: var(--mxt-brand-soft);
  --mxt-theme-good: #16372f;
  --mxt-theme-goodink: #75d4b7;
  --mxt-theme-warn: #352b18;
  --mxt-theme-warnink: #f7d488;
  --mxt-theme-bad: #38202a;
  --mxt-theme-badink: #ffa9b4;
  --ink: var(--mxt-text);
  --page: var(--mxt-canvas);
  --card: var(--mxt-surface);
  --brand: var(--mxt-brand);
  --brand-dark: var(--mxt-brand-strong);
  --sidebar-bg: var(--mxt-surface);
  --warning-bg: #352b18;
  --warning-text: #f7d488;
  --danger-bg: #38202a;
  --mxt-success: #75d4b7;
  --mxt-warning: #f7d488;
  --mxt-danger: #ffa9b4;
  --mxt-danger-soft: #38202a;
  --mxt-accent: #81d5e3;
  --mxt-accent-soft: #15343a;
  --mxt-canvas: #0b1220;
  --mxt-surface: #182131;
  --mxt-surface-muted: #111827;
  --mxt-text: #f1f5f9;
  --mxt-muted: #a8b3c5;
  --mxt-line: #344155;
  --mxt-brand: #8dbbff;
  --mxt-brand-strong: #b8d4ff;
  --mxt-brand-soft: #182f51;
  --mxt-on-brand: #0b1846;
  --mxt-control-border: #8193ae;
  --mxt-select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23a8b3c5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --mxt-focus: #93c5fd;
  --bg: var(--mxt-canvas);
  --canvas: var(--mxt-canvas);
  --bg-color: var(--mxt-canvas);
  --bg-base: var(--mxt-canvas);
  --surface: var(--mxt-surface);
  --card-bg: var(--mxt-surface);
  --bg-white: var(--mxt-surface);
  --surface-muted: var(--mxt-surface-muted);
  --bg-muted: var(--mxt-surface-muted);
  --text: var(--mxt-text);
  --text-color: var(--mxt-text);
  --text-primary: var(--mxt-text);
  --text-secondary: var(--mxt-muted);
  --text-muted: var(--mxt-muted);
  --muted: var(--mxt-muted);
  --line: var(--mxt-line);
  --border: var(--mxt-line);
  --border-color: var(--mxt-line);
  --primary: var(--mxt-brand);
  --primary-color: var(--mxt-brand);
  --primary-hover: var(--mxt-brand-strong);
  --primary-strong: var(--mxt-brand-strong);
  --focus: var(--mxt-focus);
  color-scheme: dark;
}

/* Legacy nested surfaces not backed by the original shared aliases. */
html[data-theme="dark"] body.mxt-ui :is(.tips-box,.plan-status-note,.model-chain-status,.mxt-connection-error) {
  background: var(--mxt-brand-soft);
  color: var(--mxt-text);
  border-color: var(--mxt-line);
}
html[data-theme="dark"] body.mxt-ui :is(.button:not(.secondary),.btn-primary,.primary-button,.btn-submit,.accept,.mxt-outcome-button:not(.mxt-outcome-button--secondary)) {
  color: var(--mxt-on-brand);
}
html[data-theme="dark"] body.mxt-ui--notes :is(.bg-light,.bg-white) {
  background-color: var(--mxt-surface-muted) !important;
  color: var(--mxt-text);
}
html[data-theme="dark"] body.mxt-ui--notes #note-list .list-group-item {
  color: var(--mxt-text);
  background: var(--mxt-surface);
  border-color: var(--mxt-line);
}
html[data-theme="dark"] body.mxt-ui--notes #note-list .list-group-item:is(:hover,.active) {
  background: var(--mxt-brand-soft);
}
html[data-theme="dark"] body.mxt-ui--console .persona-config-toggle {
  color: var(--mxt-text);
  background: var(--mxt-surface);
}
html[data-theme="dark"] body.mxt-ui--notes .jstree-default :is(.jstree-hovered,.jstree-clicked) {
  background: var(--mxt-brand-soft);
  color: var(--mxt-text);
  box-shadow: none;
}
html[data-theme="dark"] body.mxt-ui :is(.chat-bubble,.markdown-content,.analysis-content) a {
  color: var(--mxt-brand);
}

body.mxt-ui *,
body.mxt-ui *::before,
body.mxt-ui *::after {
  box-sizing: border-box;
}

/* Keep hints readable without outranking the shell's collapsed-search hint or
   changing vendor editor internals. UA placeholder colors are not theme tokens. */
body.mxt-ui :where(input,textarea):not(:where(.vditor *,.cm-editor *,.monaco-editor *))::placeholder {
  color: var(--mxt-muted);
  opacity: 1;
}

body.mxt-ui :focus-visible {
  outline: 2px solid var(--mxt-focus);
  outline-offset: 2px;
}

body.mxt-ui a {
  text-underline-offset: 3px;
}

body.mxt-ui button,
body.mxt-ui input,
body.mxt-ui select,
body.mxt-ui textarea {
  font: inherit;
}

body.mxt-ui input,
body.mxt-ui select,
body.mxt-ui textarea {
  color: var(--mxt-text);
  background-color: var(--mxt-surface);
  border-color: var(--mxt-control-border);
}

/* Text fields share metrics, not layout. Leave native pickers and editor
 * internals alone; a textarea's content height and a composer's width stay local. */
body.mxt-ui :is(input,select,textarea):not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not(:where([type="range"],[type="color"],[type="file"],[type="button"],[type="submit"],[type="reset"],.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: var(--mxt-control-padding-block) var(--mxt-control-padding-inline);
  border: 1px solid var(--mxt-control-border);
  border-radius: var(--mxt-radius-sm);
  font-size: var(--mxt-control-font-size);
  line-height: var(--mxt-control-line-height);
  font-weight: 400;
}

body.mxt-ui :is(input,select):not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not(:where([type="range"],[type="color"],[type="file"],[type="button"],[type="submit"],[type="reset"],.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
  min-height: var(--mxt-control-height);
}
/* A multiline editor is not a single-line control. Zero specificity makes
 * this only a fallback; page editors and the compact assistant retain theirs. */
:where(body.mxt-ui textarea:not([hidden],.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
  min-height: 120px;
  resize: vertical;
}

/* Geometry only: colors, width, emphasis, multiline content and primary-action
 * minimums remain owned by the page. No display or fixed height is imposed. */
body.mxt-ui :is(button,.button,.btn):not(:where(.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
  min-height: var(--mxt-control-height);
  padding-block: var(--mxt-control-padding-block);
  line-height: var(--mxt-control-line-height);
}

/* Native select semantics, one consistently inset chevron. A listbox is not a
 * dropdown; high-contrast mode below deliberately restores the system arrow. */
body.mxt-ui select:not([multiple]):not([size]):not([hidden]):not(:where(.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
  -webkit-appearance: none;
  appearance: none;
  padding-inline-end: var(--mxt-select-padding-end);
  background-image: var(--mxt-select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}
body.mxt-ui select:not([multiple]):not([size]):not([hidden]):dir(rtl) { background-position: left 12px center; }
@media (forced-colors: active) {
  body.mxt-ui select:not([multiple]):not([size]):not([hidden]):not(:where(.vditor *,.cm-editor *,.monaco-editor *,.mxt-oauth-card *)) {
    -webkit-appearance: auto;
    appearance: auto;
    background-image: none;
    padding-inline-end: var(--mxt-control-padding-inline);
  }
}

body.mxt-ui input:focus,
body.mxt-ui select:focus,
body.mxt-ui textarea:focus {
  border-color: var(--mxt-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mxt-focus) 12%, transparent);
  outline: 0;
}

/* These application dialogs can live outside their page's styled ancestor.
 * Keep the native dialog, original actions, busy guards and focus lifecycle. */
/* Opt-in frame shared by existing domain adapters. Keep this in the already
 * loaded brand sheet, not duplicated in each page's closed resource bundle. */
body.mxt-ui dialog.mxt-dialog-layout[open] { display:flex; flex-direction:column; overflow:hidden; }
body.mxt-ui dialog.mxt-dialog-layout > :is(header,footer) { flex:0 0 auto; min-width:0; }
body.mxt-ui dialog.mxt-dialog-layout > header { flex-wrap:nowrap; align-items:flex-start; }
body.mxt-ui dialog.mxt-dialog-layout > header > :is(h2,h3) { min-width:0; overflow-wrap:anywhere; }
body.mxt-ui dialog.mxt-dialog-layout > header > button { flex:0 0 auto; white-space:nowrap; }
body.mxt-ui dialog.mxt-dialog-layout > .mxt-dialog-scroll { flex:1 1 auto; min-height:0; max-height:none; overflow:auto; overscroll-behavior:contain; scroll-padding:16px; }
body.mxt-ui :is(.console-modal,.agent-workspace-dialog,.growth-review-dialog,.growth-execution-dialog,.charter-dialog,.mxt-react-dialog) {
  min-width: 0;
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
}
body.mxt-ui :is(.console-modal,.agent-workspace-dialog,.growth-review-dialog,.growth-execution-dialog,.charter-dialog,.mxt-react-dialog) > :is(header,.agent-workspace-header) {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}
body.mxt-ui :is(.console-modal,.agent-workspace-dialog,.growth-review-dialog,.growth-execution-dialog,.charter-dialog,.mxt-react-dialog) > :is(header,.agent-workspace-header) > :is(h2,h3) {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  font-size: 20px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
body.mxt-ui :is(.console-modal,.agent-workspace-dialog,.growth-review-dialog,.growth-execution-dialog,.charter-dialog,.mxt-react-dialog) > :is(header,.agent-workspace-header) > button {
  flex-shrink: 0;
  margin: 0;
}
body.mxt-ui :is(.console-modal,.agent-workspace-dialog) {
  --mxt-dialog-padding: 24px;
  scroll-padding-block: 96px 24px;
}
body.mxt-ui :is(.console-modal,.agent-workspace-dialog) > :is(header,.agent-workspace-header) {
  position: sticky;
  top: calc(-1 * var(--mxt-dialog-padding));
  margin: calc(-1 * var(--mxt-dialog-padding)) calc(-1 * var(--mxt-dialog-padding)) 16px;
  padding: 16px var(--mxt-dialog-padding);
  background: var(--mxt-surface);
  border-bottom: 1px solid var(--mxt-line);
  z-index: 2;
}
body.mxt-ui :is(.growth-review-dialog,.growth-execution-dialog) > header {
  position: sticky;
  top: 0;
  background: var(--mxt-surface);
  z-index: 2;
}
body.mxt-ui .console-modal .console-field :is(input,select,textarea) { width: 100%; }
body.mxt-ui .console-modal small { font-size: 14px; color: var(--mxt-muted); }
@media (max-width: 600px) {
  body.mxt-ui :is(.console-modal,.agent-workspace-dialog) { --mxt-dialog-padding: 16px; }
}

/* Shared headers, navigation and panels. */
body.mxt-ui .topbar,
body.mxt-ui .app-header,
body.mxt-ui .navbar,
body.mxt-ui .portal-header,
body.mxt-ui .admin-header {
  color: var(--mxt-text);
  background: color-mix(in srgb, var(--mxt-surface) 96%, transparent);
  border-color: var(--mxt-line);
  box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
}

body.mxt-ui .workflow-nav,
body.mxt-ui .source-nav {
  border-color: var(--mxt-line);
  background: var(--mxt-surface-muted);
}

body.mxt-ui .workflow-nav a,
body.mxt-ui .source-nav a {
  color: var(--mxt-muted);
}

body.mxt-ui .workflow-nav a:hover,
body.mxt-ui .source-nav a:hover {
  color: var(--mxt-brand-strong);
  background: var(--mxt-surface);
}

body.mxt-ui .workflow-nav a[aria-current="page"],
body.mxt-ui .source-nav a[aria-current="page"] {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
}

body.mxt-ui .brand,
body.mxt-ui .brand-mark {
  background: linear-gradient(145deg, var(--mxt-brand-strong), var(--mxt-brand));
  color: var(--mxt-on-brand);
}

body.mxt-ui .card,
body.mxt-ui .panel,
body.mxt-ui .section-block,
body.mxt-ui .candidate-card,
body.mxt-ui .stat-card,
body.mxt-ui .operation-card,
body.mxt-ui .metric,
body.mxt-ui .toolbar,
body.mxt-ui .table-wrapper,
body.mxt-ui .command-bar,
body.mxt-ui .summary-strip,
body.mxt-ui .signal-panel,
body.mxt-ui .plans-section,
body.mxt-ui .operations-section {
  background: var(--mxt-surface);
  border-color: var(--mxt-line);
  border-radius: var(--mxt-radius);
  box-shadow: var(--mxt-shadow);
}

body.mxt-ui .button,
body.mxt-ui .btn,
body.mxt-ui button {
  border-radius: var(--mxt-radius-sm);
}

body.mxt-ui .button:not(.secondary),
body.mxt-ui .btn-primary,
body.mxt-ui .primary-button,
body.mxt-ui .btn-submit,
body.mxt-ui .accept {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
  border-color: var(--mxt-brand);
}

body.mxt-ui .button:not(.secondary):hover,
body.mxt-ui .btn-primary:hover,
body.mxt-ui .primary-button:hover,
body.mxt-ui .btn-submit:hover,
body.mxt-ui .accept:hover {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand-strong);
  border-color: var(--mxt-brand-strong);
}

body.mxt-ui .button.secondary,
body.mxt-ui .btn-secondary,
body.mxt-ui .secondary-button,
body.mxt-ui .quiet-button,
body.mxt-ui .small-button {
  color: var(--mxt-text);
  background: var(--mxt-surface);
  border-color: var(--mxt-line);
}

body.mxt-ui .button.secondary:hover,
body.mxt-ui .btn-secondary:hover,
body.mxt-ui .secondary-button:hover,
body.mxt-ui .quiet-button:hover,
body.mxt-ui .small-button:hover {
  color: var(--mxt-brand-strong);
  background: var(--mxt-brand-soft);
  border-color: #c7d2fe;
}

body.mxt-ui .empty,
body.mxt-ui .empty-state {
  color: var(--mxt-muted);
  background: var(--mxt-surface);
  border-color: #cbd5e1;
}

body.mxt-ui dialog,
body.mxt-ui .modal-dialog,
body.mxt-ui .modal-content {
  color: var(--mxt-text);
  background: var(--mxt-surface);
  border-color: var(--mxt-line);
  border-radius: var(--mxt-radius);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .2);
}

/* Universal inbox. */
body.mxt-ui--inbox .topbar {
  min-height: 76px;
  padding-top: .75rem;
  padding-bottom: .75rem;
}

body.mxt-ui--inbox .brand,
body.mxt-ui--proposal .brand,
body.mxt-ui--lifeops .brand-mark {
  overflow: hidden;
  color: transparent;
  background: var(--mxt-surface) url("/assets/mxt-mark.svg?v=20260907-g5") center / cover no-repeat;
  text-indent: -999px;
}

body.mxt-ui--inbox .topbar h1,
body.mxt-ui--review .topbar h1 {
  letter-spacing: -.025em;
}

body.mxt-ui--inbox .notice {
  background: var(--mxt-brand-soft);
  border-color: #c7d2fe;
}

body.mxt-ui--inbox .notice summary,
body.mxt-ui--inbox code {
  color: var(--mxt-brand-strong);
}

body.mxt-ui--inbox code {
  background: var(--mxt-surface);
  border-color: #c7d2fe;
}

body.mxt-ui--inbox .filters .active {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
  border-color: var(--mxt-brand);
}

body.mxt-ui--inbox .candidate-card {
  border-left: 3px solid var(--mxt-brand);
}

body.mxt-ui--inbox .kind-badge {
  color: var(--mxt-brand-strong);
  background: var(--mxt-brand-soft);
}

body.mxt-ui--inbox .source-box {
  background: var(--mxt-surface-muted);
  border-left-color: #a5b4fc;
}

/* Reviews and action plan proposals. */
body.mxt-ui--review .button.secondary,
body.mxt-ui--proposal header > a:last-child,
body.mxt-ui--review .back-link {
  color: var(--mxt-brand);
}

body.mxt-ui--review .segment.active {
  color: var(--mxt-brand-strong);
  background: var(--mxt-surface);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

body.mxt-ui--review .segmented {
  background: var(--mxt-brand-soft);
}

body.mxt-ui--review .plan-item::before {
  color: var(--mxt-brand-strong);
  background: var(--mxt-brand-soft);
}

body.mxt-ui--review .narrative-block {
  border-left: 4px solid var(--mxt-brand);
}

body.mxt-ui--proposal .explain {
  background: var(--mxt-brand-soft);
  border-color: #c7d2fe;
}

body.mxt-ui--proposal .manual-import summary {
  color: var(--mxt-brand-strong);
}

body.mxt-ui--proposal button.active {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
  border-color: var(--mxt-brand);
}

body.mxt-ui--proposal .weather {
  background: var(--mxt-surface-muted);
  border-left-color: #a5b4fc;
}

/* Personal operations cockpit and secretary. */
body.mxt-ui--lifeops .app-header {
  backdrop-filter: blur(12px);
}

body.mxt-ui--lifeops .command-bar {
  border-top: 4px solid var(--mxt-brand);
}

body.mxt-ui--lifeops .eyebrow,
body.mxt-ui--lifeops .operation-card > header span {
  color: var(--mxt-brand);
}

body.mxt-ui--lifeops .tabs button[aria-selected="true"] {
  color: var(--mxt-brand);
  border-bottom-color: var(--mxt-brand);
}

body.mxt-ui--lifeops .plan-change,
body.mxt-ui--lifeops .narrative-block {
  border-left-color: var(--mxt-brand);
}

body.mxt-ui--secretary .navbar {
  min-height: 68px;
}

body.mxt-ui--secretary .stat-card {
  border-top: 3px solid transparent;
}

body.mxt-ui--secretary .stat-card:nth-child(1) { border-top-color: var(--mxt-brand); }
body.mxt-ui--secretary .stat-card:nth-child(2) { border-top-color: #f97316; }
body.mxt-ui--secretary .stat-card:nth-child(3) { border-top-color: #22c55e; }
body.mxt-ui--secretary .stat-card:nth-child(4) { border-top-color: #94a3b8; }

body.mxt-ui--secretary .filter-tab.active,
body.mxt-ui--secretary .filter-tabs button.active {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
  border-color: var(--mxt-brand);
}

/* Large consoles: keep the proven sidebar interaction, use the shared palette. */
body.mxt-ui--console,
body.mxt-ui--prompt {
  --sidebar-bg: #ffffff;
  --sidebar-text: var(--mxt-muted);
  --sidebar-active: var(--mxt-text);
}

body.mxt-ui--console .sidebar,
body.mxt-ui--prompt .sidebar {
  color: var(--mxt-muted);
  background: var(--mxt-surface);
  border-right: 1px solid var(--mxt-line);
  box-shadow: 8px 0 28px rgba(15, 23, 42, .035);
}

body.mxt-ui--console .sidebar-header,
body.mxt-ui--prompt .sidebar-header,
body.mxt-ui--console .sidebar-user,
body.mxt-ui--prompt .sidebar-user {
  border-color: var(--mxt-line);
}

body.mxt-ui--console .sidebar-header h1,
body.mxt-ui--prompt .sidebar-header h1 {
  color: var(--mxt-text);
}

body.mxt-ui--console .sidebar-header .back-portal,
body.mxt-ui--console .sidebar-header .logout-btn,
body.mxt-ui--prompt .sidebar-header .back-portal,
body.mxt-ui--prompt .sidebar-header .logout-btn,
body.mxt-ui--console .sidebar-user .user-link,
body.mxt-ui--prompt .sidebar-user .user-link {
  color: var(--mxt-muted);
  background: var(--mxt-surface-muted);
}

body.mxt-ui--console .sidebar-user .user-email,
body.mxt-ui--prompt .sidebar-user .user-email {
  color: var(--mxt-muted);
}

body.mxt-ui--console .nav-item,
body.mxt-ui--prompt .nav-item {
  margin: 2px 10px;
  color: var(--mxt-muted);
  border-radius: var(--mxt-radius-sm);
}

body.mxt-ui--console .nav-item:hover,
body.mxt-ui--prompt .nav-item:hover {
  color: var(--mxt-brand-strong);
  background: var(--mxt-brand-soft);
}

body.mxt-ui--console .nav-item.active,
body.mxt-ui--prompt .nav-item.active {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
}

body.mxt-ui--console .page-header,
body.mxt-ui--prompt .page-header {
  border-bottom-color: var(--mxt-line);
}

body.mxt-ui--console .card,
body.mxt-ui--prompt .card {
  overflow: clip;
}

/* Data crawler: replace the isolated dark theme with the shared light canvas. */
body.mxt-ui--crawler {
  --bg-primary: var(--mxt-canvas);
  --bg-secondary: var(--mxt-surface-muted);
  --bg-card: var(--mxt-surface);
  --bg-hover: var(--mxt-brand-soft);
  --text-primary: var(--mxt-text);
  --text-secondary: var(--mxt-muted);
  --text-muted: #94a3b8;
  --border-color: var(--mxt-line);
  --accent: var(--mxt-brand);
  --accent-hover: var(--mxt-brand-strong);
}

body.mxt-ui--crawler .app-header {
  background: var(--mxt-surface);
}

body.mxt-ui--crawler .task-card,
body.mxt-ui--crawler .result-card,
body.mxt-ui--crawler .merge-panel,
body.mxt-ui--crawler .config-panel {
  background: var(--mxt-surface);
  border-color: var(--mxt-line);
  border-radius: var(--mxt-radius);
  box-shadow: var(--mxt-shadow);
}

body.mxt-ui--crawler .tab-btn.active {
  color: var(--mxt-brand);
  border-bottom-color: var(--mxt-brand);
}

/* Cloud notes: harmonise Bootstrap chrome without changing editor behavior. */
body.mxt-ui--notes .navbar.bg-dark {
  color: var(--mxt-text);
  background: var(--mxt-surface) !important;
  border-color: var(--mxt-line) !important;
}

body.mxt-ui--notes .navbar .navbar-brand,
body.mxt-ui--notes .navbar .text-light,
body.mxt-ui--notes .navbar .btn-link.text-light {
  color: var(--mxt-text) !important;
}

body.mxt-ui--notes .navbar .btn-outline-light {
  color: var(--mxt-brand);
  border-color: #c7d2fe;
}

body.mxt-ui--notes .sidebar,
body.mxt-ui--notes .note-list-col,
body.mxt-ui--notes .editor-col {
  background: var(--mxt-surface) !important;
}

body.mxt-ui--notes .note-item.active,
body.mxt-ui--notes .list-group-item.active {
  color: var(--mxt-brand-strong);
  background: var(--mxt-brand-soft);
  border-color: #c7d2fe;
}

body.mxt-ui--notes .resizer {
  background: var(--mxt-line);
}

/* Portal, login and administration remain the reference implementation. */
body.mxt-ui--portal .welcome-section {
  background: linear-gradient(120deg, #3730a3 0%, #4f46e5 56%, #7c3aed 100%);
}

body.mxt-ui--portal .workflow-card,
body.mxt-ui--portal .quick-card,
body.mxt-ui--admin .table-wrapper {
  border-color: var(--mxt-line);
  border-radius: var(--mxt-radius);
}

body.mxt-ui--login {
  background: radial-gradient(circle at 18% 12%, #dfedff, transparent 42%), var(--mxt-canvas);
}

body.mxt-ui--login .login-card {
  border: 1px solid rgba(255, 255, 255, .64);
  border-radius: 16px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .32);
}

body.mxt-ui--login .tab-item.active,
body.mxt-ui--admin .logo i,
body.mxt-ui--admin .badge {
  color: var(--mxt-brand);
}

body.mxt-ui--admin .btn-refresh {
  color: var(--mxt-on-brand);
  background: var(--mxt-brand);
}

/* Shared structured task outcome dialog. It is injected by the shared script
   so every task surface uses the same validation and owned API. */
.mxt-outcome-dialog {
  width: min(680px, calc(100% - 24px));
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--mxt-line, #dfe3ea);
  border-radius: 16px;
  color: var(--mxt-ink, #171b26);
  background: var(--mxt-surface, #fff);
  box-shadow: 0 28px 80px rgba(15, 23, 42, .24);
}

.mxt-outcome-dialog::backdrop { background: rgba(15, 23, 42, .52); }
.mxt-outcome-form { padding: 22px; overflow: auto; max-height: 90vh; }
.mxt-outcome-header { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 15px; border-bottom: 1px solid var(--mxt-line, #dfe3ea); }
.mxt-outcome-header h2 { margin: 2px 0 0; font-size: 21px; }
.mxt-outcome-kicker { margin: 0; color: var(--mxt-brand, #4f46e5); font-weight: 750; font-size: 12px; letter-spacing: .06em; }
.mxt-outcome-close { width: 38px; height: 38px; padding: 0; border: 0; border-radius: 9px; color: var(--mxt-muted, #667085); background: transparent; font-size: 26px; cursor: pointer; }
.mxt-outcome-close:hover { background: var(--mxt-soft, #f5f6fa); }
.mxt-outcome-task { margin: 16px 0 5px; color: var(--mxt-ink, #171b26); font-weight: 700; overflow-wrap: anywhere; }
.mxt-outcome-helper { margin: 0 0 16px; color: var(--mxt-muted, #667085); font-size: 13px; line-height: 1.55; }
.mxt-outcome-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mxt-outcome-field { display: grid; gap: 6px; color: var(--mxt-muted, #667085); font-size: 13px; font-weight: 650; }
.mxt-outcome-field--full { grid-column: 1 / -1; }
.mxt-outcome-field input, .mxt-outcome-field select, .mxt-outcome-field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--mxt-line-strong, #cdd3df); border-radius: 9px; color: var(--mxt-ink, #171b26); background: var(--mxt-surface, #fff); font: inherit; font-weight: 400; }
.mxt-outcome-field textarea { resize: vertical; }
.mxt-outcome-field input:focus, .mxt-outcome-field select:focus, .mxt-outcome-field textarea:focus { outline: 3px solid rgba(79, 70, 229, .16); border-color: var(--mxt-brand, #4f46e5); }
.mxt-outcome-status { min-height: 24px; margin: 9px 0 0; color: var(--mxt-muted, #667085); font-size: 13px; }
.mxt-outcome-status.error { color: var(--mxt-danger, #b42318); }
.mxt-outcome-form [hidden] { display: none !important; }
.mxt-outcome-saved { padding: 14px 16px; border: 1px solid var(--mxt-line, #dfe3ea); border-radius: 12px; background: var(--mxt-soft, #f5f8ff); overflow-wrap: anywhere; }
.mxt-outcome-saved p { margin: 8px 0; line-height: 1.65; }
.mxt-outcome-note { white-space: pre-wrap; }
.mxt-outcome-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 8px; }
.mxt-outcome-button { min-height: 42px; padding: 9px 15px; border: 1px solid var(--mxt-brand, #4f46e5); border-radius: 9px; color: var(--mxt-on-brand, #fff); background: var(--mxt-brand, #4f46e5); font: inherit; font-weight: 700; cursor: pointer; }
.mxt-outcome-button:disabled { opacity: .6; cursor: wait; }
.mxt-outcome-button--secondary { color: var(--mxt-brand, #4f46e5); background: var(--mxt-surface, #fff); }

@media (max-width: 1024px) {
  body.mxt-ui .topbar,
  body.mxt-ui .portal-header,
  body.mxt-ui .admin-header {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

@media (max-width: 768px) {
  body.mxt-ui .topbar,
  body.mxt-ui .navbar,
  body.mxt-ui .app-header {
    position: relative;
  }

  body.mxt-ui .card,
  body.mxt-ui .panel,
  body.mxt-ui .section-block,
  body.mxt-ui .candidate-card,
  body.mxt-ui .toolbar,
  body.mxt-ui .command-bar {
    border-radius: 10px;
  }

  body.mxt-ui--console .sidebar,
  body.mxt-ui--prompt .sidebar {
    box-shadow: 18px 0 45px rgba(15, 23, 42, .16);
  }
}

@media (max-width: 480px) {
  body.mxt-ui {
    font-size: 16px;
  }

  body.mxt-ui button,
  body.mxt-ui .button,
  body.mxt-ui .btn {
    min-height: 42px;
  }

  .mxt-outcome-fields { grid-template-columns: 1fr; }
  .mxt-outcome-field--full { grid-column: auto; }
  .mxt-outcome-actions { flex-direction: column-reverse; }
  .mxt-outcome-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  body.mxt-ui *,
  body.mxt-ui *::before,
  body.mxt-ui *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
