/* Dialog system: every popup (forms, confirmations, side sheet, command palette) shares this look.
   Colours come from the theme variables, so light and dark themes both work. */

.mx-backdrop {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px;
  background: rgba(8, 14, 28, .52); backdrop-filter: blur(6px) saturate(120%);
  animation: mx-fade .18s ease both;
}
.mx-backdrop.closing { animation: mx-fade-out .14s ease both; }
.mx-backdrop.mx-sheet-backdrop { place-items: stretch end; padding: 0; }

.mx {
  --mx-radius: 18px;
  position: relative; display: flex; flex-direction: column; width: 100%; max-height: min(88vh, 900px);
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--mx-radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 30px 80px rgba(6, 12, 30, .35), 0 8px 24px rgba(6, 12, 30, .18);
  overflow: hidden; animation: mx-pop .22s cubic-bezier(.2, .9, .3, 1.2) both;
}
.closing .mx { animation: mx-pop-out .14s ease both; }
.mx-sm { max-width: 440px; }
.mx-md { max-width: 600px; }
.mx-lg { max-width: 780px; }
.mx-xl { max-width: 1080px; }

/* Side sheet (notes) */
.mx.mx-sheet { max-width: 560px; height: 100vh; max-height: none; border-radius: var(--mx-radius) 0 0 var(--mx-radius); border-right: 0; animation: mx-slide .24s cubic-bezier(.2, .8, .2, 1) both; }
.closing .mx.mx-sheet { animation: mx-slide-out .16s ease both; }

