:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #d8dee8;
    --border-soft: #e6ebf2;
    --text: #17202a;
    --text-strong: #0f172a;
    --muted: #64748b;
    --muted-strong: #475569;
    --primary: #1f5fbf;
    --primary-hover: #174f9f;
    --primary-soft: #eaf1ff;
    --success: #067647;
    --warning: #946200;
    --danger: #b42318;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 14px 30px rgba(15, 23, 42, 0.12);
}
* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    max-width: 100%;
    overflow-x: hidden;
    line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; overflow-wrap: anywhere; }
a:hover { text-decoration: underline; }
code {
    overflow-wrap: anywhere;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.topbar {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.94);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
}
.brand {
    font-weight: 800;
    color: var(--text-strong);
    letter-spacing: 0;
}
.brand:hover { text-decoration: none; color: var(--primary); }
.nav { display: flex; gap: 6px; align-items: center; font-size: 14px; min-width: 0; }
.nav a {
    color: var(--muted-strong);
    border-radius: 6px;
    padding: 7px 9px;
    font-weight: 600;
}
.nav a:hover { background: var(--surface-muted); color: var(--text-strong); text-decoration: none; }
.nav-toggle { display: none; }
.nav a.active { color: var(--text-strong); font-weight: 800; background: var(--surface-muted); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 30px 24px 56px; }
.auth-wrap { max-width: 440px; margin: 10vh auto; padding: 0 20px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .actions {
    align-items: stretch;
    justify-content: space-between;
}
.auth-card .actions .btn { flex: 1 1 auto; }
.auth-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    color: var(--muted-strong);
    font-weight: 600;
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 22px;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}
.inline-panel { margin: 12px 0; }
.callout-panel {
    margin: 14px 0;
    border-color: #bdd7ff;
    background: #f6f9ff;
}
.danger-panel {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #fee4e2;
}
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    margin: 18px 0;
}
.section-card {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface-muted);
    min-width: 0;
}
.section-card h2, .section-card h3 { margin-top: 0; }
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 0 0 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 26px; font-weight: 800; color: var(--text-strong); line-height: 1.1; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted-strong); font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; min-height: 14px; }
.stat-sub .ok { color: var(--success); font-weight: 700; }
.stat-sub .warn { color: var(--warning); font-weight: 700; }
.presence {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd3df;
    margin-right: 6px;
    vertical-align: middle;
    flex: 0 0 8px;
}
.presence.online { background: #12b76a; box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.15); }
.presence.idle { background: #f5a524; }
.presence.offline { background: #cbd3df; }
.last-seen-cell { display: inline-flex; align-items: center; min-width: 0; }
.relative-time { white-space: nowrap; }
.id-cell { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.id-cell code {
    font-size: 12px;
    background: #f1f3f7;
    padding: 2px 6px;
    border-radius: 4px;
    color: #1f2937;
}
.copy-btn {
    border: 1px solid #cbd3df;
    background: #ffffff;
    color: #475467;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    cursor: pointer;
    line-height: 1.2;
    flex: 0 0 auto;
}
.copy-btn:hover { background: #f6f7f9; color: #111827; }
.copy-btn.copied { color: #067647; border-color: #a6e6c8; background: #ecfdf3; }
.command-block {
    position: relative;
    margin: 12px 0 16px;
}
.command-block pre { margin: 0; padding-right: 88px; }
.command-block .copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ffffff;
}
.empty-state {
    padding: 28px 16px;
    text-align: center;
    color: var(--muted-strong);
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: var(--surface-muted);
}
.empty-state p { margin: 0 0 12px; font-size: 14px; }
.container-group { margin-top: 18px; }
.container-group:first-of-type { margin-top: 0; }
.group-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 12px;
    border-left: 4px solid var(--primary);
    background: var(--primary-soft);
    border-radius: 8px;
    margin-bottom: 8px;
}
.container-group.unassigned .group-header {
    border-left-color: #f5a524;
    background: #fff7e6;
}
.group-name { font-weight: 800; font-size: 14px; color: var(--text-strong); }
.group-rev {
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #475467;
    background: #ffffff;
    border: 1px solid #d0d6df;
    border-radius: 999px;
    padding: 1px 8px;
}
.group-count {
    font-size: 12px;
    color: #667085;
    margin-left: auto;
}
.group-count::after { content: ' Container'; }
h1 { margin: 0 0 18px; font-size: 26px; letter-spacing: 0; overflow-wrap: anywhere; word-break: break-word; line-height: 1.18; }
h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: 0; line-height: 1.25; color: var(--text-strong); }
.muted { color: var(--muted); font-size: 14px; }
.error { padding: 10px 12px; margin-bottom: 14px; border-radius: 6px; background: #fff1f0; color: #a8071a; border: 1px solid #ffa39e; }
.notice { padding: 10px 12px; margin-bottom: 14px; border-radius: 6px; background: #ecfdf3; color: #067647; border: 1px solid #abefc6; }
ul, ol { padding-left: 22px; }
label { display: block; margin: 12px 0 6px; font-size: 14px; font-weight: 600; }
input, select, textarea {
    width: 100%;
    border: 1px solid #cbd3df;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: var(--surface);
    min-width: 0;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.14);
    outline: 0;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input[type="checkbox"] { width: auto; }
textarea { min-height: 180px; resize: vertical; line-height: 1.45; }
.speech-input {
    display: grid;
    gap: 8px;
}
.speech-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.speech-record-btn.is-recording {
    background: #b42318;
    border-color: #b42318;
    color: #ffffff;
}
.speech-status {
    min-height: 20px;
}
.check-row { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.checkbox-row { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.checkbox-row span { min-width: 0; }
.danger-zone { margin-top: 14px; padding-top: 14px; border-top: 1px solid #e5e7eb; }
.settings-form { margin-top: 20px; }
.telegram-status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.telegram-link-box { margin-top: 14px; padding-top: 14px; border-top: 1px solid #e5e7eb; }
.telegram-link-box code { overflow-wrap: anywhere; }
.quick-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -4px 0 18px;
}
.quick-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted-strong);
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
}
.quick-nav a:hover {
    text-decoration: none;
    color: var(--text-strong);
    border-color: #94a3b8;
}
.env-detail > .actions:first-child {
    min-width: 0;
}
.env-detail > .actions:first-child h1 {
    min-width: 0;
    max-width: 100%;
}
.env-detail .env-edit-table td[colspan] {
    padding: 12px 8px;
}
.env-detail .env-edit-table input,
.env-detail .env-edit-table select,
.env-detail .env-edit-table textarea {
    max-width: 100%;
}
.dashboard-page .mobile-card-table,
.hosts-page .mobile-card-table {
    min-width: 0;
}
.dashboard-page .action-buttons,
.hosts-page .action-buttons {
    min-width: 0;
}
.dashboard-page .action-buttons form,
.hosts-page .action-buttons form {
    margin: 0;
}
.resource-lines,
.capacity-breakdown {
    display: grid;
    gap: 3px;
}
.resource-lines span,
.capacity-breakdown span {
    min-width: 0;
    overflow-wrap: anywhere;
}
dialog.edit-dialog {
    width: min(560px, calc(100vw - 32px));
    border: 1px solid #dde1e7;
    border-radius: 8px;
    padding: 0;
    color: #17202a;
}
dialog.edit-dialog::backdrop { background: rgba(17, 24, 39, 0.35); }
.dialog-head,
.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
}
.dialog-footer {
    justify-content: flex-end;
    border-top: 1px solid #e5e7eb;
    border-bottom: 0;
}
.dialog-head h3 { margin: 0; font-size: 16px; }
.dialog-body { padding: 16px; }
.dialog-close-x {
    border: 0;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #667085;
}
.deploy-action { margin-top: 10px; }
.value-panel { margin-top: 20px; }
.value-edit-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(220px, 2fr) auto auto auto;
    gap: 10px;
    align-items: end;
}
.value-edit-form label { margin-top: 0; }
.value-secret-toggle { margin-bottom: 10px; }
.current-value { margin-bottom: 10px; }
.value-actions { margin-top: 0; }
.value-delete-form { margin-top: 8px; }
.env-section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.env-section-head h2 { margin: 0; }
.env-section-head .muted { margin: 2px 0 0; }
.environment-assign-form { display: grid; gap: 6px; }
.launch-form { display: grid; gap: 4px; }
.file-edit-form textarea { min-height: 220px; }
.file-version-label {
    display: inline-block;
    margin-top: 5px;
    font-size: 12px;
}
.file-edit-grid {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(220px, 1fr) auto;
    gap: 10px;
    align-items: end;
}
.file-version-history {
    margin-top: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fbfcfe;
}
.file-version-history summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 10px;
    font-size: 13px;
    font-weight: 700;
}
.file-version-list {
    display: grid;
    gap: 0;
    border-top: 1px solid #e5e7eb;
}
.file-version-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    font-size: 13px;
    border-bottom: 1px solid #eef1f5;
}
.file-version-row:last-child { border-bottom: 0; }
.file-version-row code {
    background: #f1f3f7;
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 12px;
}
.repo-edit-form {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(120px, 1fr) minmax(160px, 1fr) auto;
    gap: 10px;
    align-items: end;
}
.repo-actions { margin-top: 0; }
.token-profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin: 14px 0 20px;
}
.token-profile-list { display: grid; gap: 12px; }
.token-profile {
    border: 1px solid #dde1e7;
    border-radius: 8px;
    background: #fbfcfe;
    padding: 14px;
    min-width: 0;
}
.token-profile.compact { padding: 12px; }
.token-profile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.token-profile h3 {
    margin: 0;
    font-size: 15px;
    color: #111827;
}
.token-profile p { margin: 0 0 8px; }
.token-permissions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.token-permissions code {
    background: #eef2ff;
    color: #3730a3;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
}
.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; min-width: 0; }
.actions.page-header { justify-content: space-between; margin-top: 0; flex-wrap: wrap; }
.actions.page-header h1 { margin: 0; }
.page-header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.page-title h1 { margin: 0; }
.page-title .actions { margin-top: 0; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.muted-link { color: #475467; font-size: 13px; }
.muted-link:hover { color: #1f2937; }
details.collapsible { padding: 0; }
details.collapsible > summary {
    list-style: none;
    cursor: pointer;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-radius: 8px;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after {
    content: "▾";
    color: #667085;
    font-size: 12px;
    transition: transform 0.15s ease;
}
details.collapsible[open] > summary::after { transform: rotate(180deg); }
details.collapsible > summary h2 { margin: 0; font-size: 16px; }
details.collapsible > summary > .muted { margin-left: auto; margin-right: 8px; }
details.collapsible > table { margin: 0 20px 20px; width: calc(100% - 40px); }
details.collapsible > .details-body { padding: 0 20px 20px; }
details.collapsible > .details-body > *:first-child { margin-top: 0; }
dialog.edit-dialog form.launch-form { display: block; gap: 0; }
dialog.edit-dialog .dialog-body label:first-child { margin-top: 0; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 6px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    max-width: 100%;
    min-width: 0;
    text-align: center;
    white-space: normal;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}
.btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #ffffff;
    text-decoration: none;
}
.btn:focus-visible, .copy-btn:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.2);
}
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}
.btn.is-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}
.btn.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
.btn.secondary.is-loading::after {
    border-color: rgba(31, 41, 55, 0.25);
    border-top-color: #1f2937;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .btn.is-loading::after { animation: none; }
}
.btn-sm {
    min-height: 28px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
}
.btn.secondary { background: #ffffff; color: #1f2937; border-color: #cbd3df; }
.btn.secondary:hover { background: #f8fafc; border-color: #94a3b8; color: #0f172a; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #912018; border-color: #912018; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border-soft); vertical-align: top; overflow-wrap: anywhere; word-break: break-word; }
th { color: var(--muted-strong); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 800; }
tbody tr:hover { background: #fbfdff; }
.status {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: #eef2ff;
    color: #3730a3;
}
.status.done { background: #ecfdf3; color: #067647; }
.status.error { background: #fef3f2; color: #b42318; }
.status.running { background: #fff8e6; color: #946200; }
.status.queued { background: #eef2ff; color: #3730a3; }
.status.claimed, .status.started { background: #fff8e6; color: #946200; }
.status.succeeded { background: #ecfdf3; color: #067647; }
.polling-state { margin-left: 10px; }
.task-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.task-title-cli { font-size: 24px; font-weight: 800; color: var(--text-strong); }
.task-title-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 16px;
    color: var(--muted);
    font-weight: 400;
    background: #f1f3f7;
    border-radius: 4px;
    padding: 2px 8px;
}
.task-prompt-preview {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
    display: block;
    margin-top: 2px;
}
.more-menu { width: 100%; }
.more-menu > summary {
    list-style: none;
    cursor: pointer;
    width: max-content;
}
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu > summary::after {
    content: "▾";
    font-size: 10px;
    margin-left: 6px;
    transition: transform 0.15s ease;
}
.more-menu[open] > summary::after { transform: rotate(180deg); }
.more-menu-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: var(--surface-muted);
}
.cli-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}
.cli-group-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--muted-strong);
    min-width: 48px;
}
.task-status-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 18px;
}
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin: 0 0 20px;
}
.meta-item {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: var(--surface-muted);
    padding: 10px 12px;
    min-width: 0;
}
.task-info-disclosure {
    margin: -2px 0 14px;
}
.task-info-disclosure > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: #ffffff;
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
}
.task-info-disclosure > summary::-webkit-details-marker { display: none; }
.task-info-disclosure > summary::before {
    content: "i";
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-right: 6px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1;
}
.task-info-disclosure[open] > summary {
    margin-bottom: 12px;
    color: #1f5fbf;
    border-color: #bdd7ff;
}
.task-info-disclosure .meta-grid {
    margin-bottom: 16px;
}
.meta-label {
    display: block;
    margin-bottom: 3px;
    color: var(--muted-strong);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.meta-value {
    display: block;
    color: var(--text-strong);
    font-size: 14px;
    overflow-wrap: anywhere;
}
pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    overflow-x: auto;
    background: #111827;
    color: #f9fafb;
    padding: 14px;
    border-radius: 8px;
    line-height: 1.5;
}
.chat-shell {
    margin-top: 10px;
    margin-bottom: 18px;
    padding: 4px 2px;
    height: min(72vh, 760px);
    min-height: 360px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.chat-list { display: grid; gap: 18px; }
.chat-loader {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: -6px auto 12px;
    width: fit-content;
    max-width: 100%;
    padding: 6px 10px;
    border: 1px solid #d9e0ea;
    border-radius: 999px;
    background: #ffffff;
    color: #667085;
    font-size: 12px;
}
.message { display: flex; flex-direction: column; gap: 6px; max-width: 78%; }
.user-message { margin-left: auto; align-items: flex-end; }
.assistant-message, .error-message { margin-right: auto; align-items: flex-start; }
.message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    color: #667085;
    font-size: 12px;
}
.bubble {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    line-height: 1.48;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}
.user-message .bubble {
    background: #1f5fbf;
    color: #ffffff;
    border-top-right-radius: 3px;
}
.assistant-message .bubble {
    background: var(--surface-muted);
    color: #17202a;
    border: 1px solid var(--border-soft);
    border-top-left-radius: 3px;
}
.error-message .bubble {
    background: #fff1f0;
    color: #a8071a;
    border: 1px solid #ffa39e;
}
.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 260px));
    gap: 10px;
    width: 100%;
}
.attachment-grid.standalone { margin: 12px 0 18px; }
.attachment-card {
    display: grid;
    gap: 6px;
    color: #1f2937;
    text-decoration: none;
    font-size: 12px;
}
.attachment-card img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: contain;
    border: 1px solid #d9e0ea;
    border-radius: 6px;
    background: #ffffff;
}
.attachment-card span {
    overflow-wrap: anywhere;
    color: #667085;
}
.image-viewer {
    width: min(96vw, 1180px);
    height: min(92vh, 900px);
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: #101828;
    color: #ffffff;
}
.image-viewer::backdrop {
    background: rgba(15, 23, 42, 0.72);
}
.image-viewer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}
#image-viewer-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}
.image-viewer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #cbd3df;
    border-radius: 6px;
    background: #ffffff;
    color: #111827;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.image-viewer-stage {
    height: calc(100% - 57px);
    overflow: hidden;
    display: grid;
    place-items: center;
    padding: 18px;
    touch-action: none;
    user-select: none;
}
.image-viewer-stage img {
    max-width: none;
    max-height: none;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 120ms ease;
    user-select: none;
    -webkit-user-drag: none;
    will-change: transform;
}
.image-viewer-stage.is-panning img,
.image-viewer-stage.is-gesturing img {
    transition: none;
}
.image-viewer-stage.can-pan {
    cursor: grab;
}
.image-viewer-stage.is-panning {
    cursor: grabbing;
}
.reply-form { margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 18px; }
@media (max-width: 760px) {
    .topbar { min-height: 56px; flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; padding: 0 16px; max-width: 100%; }
    .brand { max-width: calc(100% - 52px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        flex: 0 0 auto;
        border: 1px solid var(--border-soft);
        border-radius: 8px;
        background: #ffffff;
        cursor: pointer;
        list-style: none;
    }
    .nav-toggle-bars,
    .nav-toggle-bars::before,
    .nav-toggle-bars::after {
        content: "";
        display: block;
        width: 18px;
        height: 2px;
        background: var(--text-strong);
        border-radius: 2px;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }
    .nav-toggle-bars { position: relative; }
    .nav-toggle-bars::before { position: absolute; left: 0; top: -6px; }
    .nav-toggle-bars::after { position: absolute; left: 0; top: 6px; }
    .nav-toggle-checkbox:checked ~ .nav-toggle .nav-toggle-bars { background: transparent; }
    .nav-toggle-checkbox:checked ~ .nav-toggle .nav-toggle-bars::before { top: 0; transform: rotate(45deg); }
    .nav-toggle-checkbox:checked ~ .nav-toggle .nav-toggle-bars::after { top: 0; transform: rotate(-45deg); }
    .nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: 8px 12px 12px;
        background: #ffffff;
        border-bottom: 1px solid var(--border-soft);
        box-shadow: 0 10px 20px rgba(16, 24, 40, 0.10);
        max-height: calc(100vh - 56px);
        overflow-y: auto;
    }
    .nav-toggle-checkbox:checked ~ .nav { display: flex; }
    .nav a { flex: 0 0 auto; padding: 11px 12px; border-radius: 8px; }
    .nav-user {
        order: -1;
        padding: 4px 12px 8px;
        border-bottom: 1px solid var(--border-soft);
        margin-bottom: 4px;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .wrap { padding: 18px 12px 32px; width: 100%; max-width: 100%; }
    .auth-wrap { margin: 7vh auto; padding: 0 12px; }
    .auth-card .actions { flex-direction: column; }
    .auth-card .actions .btn,
    .auth-card .auth-link { width: 100%; justify-content: center; }
    .panel { padding: 16px; width: 100%; max-width: 100%; overflow: hidden; }
    .grid { grid-template-columns: 1fr; }
    .section-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat { padding: 12px 14px; }
    .stat-value { font-size: 20px; }
    h1 { font-size: 21px; }
    .task-title-cli { font-size: 21px; }
    .task-title-id { font-size: 14px; }
    h2 { font-size: 17px; }
    .actions { flex-wrap: wrap; align-items: flex-start; }
    .actions h1 { flex: 1 1 100%; min-width: 0; max-width: 100%; margin-bottom: 4px; word-break: break-all; }
    .page-title { align-items: stretch; flex-direction: column; gap: 10px; }
    .page-title .actions, .page-title .btn { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .btn { min-height: 38px; }
    .task-prompt-preview { max-width: 100%; }
    .command-block pre { padding-right: 12px; padding-top: 44px; }
    .command-block .copy-btn { left: 10px; right: auto; }
    .quick-nav { align-items: stretch; flex-direction: column; }
    .quick-nav a { justify-content: center; width: 100%; }
    .task-detail-wrap { padding-left: 0; padding-right: 0; }
    .task-chat-panel {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 12px 12px 16px;
    }
    .task-info-disclosure { margin-bottom: 8px; }
    .task-info-disclosure > summary { min-height: 34px; }
    .task-chat-panel .chat-shell {
        width: 100%;
        margin: 6px 0 14px;
        padding: 0;
        height: 72vh;
        min-height: 320px;
    }
    .chat-list { gap: 12px; }
    .message { max-width: 86%; }
    .message-meta { max-width: 100%; }
    .message-meta a { display: none; }
    .bubble { font-size: 14px; padding: 10px 13px; }
    .attachment-grid { grid-template-columns: 1fr; }
    .image-viewer {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .image-viewer-head {
        align-items: flex-start;
        flex-direction: column;
    }
    .image-viewer-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    #image-viewer-title {
        width: 100%;
    }
    textarea { min-height: 140px; }
    table { display: table; width: 100%; max-width: 100%; table-layout: fixed; overflow-x: visible; }
    th, td { min-width: 0; padding: 9px 6px; }
    td form { display: inline-flex; margin: 0 6px 6px 0; }
    .mobile-card-table { display: table; border-collapse: separate; border-spacing: 0 10px; }
    .mobile-card-table thead { display: none; }
    .mobile-card-table tbody { display: block; }
    .mobile-card-table tr {
        display: block;
        padding: 12px;
        border: 1px solid var(--border-soft);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: var(--shadow-sm);
    }
    .mobile-card-table td {
        display: grid;
        grid-template-columns: 100px minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        border-bottom: 0;
        padding: 5px 0;
        min-width: 0;
    }
    .mobile-card-table td::before {
        content: attr(data-label);
        color: var(--muted-strong);
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
    .mobile-card-table td[colspan] {
        display: block;
    }
    .mobile-card-table td[colspan]::before {
        content: none;
    }
    .mobile-card-table .environment-assign-form {
        min-width: 0;
        width: 100%;
    }
    .mobile-card-table td form {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin: 0;
    }
    .mobile-card-table .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .mobile-card-table .btn {
        width: auto;
        min-width: 92px;
    }
    .mobile-card-table .status {
        width: max-content;
    }
    .dashboard-page > .actions:first-child,
    .hosts-page .page-header {
        align-items: stretch;
        flex-direction: column;
    }
    .dashboard-page > .actions:first-child .btn,
    .hosts-page .page-header-actions,
    .hosts-page .page-header-actions .btn {
        width: 100%;
    }
    .hosts-page .page-header-actions {
        align-items: stretch;
        flex-direction: column;
    }
    .dashboard-page .group-header {
        align-items: flex-start;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 8px;
    }
    .dashboard-page .group-name {
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .dashboard-page .group-rev {
        justify-self: end;
    }
    .dashboard-page .group-count {
        grid-column: 1 / -1;
        margin-left: 0;
    }
    .dashboard-page .mobile-card-table td,
    .hosts-page .mobile-card-table td {
        grid-template-columns: 104px minmax(0, 1fr);
    }
    .dashboard-page .mobile-card-table td form,
    .hosts-page .mobile-card-table td form {
        width: 100%;
    }
    .dashboard-page .mobile-card-table .environment-assign-form {
        grid-template-columns: minmax(0, 1fr);
    }
    .dashboard-page .mobile-card-table .environment-assign-form .btn,
    .dashboard-page .mobile-card-table .action-buttons,
    .dashboard-page .mobile-card-table .action-buttons .btn,
    .hosts-page .mobile-card-table .action-buttons,
    .hosts-page .mobile-card-table .action-buttons .btn {
        width: 100%;
    }
    .dashboard-page .mobile-card-table .action-buttons,
    .hosts-page .mobile-card-table .action-buttons {
        align-items: stretch;
        flex-direction: column;
    }
    .dashboard-page .id-cell,
    .hosts-page .id-cell {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .hosts-page .panel-head {
        align-items: stretch;
        flex-direction: column;
    }
    .hosts-page .panel-head .btn,
    .hosts-page .panel-head .muted-link,
    .hosts-page .empty-state .btn {
        width: 100%;
    }
    .hosts-page details.collapsible > summary {
        align-items: flex-start;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .hosts-page details.collapsible > summary > .muted {
        grid-column: 1 / 2;
        margin: 0;
    }
    .hosts-page details.collapsible > summary::after {
        grid-column: 2 / 3;
        grid-row: 1 / span 2;
        align-self: center;
    }
    .hosts-page dialog.edit-dialog {
        width: calc(100vw - 24px);
    }
    .hosts-page .dialog-footer {
        align-items: stretch;
        flex-direction: column-reverse;
    }
    .hosts-page .dialog-footer .btn {
        width: 100%;
    }
    .value-edit-form { grid-template-columns: 1fr; gap: 6px; }
    .value-secret-toggle, .current-value { margin-bottom: 0; }
    .value-actions { margin-top: 4px; }
    .value-delete-form { display: block; margin-top: 4px; }
    .current-value { display: none; }
    .environment-assign-form { min-width: 160px; }
    .file-edit-grid { grid-template-columns: 1fr; gap: 6px; }
    .repo-edit-form { grid-template-columns: 1fr; gap: 6px; }
    .repo-actions { margin-top: 4px; }
    .token-profile-grid { grid-template-columns: 1fr; }
    .token-profile-head { align-items: flex-start; flex-direction: column; }
    pre { padding: 12px; font-size: 13px; }

    /* Compact mobile layout for environment-detail and similar dense forms */
    .panel { padding: 14px; }
    .value-panel { margin-top: 12px; }
    label { margin: 8px 0 4px; font-size: 13px; }
    h2 { font-size: 16px; }
    .actions { margin-top: 10px; gap: 8px; }
    .deploy-action, .danger-zone, .settings-form { margin-top: 10px; padding-top: 10px; }
    .danger-panel { margin-top: 10px; padding-top: 10px; }
    .meta-grid { grid-template-columns: 1fr; gap: 8px; }
    .task-status-row { align-items: flex-start; flex-direction: column; }
    .polling-state { margin-left: 0; }
    textarea { min-height: 110px; }
    details.collapsible > summary { padding: 12px; }
    details.collapsible > summary h2 { font-size: 15px; }
    details.collapsible > table { margin: 0 12px 12px; width: calc(100% - 24px); }
    details.collapsible > .details-body { padding: 0 12px 12px; }
    .token-profile { padding: 10px; }
    .token-profile.compact { padding: 8px; }
    .token-profile h3 { font-size: 14px; }
    .token-profile p { margin: 0 0 6px; font-size: 13px; }
    .token-permissions { margin-top: 6px; }
    .token-profile-list { gap: 8px; }
    .token-profile .actions {
        align-items: stretch;
        flex-direction: column;
    }
    .token-profile .actions .btn { width: 100%; }
    .value-edit-form > div + div { margin-top: 0; }
    .value-edit-form label, .file-edit-grid label, .repo-edit-form label { margin-top: 4px; }
    .env-detail > .actions:first-child {
        align-items: stretch;
        flex-direction: column;
        margin-bottom: 12px;
    }
    .env-detail > .actions:first-child .btn { width: 100%; }
    .env-detail > .muted {
        display: block;
        margin-top: 0;
        margin-bottom: 12px;
    }
    .env-detail .env-edit-table,
    .env-detail .env-edit-table thead,
    .env-detail .env-edit-table tbody,
    .env-detail .env-edit-table tr,
    .env-detail .env-edit-table td {
        display: block;
        width: 100%;
    }
    .env-detail .env-edit-table thead { display: none; }
    .env-detail .env-edit-table tr {
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: #ffffff;
        padding: 10px;
    }
    .env-detail .env-edit-table tr + tr { margin-top: 10px; }
    .env-detail .env-edit-table td {
        border-bottom: 0;
        padding: 0;
    }
    .env-detail .env-edit-table td[colspan] {
        padding: 0;
    }
    .env-detail .env-edit-table .value-edit-form,
    .env-detail .env-edit-table .repo-edit-form,
    .env-detail .env-edit-table .file-edit-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        width: 100%;
    }
    .env-detail .env-edit-table .actions,
    .env-detail .env-edit-table .value-delete-form {
        width: 100%;
    }
    .env-detail .env-edit-table .btn {
        width: 100%;
    }
    .env-detail .env-edit-table textarea {
        min-height: 180px;
    }
    .env-detail details.collapsible > table,
    .env-detail details.collapsible > table tbody,
    .env-detail details.collapsible > table tr,
    .env-detail details.collapsible > table th,
    .env-detail details.collapsible > table td {
        display: block;
        width: 100%;
    }
    .env-detail details.collapsible > table tr {
        border-bottom: 1px solid #e5e7eb;
        padding: 8px 0;
    }
    .env-detail details.collapsible > table tr:last-child { border-bottom: 0; }
    .env-detail details.collapsible > table th,
    .env-detail details.collapsible > table td {
        border-bottom: 0;
        padding: 3px 0;
    }
    .env-detail .danger-zone .btn,
    .env-detail .deploy-action .btn,
    .env-detail .settings-form .btn {
        width: 100%;
    }
}

/* --- Combined: components carried over from feature/ui-ux-polish --- */
.btn-sm {
    min-height: 28px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
}
.status.secret { background: #fef3f2; color: #b42318; }
.status.variable { background: #eef2ff; color: #3730a3; }
.collapsible-list { display: grid; gap: 10px; margin-top: 14px; }
.collapsible-list > details.collapsible {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.collapsible-list > details.collapsible:hover { border-color: #cbd3df; }
.collapsible-list > details.collapsible[open] {
    border-color: #cbd3df;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}
.collapsible-list > details.collapsible > summary { padding: 12px 16px; }
.collapsible-list > details.collapsible > summary:hover { background: #f9fafb; }
.collapsible-list > details.collapsible[open] > summary {
    border-bottom: 1px solid #eef1f5;
    border-radius: 8px 8px 0 0;
}
.collapsible-list > details.collapsible > .details-body { padding: 14px 16px 16px; }
.row-key { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.row-key code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    background: #f1f3f7;
    padding: 2px 6px;
    border-radius: 4px;
    color: #1f2937;
    overflow-wrap: anywhere;
}
.row-preview {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.more-menu { width: 100%; }
.more-menu > summary {
    list-style: none;
    cursor: pointer;
    width: max-content;
}
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu > summary::after {
    content: "▾";
    font-size: 10px;
    margin-left: 6px;
    transition: transform 0.15s ease;
}
.more-menu[open] > summary::after { transform: rotate(180deg); }
.more-menu-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fbfcfe;
}
.cli-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}
.cli-group-label {
    font-size: 12px;
    font-weight: 700;
    color: #475467;
    min-width: 48px;
}
.btn.is-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}
.btn.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
.btn.secondary.is-loading::after {
    border-color: rgba(31, 41, 55, 0.25);
    border-top-color: #1f2937;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .btn.is-loading::after { animation: none; }
}
@media (max-width: 760px) {
    .row-preview { max-width: 130px; }
}

/* --- Dashboard conversation inbox (messenger-style) --- */
.conversation-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.conversation-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.conversation-row:hover { background: var(--surface-muted); border-color: var(--border); text-decoration: none; }
.conversation-row.unread { border-color: var(--primary); background: var(--primary-soft); }
.conversation-indicator {
    flex: 0 0 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
}
.conversation-row.unread .conversation-indicator {
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.18);
}
.conversation-body { min-width: 0; flex: 1 1 auto; display: grid; gap: 2px; }
.conversation-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.conversation-title {
    font-weight: 600;
    color: var(--text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.conversation-row.unread .conversation-title { font-weight: 800; }
.conversation-head .relative-time { flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.conversation-preview {
    display: flex;
    gap: 6px;
    min-width: 0;
    font-size: 13px;
    color: var(--muted-strong);
}
.conversation-author { flex: 0 0 auto; font-weight: 700; color: var(--muted); }
.conversation-author.agent { color: var(--primary); }
.conversation-row.unread .conversation-preview { color: var(--text-strong); }
.conversation-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conversation-row > .status { flex: 0 0 auto; }
