:root {
  --bg: var(--dsq-background);
  --surface: var(--dsq-surface);
  --line: var(--dsq-separator);
  --text: var(--dsq-label);
  --muted: var(--dsq-label-tertiary);
  --accent: var(--dsq-accent);
  --accent-soft: var(--dsq-accent-soft);
  --danger: var(--dsq-danger);
  --work-sidebar-width: 240px;
  font-family: var(--dsq-font-family);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: inherit; }
button, input, textarea, select { font: inherit; }

.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--work-sidebar-width); padding: 24px 8px 16px;
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line);
}
.brand, .login-brand { display: flex; align-items: center; gap: 10px; font-weight: 750; text-decoration: none; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 30px; }
.brand { min-width: 0; padding: 0; white-space: nowrap; }
.sidebar-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px;
  padding: 0; color: var(--muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.sidebar-toggle[hidden] { display: none; }
.sidebar-toggle:hover { color: var(--accent); background: var(--accent-soft); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar-collapsed .sidebar-toggle .nav-icon { transform: rotate(180deg); }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  color: var(--accent); background: var(--accent-soft); border: 1px solid var(--line); font-size: 12px; letter-spacing: .03em;
}
.nav-list { display: grid; gap: 4px; min-height: 0; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 10px 12px;
  color: var(--dsq-label-secondary); border: 0; border-radius: 8px; background: transparent; text-decoration: none;
}
.nav-link:hover { background: var(--dsq-fill); }
.nav-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-group { min-width: 0; }
.nav-toggle { cursor: pointer; list-style: none; }
.nav-toggle::-webkit-details-marker { display: none; }
.nav-toggle:focus-visible, .nav-sublink:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-toggle .nav-chevron { width: 14px; height: 14px; margin-left: auto; }
.nav-group[open] > .nav-toggle .nav-chevron { transform: rotate(90deg); }
.nav-submenu { display: grid; gap: 2px; margin: 4px 0 6px 20px; padding-left: 9px; border-left: 1px solid var(--line); }
.nav-sublink { min-height: 38px; gap: 9px; padding: 8px 10px; font-size: 14px; }
.nav-sublink .nav-icon { width: 17px; height: 17px; }
.nav-icon, .button-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.button-icon { width: 17px; height: 17px; }
.account-block { margin-top: auto; padding: 16px 4px 0; border-top: 1px solid var(--line); }
.account-name { padding: 0 7px; font-size: 14px; font-weight: 650; }
.account-email { padding: 3px 7px 10px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.logout-button { width: 100%; cursor: pointer; }
.main-content { min-height: 100vh; margin-left: var(--work-sidebar-width); padding: 40px 24px; }
@media (min-width: 992px) {
  .sidebar-collapsed { --work-sidebar-width: 72px; }
  .sidebar-collapsed .sidebar { padding: 22px 10px; }
  .sidebar-collapsed .sidebar-header { flex-direction: column; gap: 12px; }
  .sidebar-collapsed .brand { padding: 0; }
  .sidebar-collapsed .brand-name,
  .sidebar-collapsed .sidebar .nav-link > span,
  .sidebar-collapsed .sidebar .nav-chevron,
  .sidebar-collapsed .sidebar .nav-submenu,
  .sidebar-collapsed .account-name,
  .sidebar-collapsed .account-email { display: none; }
  .sidebar-collapsed .sidebar .nav-link { justify-content: center; padding: 10px; }
  .sidebar-collapsed .account-block { padding: 12px 0 0; }
}
.page-header { margin: 0 0 28px; }
.row-header, .section-heading, .article-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.035em; }
h2 { margin-bottom: 6px; font-size: 19px; }
.eyebrow { margin-bottom: 10px; color: var(--accent); font-size: 11px; font-weight: 750; letter-spacing: .12em; }
.muted { color: var(--muted); }
.plain-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 3px var(--dsq-shadow); }
.service-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; margin-bottom: 22px; }
.service-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 20px;
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface); text-decoration: none;
  box-shadow: 0 1px 3px var(--dsq-shadow);
}
.service-card:hover { border-color: var(--accent); }
.service-card strong, .service-card small { display: block; }
.service-card strong { margin-bottom: 5px; font-size: 16px; }
.service-card small { color: var(--muted); line-height: 1.45; }
.service-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; color: var(--accent); background: var(--accent-soft); }
.service-icon-svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.service-arrow { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.workflow-summary { margin-bottom: 22px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 18px; }
.project-card h2 a { text-decoration: none; }
.project-card h2 a:hover { color: var(--accent); }
.card-title-row, .title-with-badge { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.title-with-badge { justify-content: flex-start; }
.title-with-badge h1 { margin-bottom: 0; }
.status-badge, .ai-label {
  display: inline-flex; align-items: center; width: max-content; padding: 3px 8px; border-radius: 999px;
  color: #334155; background: #eef2f7; font-size: 11px; font-weight: 720; white-space: nowrap;
}
.status-active, .status-ready, .status-done, .status-succeeded, .status-approved { color: #166534; background: #dcfce7; }
.status-in_progress, .status-running, .status-review { color: #1d4ed8; background: #dbeafe; }
.status-blocked, .status-urgent, .status-failed, .status-rejected { color: #991b1b; background: #fee2e2; }
.status-on_hold, .status-cancelled, .status-archived { color: #6b4f00; background: #fef3c7; }
.ai-label { margin-left: 4px; color: #5b21b6; background: #ede9fe; vertical-align: middle; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin: 20px 0 0; }
.meta-grid div { min-width: 0; }
.meta-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.meta-grid dd { margin: 0; font-size: 14px; font-weight: 620; overflow-wrap: anywhere; }
.work-table-wrap { width: 100%; overflow-x: auto; }
.work-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.work-table th, .work-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.work-table th { color: var(--muted); font-size: 12px; font-weight: 700; }
.work-table tbody tr:last-child td { border-bottom: 0; }
.work-table a { font-weight: 650; text-decoration: none; }
.work-table a:hover { color: var(--accent); }
.two-column-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.resource-list { margin: 16px 0 0; padding: 0; list-style: none; }
.resource-list li { display: flex; flex-direction: column; gap: 5px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.resource-list li:last-child { border-bottom: 0; }
.resource-list a { color: var(--accent); font-weight: 620; text-decoration: none; overflow-wrap: anywhere; }
.resource-list span { color: var(--muted); font-size: 12px; }
.compact-empty { padding: 24px 8px; }
.project-links { margin-bottom: 18px; }
.workflow-detail > .plain-card { margin-top: 18px; }
.no-padding { padding: 0; overflow: hidden; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--dsq-label-secondary); background: var(--surface); text-decoration: none; cursor: pointer;
}
.button:hover { border-color: #bbc1ca; }
.button.primary { color: var(--dsq-on-accent); border-color: var(--accent); background: var(--accent); }
.button.danger { color: var(--danger); }
.button.full { width: 100%; }
.post-list { margin: 0; padding: 0; list-style: none; }
.post-list li { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.post-list li:last-child { border-bottom: 0; }
.post-list a { font-weight: 620; text-decoration: none; }
.post-list a:hover { color: var(--accent); }
.post-list span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.post-list.compact { margin-top: 18px; border: 1px solid var(--line); border-radius: 9px; }
.empty-state { padding: 42px 22px; color: var(--muted); text-align: center; }
.content-narrow { max-width: 860px; margin: 0 auto; }
.text-link { display: inline-flex; align-items: center; gap: 5px; margin-bottom: 18px; color: var(--muted); text-decoration: none; }
.article-header { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.article-body { min-height: 220px; padding: 26px 0; line-height: 1.75; overflow-wrap: anywhere; }
.article-actions { justify-content: flex-end; padding-top: 18px; border-top: 1px solid var(--line); }
.article-actions form { margin: 0; }
.stack-form { display: grid; gap: 9px; }
.stack-form label { margin-top: 8px; font-size: 13px; font-weight: 650; }
.stack-form input, .stack-form textarea, .stack-form select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--surface);
}
.stack-form input:focus, .stack-form textarea:focus, .stack-form select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-help { color: var(--muted); font-size: 12px; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.form-error, .errorlist { color: var(--danger); font-size: 13px; }
.errorlist { margin: 0; padding-left: 18px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); padding: 34px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 14px 40px rgb(17 24 39 / 8%); }
.login-brand { margin-bottom: 34px; }
.login-card h1 { font-size: 28px; }
.login-card .button { margin-top: 16px; }
.messages p { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

@media (max-width: 991px) {
  .sidebar { position: sticky; top: 0; z-index: 60; width: 100%; height: 64px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-header { height: 40px; flex: none; padding: 0; }
  .sidebar-toggle { width: 40px; height: 40px; }
  .sidebar-toggle-desktop { display: none; }
  .sidebar-toggle-mobile { display: block; }
  #sidebar-navigation, #sidebar-account { display: none; }
  .sidebar-mobile-open { overflow: hidden; }
  .sidebar-mobile-open .sidebar { position: fixed; inset: 0 0 auto; height: auto; max-height: var(--work-viewport-height, 100dvh); overflow-y: auto; }
  .sidebar-mobile-open #sidebar-navigation { display: grid; gap: 2px; padding-top: 12px; }
  .sidebar-mobile-open #sidebar-account { display: block; margin-top: 16px; }
  .nav-list { overflow: visible; }
  .nav-link { white-space: normal; min-height: 44px; }
  .nav-submenu { margin-left: 20px; }
  .sidebar-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 55; border: 0; background: rgb(0 0 0 / 28%); }
  .main-content { margin-left: 0; min-height: calc(100dvh - 64px); padding: 24px 16px; }
  .row-header, .section-heading { align-items: flex-start; flex-wrap: wrap; gap: 12px; }
  .post-list li { align-items: flex-start; flex-direction: column; gap: 6px; }
  .post-list span { white-space: normal; }
}

/* AI ticket documents, reviews and results. */
.status-queued, .status-pending { color: #5b21b6; background: #ede9fe; }
.status-revision, .status-answered { color: #173e80; background: #edf3fc; }
.approval-panel { padding-top: 22px; border-top: 1px solid var(--line); }
.plain-card > .approval-panel:first-child { padding-top: 0; border-top: 0; }
.approval-note, .run-summary, .readonly-description { margin: 18px 0; line-height: 1.7; overflow-wrap: anywhere; }
.approval-actions { gap: 10px; flex-wrap: wrap; }
.approval-actions button:disabled { opacity: .6; cursor: wait; }
.plan-original, .run-output pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; font: inherit; line-height: 1.8; tab-size: 4; }
.plan-original { margin: 28px 0; }
.document-integrity { margin: 18px 0; color: var(--muted); font-size: 12px; }
.document-integrity code { display: block; margin-top: 8px; overflow-wrap: anywhere; }
.document-integrity summary, .run-output summary { cursor: pointer; }
.run-output { margin-top: 18px; }
.run-progress { padding-top: 20px; }
.artifact-entry { display: grid; gap: 8px; padding-top: 10px; }
.artifact-preview { display: block; width: 100%; height: 420px; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.published-results { margin-top: 18px; }
@media (max-width: 991px) {
  .approval-actions { justify-content: flex-start; }
  .approval-actions .button { min-height: 44px; }
  .plan-page .title-with-badge { align-items: flex-start; flex-wrap: wrap; }
  .artifact-preview { height: 320px; }
}

/* Shared Migration1 visual tokens. Palette and mode script are exact upstream copies. */
body { font: var(--dsq-type-body); }
.brand-name { display: grid; gap: 3px; line-height: 1; }
.brand-name strong { font-size: 13px; letter-spacing: .08em; }
.brand-name small { color: var(--muted); font-size: 10px; font-weight: 500; }
.brand-mark { flex: none; }
.sidebar-toggle-mobile, .sidebar-scrim { display: none; }
.nav-link > .nav-icon { color: var(--dsq-icon-neutral); }
.nav-link.active > .nav-icon, .nav-link:hover > .nav-icon { color: currentColor; }
.account-block { padding-inline: 4px; }
.theme-switcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 2px; margin: 0 4px 14px; background: var(--dsq-fill); border-radius: var(--dsq-r-segment); }
.theme-switcher button { padding: 5px 6px; min-height: 32px; border: 0; border-radius: var(--dsq-r-segment-inner); background: transparent; color: var(--dsq-label-secondary); font-size: 12px; cursor: pointer; }
.theme-switcher button[aria-pressed="true"] { background: var(--dsq-segment-selected); color: var(--text); box-shadow: 0 1px 3px var(--dsq-segment-shadow); font-weight: 600; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (min-width: 992px) { .sidebar-collapsed .theme-switcher { display: none; } }
@media (max-width: 991px) { .sidebar-toggle-mobile { display: block; } }
@media (max-width: 480px) { .service-card { padding: 16px; gap: 12px; } .plain-card { padding: 16px; } }
/* Older Work forms share the same dark field palette as the portal. */
html[data-bs-theme="dark"] .main-content :is(input, textarea, select):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]) {
  background-color: var(--surface); color: var(--text); border-color: var(--line);
}
@media (max-width: 991px) {
  .main-content :is(input, textarea, select):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]) { font-size: 16px; }
}