/* Header */
.mx-head { display: flex; align-items: center; gap: 14px; padding: 20px 22px 18px; border-bottom: 1px solid var(--line); flex: none;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 6%, transparent), transparent); }
.mx-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; color: #fff;
  background: linear-gradient(135deg, #3976d8, #214fa6); box-shadow: 0 8px 18px rgba(33, 79, 166, .32); }
.mx-icon.tone-green { background: linear-gradient(135deg, #2fb380, #1b8a5f); box-shadow: 0 8px 18px rgba(27, 138, 95, .3); }
.mx-icon.tone-amber { background: linear-gradient(135deg, #f0a43a, #d07a12); box-shadow: 0 8px 18px rgba(208, 122, 18, .3); }
.mx-icon.tone-violet { background: linear-gradient(135deg, #8a72f0, #5b45c9); box-shadow: 0 8px 18px rgba(91, 69, 201, .3); }
.mx-icon.tone-red { background: linear-gradient(135deg, #ef5b5b, #c93636); box-shadow: 0 8px 18px rgba(201, 54, 54, .3); }
.mx-icon.tone-slate { background: linear-gradient(135deg, #5d6b86, #3b475f); box-shadow: 0 8px 18px rgba(59, 71, 95, .3); }
.mx-title { flex: 1; min-width: 0; }
.mx-title h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.2px; color: var(--ink); }
.mx-title p { margin: 3px 0 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-close { width: 34px; height: 34px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s; flex: none; }
.mx-close:hover { background: var(--surface2); color: var(--ink); border-color: var(--line); }

/* Layout: form (+ optional aside panel) */
.mx-main { display: flex; flex: 1; min-height: 0; }
.mx-form { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.mx-body { flex: 1; min-height: 0; overflow: auto; padding: 20px 22px 22px; display: grid; gap: 18px; align-content: start; scrollbar-width: thin; }
.mx-aside { width: 380px; flex: none; border-left: 1px solid var(--line); background: var(--surface2); display: flex; flex-direction: column; min-height: 0; }
.mx-aside .context-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.mx-aside .context-messages { flex: 1; min-height: 120px; max-height: none; overflow: auto; display: flex; flex-direction: column; gap: 8px; align-content: start; }
.mx-aside .context-messages > * { flex: none; }

/* Footer */
.mx-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface); flex: none; }
.mx-spacer { flex: 1; }

/* Sections and fields */
.mx-section { display: grid; gap: 12px; }
.mx-section + .mx-section { padding-top: 18px; border-top: 1px dashed var(--line); }
.mx-section-title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.mx-section-title svg { color: var(--accent); }
.mx-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.mx-field { align-content: start; }
.mx-choice { align-items: center; }
.mx-field select { height: 40px; }
.mx-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mx-grid > .span-2, .mx-grid > .span-all { grid-column: 1 / -1; }
.mx-field { display: grid; gap: 6px; min-width: 0; }
.mx-label { font-size: 12px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.mx-label em { font-style: normal; font-weight: 600; color: var(--muted); }
.mx-hint { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.mx .mx-input, .mx-field input:not([type=checkbox]):not([type=radio]), .mx-field select, .mx-field textarea {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2);
  color: var(--ink); font: inherit; font-size: 13px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.mx-field textarea { resize: vertical; line-height: 1.5; }
.mx-field input:hover, .mx-field select:hover, .mx-field textarea:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.mx-field input:focus, .mx-field select:focus, .mx-field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); background: var(--surface); }
.mx-field input:disabled, .mx-field select:disabled, .mx-field textarea:disabled { opacity: .7; cursor: not-allowed; }
.mx-field input::placeholder, .mx-field textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.mx-title-input input { font-size: 16px; font-weight: 700; min-height: 46px; }
.mx-input-icon { position: relative; }
.mx-input-icon > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.mx-input-icon > input { padding-left: 36px !important; }

/* Segmented choice (status, priority, type…) */
.mx-choice { display: flex; flex-wrap: wrap; gap: 6px; }
.mx-choice button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface2);
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; transition: all .15s; }
.mx-choice button:hover:not(:disabled) { color: var(--ink); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.mx-choice button.on { color: #fff; background: var(--accent); border-color: var(--accent); box-shadow: 0 6px 14px color-mix(in srgb, var(--accent) 30%, transparent); }
:root[data-theme=dark] .mx-choice button.on { color: #0b1427; }
.mx-choice button i.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .8; }
.mx-choice .tone-backlog i.dot { background: #8a94a8; } .mx-choice .tone-todo i.dot { background: #5d8ee8; }
.mx-choice .tone-progress i.dot { background: #2f9bd6; } .mx-choice .tone-review i.dot { background: #9b7cf0; } .mx-choice .tone-done i.dot { background: #2fb380; }
.mx-choice .tone-low i.dot { background: #2fb380; } .mx-choice .tone-medium i.dot { background: #f0a43a; } .mx-choice .tone-high i.dot { background: #ef5b5b; }
.mx-choice button.on i.dot { background: currentColor; }

/* People / checkbox pickers */
.mx-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mx-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface2); color: var(--ink);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .15s; user-select: none; }
.mx-chip .mx-avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; background: var(--soft); color: var(--accent); }
.mx-chip:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.mx-chip.on, .mx-chip:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--ink); }
.mx-chip.on .mx-avatar, .mx-chip:has(input:checked) .mx-avatar { background: var(--accent); color: #fff; }
.mx-chip input { position: absolute; opacity: 0; pointer-events: none; }
.mx-chip.plain { padding: 7px 12px; }
.mx-chip small { color: var(--muted); font-weight: 600; }
.mx-empty { font-size: 12px; color: var(--muted); padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }

/* Switch */
.mx-switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface2); cursor: pointer; }
.mx-switch strong { display: block; font-size: 13px; }
.mx-switch small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.mx-switch input { appearance: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .18s; flex: none; margin: 0; }
.mx-switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .18s; }
.mx-switch input:checked { background: var(--accent); }
.mx-switch input:checked::after { transform: translateX(18px); }

/* Buttons */
.mx-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; transition: transform .12s, box-shadow .15s, background .15s, color .15s; white-space: nowrap; }
.mx-btn:active { transform: translateY(1px); }
.mx-btn:disabled { opacity: .55; cursor: not-allowed; }
.mx-btn.primary { color: #fff; background: linear-gradient(135deg, #3976d8, #214fa6); box-shadow: 0 8px 18px rgba(33, 79, 166, .3); }
.mx-btn.primary:hover:not(:disabled) { box-shadow: 0 10px 22px rgba(33, 79, 166, .42); }
.mx-btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.mx-btn.ghost:hover { background: var(--surface2); }
.mx-btn.danger { color: #fff; background: linear-gradient(135deg, #ef5b5b, #c93636); box-shadow: 0 8px 18px rgba(201, 54, 54, .28); }
.mx-btn.danger-ghost { background: transparent; color: #d84a4a; border-color: transparent; padding: 0 10px; }
.mx-btn.danger-ghost:hover { background: rgba(216, 74, 74, .1); }
.mx-btn.small { min-height: 32px; padding: 0 12px; font-size: 12px; }

/* Company logo + colour */
.mx-identity { display: flex; align-items: center; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface2); }
.mx-identity .client-logo-preview { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; overflow: hidden; color: #fff; font-size: 24px; font-weight: 800; flex: none; box-shadow: 0 8px 18px rgba(0, 0, 0, .15); }
.mx-identity .client-logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.mx-identity > div:last-child { display: grid; gap: 8px; flex: 1; }
.mx-identity strong { font-size: 13px; }
.mx-identity small { color: var(--muted); font-size: 11.5px; }
.mx-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.mx-swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; transition: transform .15s, box-shadow .15s; }
.mx-swatches button:hover { transform: scale(1.08); }
.mx-swatches button.selected { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }

/* Read-only notice */
.mx-notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 12px; line-height: 1.45;
  background: color-mix(in srgb, #f0a43a 12%, var(--surface)); border: 1px solid color-mix(in srgb, #f0a43a 35%, var(--line)); color: var(--ink); }
.mx-notice.info { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 28%, var(--line)); }
.mx-notice svg { flex: none; margin-top: 1px; color: #d07a12; }
.mx-notice.info svg { color: var(--accent); }

/* Confirmation */
.mx-confirm .mx-body { padding: 26px 26px 8px; text-align: center; justify-items: center; gap: 10px; }
.mx-confirm .mx-icon { width: 56px; height: 56px; border-radius: 16px; }
.mx-confirm h2 { margin: 6px 0 0; font-size: 18px; font-weight: 800; }
.mx-confirm p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; max-width: 340px; }
.mx-confirm .mx-foot { border-top: 0; padding: 18px 26px 24px; }
.mx-confirm .mx-foot .mx-btn { flex: 1; }

/* Role claim matrix inside dialogs */
.mx .claim-matrix { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; gap: 0; margin: 0; }
.mx .claim-row { border-radius: 0; padding: 8px 12px; }
.mx .claim-row:nth-child(even) { background: var(--surface2); }
.mx .claim-head { background: var(--surface2); border-bottom: 1px solid var(--line); }
.mx .claim-row input { accent-color: var(--accent); }

/* Command palette */
.mx.mx-palette { max-width: 640px; align-self: start; margin-top: 12vh; }
.mx-palette .mx-search { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.mx-palette .mx-search svg { color: var(--accent); }
.mx-palette .mx-search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 15px; }
.mx-palette .mx-search kbd { font-size: 11px; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.mx-palette .palette-results { max-height: 50vh; overflow: auto; padding: 8px; margin: 0; }
.mx-palette .palette-row { border-radius: 10px; padding: 9px 10px; }
.mx-palette .palette-row .palette-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface2); color: var(--accent); flex: none; }
.mx-palette .palette-row.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.mx-palette .palette-row.active .palette-icon { background: var(--accent); color: #fff; }
.mx-palette .palette-foot { display: flex; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); margin: 0; font-size: 11px; color: var(--muted); }
.mx-palette .palette-foot kbd { font-size: 10px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); margin-right: 4px; }

/* Idle prompt uses the same look */
.idle-overlay { background: rgba(8, 14, 28, .52); backdrop-filter: blur(6px); }
.idle-dialog { border-radius: 18px; text-align: center; }
.idle-dialog-icon { margin: 0 auto 14px; width: 56px; height: 56px; border-radius: 16px; color: #fff; background: linear-gradient(135deg, #f0a43a, #d07a12); }
.idle-dialog-actions { justify-content: stretch; }
.idle-dialog-actions button { flex: 1; min-height: 40px; border-radius: 10px; }

/* Small screens: stack the aside, full width dialogs */
@media (max-width: 900px) {
  .mx-main { flex-direction: column; }
  .mx-aside { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .mx-grid, .mx-grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .mx-backdrop { padding: 0; place-items: end stretch; } .mx { max-height: 92vh; border-radius: 18px 18px 0 0; } }

@keyframes mx-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes mx-fade-out { to { opacity: 0 } }
@keyframes mx-pop { from { opacity: 0; transform: translateY(10px) scale(.97) } to { opacity: 1; transform: none } }
@keyframes mx-pop-out { to { opacity: 0; transform: translateY(6px) scale(.98) } }
@keyframes mx-slide { from { transform: translateX(40px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes mx-slide-out { to { transform: translateX(30px); opacity: 0 } }
@media (prefers-reduced-motion: reduce) { .mx-backdrop, .mx, .mx.mx-sheet { animation: none !important; } }

/* Task dialog: assignment as clear rows */
.as-box { display: grid; gap: 8px; }
.as-summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--line); color: var(--muted); }
.as-summary > div { display: grid; min-width: 0; }
.as-summary strong { font-size: 13px; color: var(--ink); }
.as-summary span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-summary.has { border-style: solid; border-color: rgba(47, 179, 128, .45); background: rgba(47, 179, 128, .08); color: #1b8a5f; }
:root[data-theme=dark] .as-summary.has { color: #6fdcae; }
.as-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.as-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; transition: border-color .12s, background .12s; }
.as-row:hover { border-color: var(--accent); }
.as-name { flex: 1; min-width: 0; display: grid; }
.as-name strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-name small { font-size: 11px; color: var(--muted); }
.as-state { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 800; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.as-row.on { border-color: #2fb380; background: rgba(47, 179, 128, .1); }
.as-row.on .as-state { color: #fff; background: #2fb380; border-color: #2fb380; }
.as-row.on .mx-avatar { background: #2fb380; color: #fff; }
.as-row[disabled] { cursor: default; opacity: .75; }
/* Assignment: dropdown + assigned chips */
.as-pick { width: 100%; height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface2); color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer; }
.as-pick:disabled { cursor: default; opacity: .65; }
.as-chosen { display: flex; flex-wrap: wrap; gap: 6px; }
.as-chip { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 4px 0 4px; border-radius: 999px; border: 1px solid rgba(47, 179, 128, .5); background: rgba(47, 179, 128, .12); font-size: 13px; font-weight: 700; color: var(--ink); }
.as-av { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 10.5px; font-weight: 800; color: #fff; background: #2fb380; }
.as-chip button { width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.as-chip button:hover { color: #dc2626; background: rgba(220, 38, 38, .1); }
.as-none { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 12.5px; color: var(--muted); }