:root {
  --bg: #f3f6f8;
  --surface: #fff;
  --surface-soft: #f7f9fa;
  --ink: #17212b;
  --muted: #65727e;
  --line: #dce3e8;
  --brand: #0c6b58;
  --brand-dark: #084c40;
  --brand-soft: #dff3ea;
  --danger: #9f3535;
  --danger-soft: #fdeaea;
  --warning: #8a5d10;
  --shadow: 0 10px 28px rgba(20, 35, 48, .07);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button, a, input, select { outline-offset: 3px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex="0"]:focus-visible { outline: 3px solid #4c9d8d; }
h1 { margin: .25rem 0; font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.2; }
h2 { margin: 0; font-size: 1.2rem; }
hr { margin: 26px 0; border: 0; border-top: 1px solid var(--line); }
.muted, .muted-text, .page-description, .secondary-text { color: var(--muted); }
.muted-text, .page-description { margin: 4px 0 0; }
.secondary-text { display: block; margin-top: 3px; font-size: .78rem; }
.eyebrow { margin: 0; color: var(--brand); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.align-right { text-align: right; }
.number, .money { font-variant-numeric: tabular-nums; }
.money { white-space: nowrap; }
.money-available { color: var(--brand-dark); font-weight: 700; }
.money-reserved { color: var(--warning); }
.unavailable { color: var(--muted); font-style: italic; }
.refresh-indicator { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); }
.refresh-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #e8f2ef, #f7f9fa); }
.login-card { width: min(420px, 100%); padding: 38px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 18px; margin-top: 28px; }
.login-card label { display: grid; gap: 7px; font-weight: 700; }
.login-card input { width: 100%; padding: 12px 14px; border: 1px solid #b8c4cc; border-radius: 9px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); grid-template-rows: 64px minmax(0, 1fr) 44px; grid-template-areas: "header header" "aside main" "footer footer"; }
.app-header, header { grid-area: header; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: #102a25; color: #fff; }
.brand { margin-right: 18px; font-size: 1.1rem; font-weight: 900; }
.admin-box { display: flex; align-items: center; gap: 16px; }
.admin-box form { margin: 0; }
.link-button { border: 0; border-radius: 9px; background: #245f53; color: #fff; padding: 7px 12px; font-weight: 800; cursor: pointer; }
aside { grid-area: aside; min-width: 0; padding: 22px 14px; background: #173a33; color: #dcebe7; }
aside nav { display: grid; gap: 5px; }
aside nav a, aside nav span { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 8px; color: inherit; text-decoration: none; }
aside nav .active { background: #266a5d; color: #fff; font-weight: 800; }
aside nav span { opacity: .62; }
aside nav small { font-size: .7rem; }
.page-content, main { grid-area: main; min-width: 0; padding: 28px; overflow-x: hidden; }
footer { grid-area: footer; padding: 12px 24px; background: #fff; border-top: 1px solid var(--line); color: var(--muted); }

.page-title, .page-heading, .client-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.client-heading { align-items: center; }
.breadcrumbs { display: flex; gap: 9px; margin-bottom: 14px; color: var(--muted); }
.breadcrumbs a { color: var(--brand); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; border: 0; border-radius: 8px; background: var(--brand); color: #fff; padding: 9px 14px; font-weight: 800; text-decoration: none; cursor: pointer; white-space: nowrap; }
.button-secondary, .button-quiet { border: 1px solid #bfd1cc; background: #edf4f2; color: var(--brand-dark); }
.button-danger { background: var(--danger); }
.button-small { min-height: 32px; padding: 5px 9px; font-size: .85rem; }
.button-disabled { border: 1px solid var(--line); background: var(--surface-soft); color: #9aa4ac; cursor: default; }

.toolbar { display: grid; grid-template-columns: minmax(280px, 2fr) minmax(150px, .55fr) minmax(180px, .7fr) auto; align-items: end; gap: 14px; margin-bottom: 20px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.compact-toolbar { grid-template-columns: minmax(260px, 2fr) minmax(190px, 1fr) auto; margin-top: 18px; box-shadow: none; }
.execution-toolbar { grid-template-columns: minmax(260px, 1.8fr) repeat(5, minmax(140px, .7fr)); }
.execution-toolbar .toolbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
.toolbar-actions, .form-actions, .row-actions, .pagination-actions, .copy-row { display: flex; align-items: center; gap: 10px; }
.field { display: grid; align-content: start; gap: 6px; min-width: 0; }
.field label { font-weight: 750; }
.field input, .field select { width: 100%; min-width: 0; padding: 10px 11px; border: 1px solid #b8c4cc; border-radius: 8px; background: #fff; color: var(--ink); }
.field input:invalid:not(:placeholder-shown) { border-color: var(--danger); }
.field small { color: var(--muted); }
.field-full { grid-column: 1 / -1; }

.data-panel, .content-card, .status-panel { min-width: 0; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.data-panel-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.data-table { width: 100%; min-width: 1120px; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
.data-table caption { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.data-table th, .data-table td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th { position: sticky; top: 0; z-index: 1; background: #eaf0f2; color: #46545f; font-size: .77rem; font-weight: 800; letter-spacing: .025em; text-transform: uppercase; white-space: nowrap; }
.data-table th.align-right, .data-table td.align-right { text-align: right; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #f5faf8; }
.data-table code { font-size: .8rem; }
.client-cell { min-width: 220px; }
.client-cell a { color: var(--brand-dark); text-decoration: none; }
.client-cell strong { display: block; font-size: .96rem; }
.client-cell span { display: block; max-width: 240px; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; }
.row-actions { min-width: 190px; flex-wrap: wrap; }
.row-actions a { color: var(--brand-dark); font-size: .83rem; font-weight: 700; text-decoration: none; }
.row-actions a:hover { text-decoration: underline; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; font-size: .82rem; font-weight: 750; white-space: nowrap; }
.status-active { border-color: #b9dfd1; background: var(--brand-soft); color: var(--brand-dark); }
.status-inactive { border-color: #e2caca; background: var(--danger-soft); color: #793232; }
.execution-status { display: inline-flex; align-items: center; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; font-size: .82rem; font-weight: 750; white-space: nowrap; }
.execution-status-pending { border-color: #d7c793; background: #fff6d8; color: #765a00; }
.execution-status-processing { border-color: #a9cce7; background: #e5f3fc; color: #185982; }
.execution-status-succeeded { border-color: #b9dfd1; background: var(--brand-soft); color: var(--brand-dark); }
.execution-status-failed { border-color: #e2caca; background: var(--danger-soft); color: #793232; }
.execution-status-cancelled { border-color: #c9cfd4; background: #edf0f2; color: #4c5963; }
.execution-status-expired { border-color: #d5c2df; background: #f2e9f7; color: #654076; }
.execution-status-reconciliation_required { border-color: #e4c798; background: #fff0d7; color: #78510b; }
.worker-status { display: inline-flex; align-items: center; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; font-size: .82rem; font-weight: 750; white-space: nowrap; }
.worker-status-online { border-color: #b9dfd1; background: var(--brand-soft); color: var(--brand-dark); }
.worker-status-offline { border-color: #e2caca; background: var(--danger-soft); color: #793232; }
.worker-status-delayed { border-color: #e4c798; background: #fff0d7; color: #78510b; }
.worker-status-unknown { border-color: #c9cfd4; background: #edf0f2; color: #4c5963; }
.execution-results { margin-top: 20px; }
.worker-results { margin-top: 20px; }
.execution-table { min-width: 1380px; }
.worker-table { min-width: 1480px; }
.job-results { margin-top: 20px; }
.job-table { min-width: 1720px; }
.job-status { display: inline-flex; align-items: center; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; font-size: .82rem; font-weight: 750; white-space: nowrap; }
.job-status-pending { border-color: #d7c793; background: #fff6d8; color: #765a00; }
.job-status-leased, .job-status-processing { border-color: #a9cce7; background: #e5f3fc; color: #185982; }
.job-status-retrying { border-color: #d8b98b; background: #fff0d7; color: #78510b; }
.job-status-completed { border-color: #b9dfd1; background: var(--brand-soft); color: var(--brand-dark); }
.job-status-failed { border-color: #e2caca; background: var(--danger-soft); color: #793232; }
.job-status-expired { border-color: #d5c2df; background: #f2e9f7; color: #654076; }
.job-status-reconciliation_required { border-color: #e4c798; background: #fff0d7; color: #78510b; }
.job-attention { background: #fffaf0; }
.job-alert { display: block; width: max-content; max-width: 260px; margin-top: 5px; border-radius: 5px; background: #fff0d7; color: #78510b; padding: 2px 6px; font-size: .72rem; font-weight: 700; }
.job-alert-neutral { background: #edf0f2; color: #4c5963; }
.job-alert-panel { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; padding: 13px; border: 1px solid #e4c798; border-radius: 10px; background: #fffaf0; }
.job-alert-panel span { color: #78510b; font-weight: 750; }
.execution-table td a { color: var(--brand-dark); }
.empty-state { min-width: 280px; padding: 34px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 1rem; }
.empty-state p { margin: 5px 0 0; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; }
.pagination p { margin: 0; color: var(--muted); }

.summary-cards, .cards { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.summary-cards article, .cards article { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 5px 15px rgba(20, 35, 48, .04); }
.summary-cards p, .cards p { margin: 0; color: var(--muted); }
.summary-cards strong, .cards strong { display: block; margin-top: 7px; font-size: 1.5rem; }
.content-card, .status-panel { margin-top: 20px; }
.definition-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 22px; margin-bottom: 0; }
.definition-grid div { min-width: 0; padding: 14px 0; border-bottom: 1px solid var(--line); }
.definition-grid dt { color: var(--muted); }
.definition-grid dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 700; }
.execution-definition { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.artifact-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.artifact-card dl { display: flex; flex: 1; justify-content: center; gap: 32px; margin: 0; }
.artifact-card dt { color: var(--muted); }
.artifact-card dd { margin: 3px 0 0; }
.artifact-card code { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.data-note { padding: 10px 12px; border-left: 3px solid #9aabb5; background: var(--surface-soft); color: var(--muted); }
.section-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.section-grid-wide { grid-template-columns: minmax(290px, .8fr) minmax(0, 2fr); }
.section-grid .content-card { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.compact-form { grid-template-columns: 1fr; }
.balance { display: grid; margin: 18px 0; }
.balance strong { font-size: 1.8rem; }
.balance span { color: var(--muted); }
.tabs { display: flex; gap: 5px; margin-bottom: 20px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 14px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 700; text-decoration: none; white-space: nowrap; }
.tabs a.active { background: var(--brand); color: #fff; }
.feedback, .secret-once { padding: 13px 15px; border-radius: 9px; }
.feedback-success, .secret-once { background: var(--brand-soft); color: var(--brand-dark); }
.feedback-error { background: var(--danger-soft); color: var(--danger); }
.secret-once { margin-bottom: 18px; }
.secret-once p { margin: 5px 0 12px; }
.secret-once code { min-width: 0; flex: 1; overflow-x: auto; padding: 10px; background: #fff; }
.timeline { margin: 18px 0 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 20px; padding: 15px; border-bottom: 1px solid var(--line); border-left: 3px solid var(--brand); }
.timeline time, .timeline small { color: var(--muted); }
.timeline p { margin: 3px 0; }

.status-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 28px; }
.status-grid > div { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.badge { padding: 2px 9px; border-radius: 99px; background: #e9eef1; }
.badge.healthy { background: var(--brand-soft); color: var(--brand-dark); }
.badge.attention { background: #fff0cf; color: var(--warning); }
.badge.unavailable { background: var(--danger-soft); color: var(--danger); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }

dialog { width: min(560px, calc(100% - 30px)); border: 0; border-radius: 14px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(4, 25, 21, .55); }
.dialog-form { display: grid; gap: 10px; }

@media (max-width: 1180px) {
  .toolbar { grid-template-columns: minmax(240px, 1fr) repeat(2, minmax(150px, .5fr)); }
  .toolbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .summary-cards, .cards, .definition-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-grid, .section-grid-wide { grid-template-columns: 1fr; }
  .execution-toolbar { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
  .execution-definition { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .artifact-card { align-items: flex-start; flex-direction: column; }
  .artifact-card dl { justify-content: flex-start; flex-wrap: wrap; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "header" "aside" "main" "footer"; }
  aside { overflow-x: auto; }
  aside nav { display: flex; min-width: max-content; }
  .page-content, main { padding: 22px; }
  .data-table { min-width: 1080px; }
}

@media (max-width: 640px) {
  .app-header, header { align-items: flex-start; padding: 14px; gap: 12px; }
  .admin-box { align-items: flex-end; flex-direction: column; gap: 5px; }
  .page-content, main { padding: 16px; }
  .page-heading, .page-title, .client-heading { align-items: stretch; flex-direction: column; }
  .toolbar, .compact-toolbar, .form-grid { grid-template-columns: 1fr; }
  .toolbar-actions, .form-actions { grid-column: 1; flex-wrap: wrap; }
  .summary-cards, .cards, .definition-grid { grid-template-columns: 1fr; }
  .execution-toolbar, .execution-definition { grid-template-columns: 1fr; }
  .pagination, .data-panel-heading, .section-heading { align-items: flex-start; flex-direction: column; }
  .copy-row { align-items: stretch; flex-direction: column; }
  .timeline li { grid-template-columns: 1fr; }
}
