:root {
  color-scheme: light dark;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-soft: #efefeb;
  --surface-raised: rgba(255, 255, 255, .82);
  --text: #191a18;
  --muted: #74756f;
  --line: #deded8;
  --line-strong: #c7c8c0;
  --accent: #2e6452;
  --accent-strong: #184837;
  --accent-soft: #dcebe4;
  --danger: #b84234;
  --danger-soft: #fae2dd;
  --warning: #9a6314;
  --warning-soft: #f5e9ce;
  --ok: #27725a;
  --ok-soft: #dbede5;
  --shadow: 0 18px 48px rgba(19, 31, 25, .10);
  --sidebar: 232px;
  --visual-viewport-height: 100dvh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #111412;
  --surface: #181c19;
  --surface-soft: #202521;
  --surface-raised: rgba(24, 28, 25, .88);
  --text: #f1f3ef;
  --muted: #999f98;
  --line: #303630;
  --line-strong: #454c45;
  --accent: #7fc0a5;
  --accent-strong: #a1d8c1;
  --accent-soft: #213d32;
  --danger: #ef8b7d;
  --danger-soft: #492621;
  --warning: #e2b361;
  --warning-soft: #44351c;
  --ok: #77c8a7;
  --ok-soft: #213d32;
  --shadow: 0 22px 56px rgba(0, 0, 0, .36);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111412; --surface: #181c19; --surface-soft: #202521; --surface-raised: rgba(24, 28, 25, .88);
    --text: #f1f3ef; --muted: #999f98; --line: #303630; --line-strong: #454c45;
    --accent: #7fc0a5; --accent-strong: #a1d8c1; --accent-soft: #213d32;
    --danger: #ef8b7d; --danger-soft: #492621; --warning: #e2b361; --warning-soft: #44351c;
    --ok: #77c8a7; --ok-soft: #213d32; --shadow: 0 22px 56px rgba(0, 0, 0, .36);
  }
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { min-height: var(--visual-viewport-height); overflow: hidden; }
button, input, select, textarea { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 2.2vw, 2.25rem); letter-spacing: -.035em; line-height: 1.1; }
h2 { font-size: 1.35rem; letter-spacing: -.025em; }
h3 { font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; clip: rect(0,0,0,0); overflow: hidden; white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.eyebrow { color: var(--muted); font-size: .69rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }

.console-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); width: 100%; height: var(--visual-viewport-height); min-height: 100dvh; }
.sidebar { position: relative; display: flex; flex-direction: column; gap: 34px; padding: calc(22px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)); background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; min-height: 44px; }
.brand-mark { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; color: #f4fff9; background: var(--accent-strong); border-radius: 12px; font-size: 1.2rem; }
.brand-mark.large { width: 48px; height: 48px; margin-bottom: 22px; border-radius: 15px; font-size: 1.45rem; }
.brand-copy { display: grid; line-height: 1.04; }
.brand-copy strong { font-size: .95rem; letter-spacing: -.015em; }
.brand-copy small { color: var(--muted); font-size: .72rem; }
.nav-list { display: grid; gap: 5px; }
.nav-list a, .nav-button { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; color: var(--muted); background: transparent; border: 0; border-radius: 10px; font-size: .88rem; font-weight: 650; cursor: pointer; }
.nav-list i, .nav-button i { width: 22px; font-size: 1.25rem; text-align: center; }
.nav-list a:hover, .nav-button:hover { color: var(--text); background: var(--surface-soft); }
.nav-list a.is-active { color: var(--accent-strong); background: var(--accent-soft); }
.sidebar-footer { display: grid; gap: 4px; margin-top: auto; }

.workspace { min-width: 0; height: 100%; overflow: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; min-height: 112px; padding: calc(22px + env(safe-area-inset-top)) clamp(24px, 4vw, 56px) 22px; background: color-mix(in srgb, var(--bg) 88%, transparent); border-bottom: 1px solid transparent; backdrop-filter: blur(16px); }
.topbar > div:first-child { display: grid; gap: 7px; }
.content { width: min(1480px, 100%); padding: 28px clamp(24px, 4vw, 56px) 64px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.toolbar-copy { color: var(--muted); font-size: .86rem; }
.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 15px; border: 1px solid transparent; border-radius: 10px; font-size: .82rem; font-weight: 730; cursor: pointer; }
.button.primary { color: #f7fffb; background: var(--accent-strong); }
.button.primary:hover { filter: brightness(1.08); }
.button.secondary { background: var(--surface); border-color: var(--line); }
.button.secondary:hover { border-color: var(--line-strong); }
.button.danger { color: var(--danger); background: var(--danger-soft); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.full { width: 100%; }
.icon-button { width: 40px; padding: 0; color: var(--muted); background: transparent; }
.icon-button:hover { color: var(--text); background: var(--surface-soft); }

.data-table { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.data-header, .project-row, .data-row { display: grid; align-items: center; column-gap: 20px; min-width: 850px; padding: 0 20px; }
.data-header { min-height: 42px; color: var(--muted); background: var(--surface-soft); border-bottom: 1px solid var(--line); font-size: .66rem; font-weight: 760; letter-spacing: .1em; text-transform: uppercase; }
.project-grid { grid-template-columns: minmax(135px, 1.2fr) 74px 74px minmax(120px, 1fr) 66px minmax(92px, .75fr); min-width: 0; column-gap: 12px; padding-inline: 14px; }
.project-row { min-height: 76px; transition: background .16s ease; }
.project-row + .project-row, .data-row + .data-row { border-top: 1px solid var(--line); }
.project-row:hover, .data-row:hover { background: var(--surface-soft); }
.project-identity { min-width: 0; display: flex; align-items: center; gap: 12px; }
.project-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; color: var(--accent-strong); background: var(--accent-soft); border-radius: 10px; font-weight: 800; }
.project-identity strong, .project-identity small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-identity strong { font-size: .9rem; }
.project-identity small { margin-top: 3px; color: var(--muted); font-size: .73rem; }
.status { display: inline-flex; align-items: center; gap: 6px; width: max-content; max-width: 100%; color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: capitalize; }
.status::before { width: 7px; height: 7px; content: ""; background: var(--muted); border-radius: 50%; }
.status.running::before, .status.online::before, .status.healthy::before, .status.completed::before { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status.paused::before, .status.starting::before, .status.draining::before, .status.blocked::before, .status.warning::before { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.status.error::before, .status.failed::before, .status.cancelled::before { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.metric { font-size: .83rem; font-variant-numeric: tabular-nums; }
.metric strong { font-size: .88rem; }
.progress { display: grid; gap: 7px; }
.progress-copy { display: flex; justify-content: space-between; color: var(--muted); font-size: .71rem; font-variant-numeric: tabular-nums; }
.progress-track { height: 5px; overflow: hidden; background: var(--surface-soft); border-radius: 99px; }
.progress-track span { display: block; height: 100%; width: var(--progress); background: var(--accent); border-radius: inherit; }
.error-copy { overflow: hidden; color: var(--danger); font-size: .72rem; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }

.project-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.project-heading-copy { display: flex; align-items: center; gap: 14px; min-width: 0; }
.project-heading-copy .project-avatar { width: 44px; height: 44px; }
.project-heading h2 { overflow: hidden; font-size: 1.45rem; text-overflow: ellipsis; white-space: nowrap; }
.project-heading p { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.project-tabs { display: flex; gap: 3px; overflow-x: auto; margin-bottom: 24px; padding: 3px; background: var(--surface-soft); border-radius: 11px; scrollbar-width: none; }
.project-tabs button { min-height: 35px; padding: 0 13px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: .76rem; font-weight: 700; white-space: nowrap; cursor: pointer; }
.project-tabs button.is-active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.overview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { min-height: 124px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.stat-label { color: var(--muted); font-size: .72rem; font-weight: 650; }
.stat-value { margin-top: 20px; font-size: clamp(1.35rem, 2.3vw, 2rem); font-weight: 740; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stat-detail { margin-top: 7px; color: var(--muted); font-size: .7rem; }
.section-panel { margin-top: 18px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.detail-list { display: grid; }
.detail-line { display: grid; grid-template-columns: minmax(130px, .7fr) minmax(0, 1.3fr); gap: 20px; padding: 13px 0; border-top: 1px solid var(--line); font-size: .8rem; }
.detail-line:first-child { border-top: 0; }
.detail-line span:first-child { color: var(--muted); }

.action-zone { position: sticky; z-index: 15; bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; width: max-content; max-width: 100%; margin: 28px auto 0; padding: 9px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); backdrop-filter: blur(20px); }
.action-zone.is-static { position: static; }
.action-zone .action-copy { display: grid; gap: 4px; max-width: 430px; padding: 0 8px; color: var(--muted); font-size: .73rem; }
.action-zone .action-hint { line-height: 1.4; }
.action-buttons { display: flex; gap: 7px; }
.action-buttons.is-pending .button { min-width: 118px; }
.button-spinner { width: 14px; height: 14px; border-color: rgba(255, 255, 255, .38); border-top-color: currentColor; }

.data-list { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.run-grid { grid-template-columns: 1fr .65fr .65fr .7fr .7fr .7fr; }
.log-grid { grid-template-columns: .7fr .7fr .9fr 1.4fr .8fr; }
.session-grid { grid-template-columns: .65fr .65fr .7fr .7fr .7fr 1fr; }
.data-row { min-height: 58px; font-size: .76rem; }
.data-row time, .data-row .mono { color: var(--muted); font-variant-numeric: tabular-nums; }
.data-row .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.form-panel { max-width: 840px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.form-panel + .form-panel { margin-top: 18px; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-panel .form-grid { margin-top: 20px; }
.settings-form { display: grid; gap: 20px; }
.settings-form .form-grid, .settings-form .form-actions { margin-top: 0; }
.form-section, .form-section-copy { display: grid; gap: 12px; }
.form-section-copy { gap: 4px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .74rem; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; outline: none; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.form-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.form-error { min-height: 18px; color: var(--danger); font-size: .73rem; }

.state-panel { display: grid; place-items: center; align-content: center; gap: 12px; min-height: 360px; padding: 48px 24px; color: var(--muted); text-align: center; }
.state-panel i { font-size: 2.2rem; }
.state-panel h2 { color: var(--text); }
.state-panel p { max-width: 430px; font-size: .82rem; line-height: 1.55; }
.spinner { width: 24px; height: 24px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pin-gate { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; min-height: var(--visual-viewport-height); padding: calc(20px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left)); background: radial-gradient(circle at 50% 20%, var(--accent-soft), var(--bg) 46%); }
.pin-gate.is-hidden { display: none; }
.pin-panel { width: min(390px, 100%); padding: 34px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); backdrop-filter: blur(20px); }
.pin-panel h1 { margin: 7px 0 10px; }
.pin-panel .muted { margin-bottom: 24px; font-size: .82rem; }
.pin-input { height: 58px; margin-bottom: 12px; font-size: 1.4rem; font-weight: 760; letter-spacing: .65em; text-align: center; text-indent: .65em; }

.modal { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 20px; color: var(--text); background: rgba(12, 16, 13, .38); border: 0; }
.modal[open] { display: grid; place-items: center; }
.modal::backdrop { background: transparent; }
.modal-panel { display: grid; gap: 16px; width: min(540px, 100%); max-height: calc(var(--visual-viewport-height) - 40px); overflow: auto; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.modal-head h2 { margin-top: 5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast-region { position: fixed; z-index: 150; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(380px, calc(100% - 36px)); pointer-events: none; }
.toast { padding: 13px 15px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); font-size: .78rem; animation: toast-in .2s ease-out; }
.toast.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }
.bottom-nav { display: none; }

@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar: 72px; }
  .sidebar { align-items: center; padding-inline: 10px; }
  .brand { padding: 0; }
  .brand-copy, .nav-list span, .nav-button span { display: none; }
  .nav-list, .sidebar-footer { width: 100%; }
  .nav-list a, .nav-button { justify-content: center; width: 100%; padding: 0; }
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  body { overflow: hidden; }
  .console-shell { display: block; }
  .sidebar { display: none; }
  .workspace { height: var(--visual-viewport-height); padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 92px; padding: calc(15px + env(safe-area-inset-top)) 18px 15px; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.55rem; }
  .content { padding: 18px 14px 48px; }
  .bottom-nav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); min-height: calc(62px + env(safe-area-inset-bottom)); padding: 6px env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); background: var(--surface-raised); border-top: 1px solid var(--line); backdrop-filter: blur(20px); transition: transform .2s ease, opacity .2s ease; }
  .bottom-nav a { display: grid; place-items: center; align-content: center; gap: 3px; min-width: 0; color: var(--muted); border-radius: 10px; font-size: .62rem; font-weight: 700; }
  .bottom-nav a i { font-size: 1.32rem; }
  .bottom-nav a.is-active { color: var(--accent-strong); background: var(--accent-soft); }
  body.keyboard-open .bottom-nav { opacity: 0; pointer-events: none; transform: translateY(110%); }
  body.keyboard-open .workspace { padding-bottom: env(safe-area-inset-bottom); }
  .toolbar { align-items: flex-start; }
  .toolbar-copy { max-width: 62%; }
  .data-table, .data-list { overflow: visible; background: transparent; border: 0; border-radius: 0; }
  .data-header { display: none; }
  .project-row { display: grid; grid-template-columns: 1fr auto; gap: 13px; min-width: 0; min-height: 0; margin-bottom: 10px; padding: 17px; background: var(--surface); border: 1px solid var(--line) !important; border-radius: 13px; }
  .project-row > :nth-child(4) { grid-column: 1 / -1; }
  .project-row > :nth-child(5) { grid-column: 1; }
  .project-row > :nth-child(6) { grid-column: 2; max-width: 130px; text-align: right; }
  .project-row > .status.worker { display: none; }
  .project-identity { grid-column: 1; }
  .project-row > .status { grid-column: 2; }
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { min-height: 110px; padding: 16px; }
  .stat-value { margin-top: 15px; font-size: 1.35rem; }
  .project-heading { align-items: flex-start; }
  .project-heading .status { margin-top: 8px; }
  .section-panel { padding: 17px; }
  .detail-line { grid-template-columns: 1fr; gap: 5px; }
  .data-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 18px; min-width: 0; min-height: 0; margin-bottom: 10px; padding: 15px; background: var(--surface); border: 1px solid var(--line) !important; border-radius: 12px; }
  .action-zone { bottom: 8px; display: block; width: 100%; margin-top: 22px; }
  .action-zone .action-copy { display: none; }
  .action-zone.is-pending .action-copy { display: grid; padding: 0 8px 9px; }
  .action-buttons { display: grid; grid-template-columns: repeat(3, 1fr); }
  .action-buttons.is-pending { grid-template-columns: 1fr; }
  .action-buttons .button { padding-inline: 8px; font-size: .72rem; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .pin-panel { padding: 27px 23px; }
  .modal { padding: 10px; }
  .modal-panel { max-height: calc(var(--visual-viewport-height) - 20px); padding: 20px; }
  .toast-region { top: calc(102px + env(safe-area-inset-top)); bottom: auto; }
  body.keyboard-open .toast-region { top: calc(12px + env(safe-area-inset-top)); bottom: auto; }
}

@media (max-width: 390px) {
  .overview-grid { grid-template-columns: 1fr; }
  .project-row > :nth-child(6) { display: none; }
  .action-buttons { grid-template-columns: repeat(2, 1fr); }
}

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