:root {
  color-scheme: light;
  --canvas: #f4f6f3;
  --surface: #ffffff;
  --surface-subtle: #eef2ee;
  --text: #16201c;
  --text-muted: #5c6963;
  --border: #ccd5cf;
  --border-strong: #9eaca4;
  --accent: #126a5a;
  --accent-hover: #0c584b;
  --accent-soft: #e2f1ec;
  --success: #18724d;
  --warning: #96610b;
  --warning-soft: #fff4d8;
  --danger: #a33737;
  --danger-soft: #fdeaea;
  --focus: #176fbd;
  --shadow-sm: 0 1px 2px rgba(20, 35, 29, 0.08), 0 8px 24px rgba(20, 35, 29, 0.06);
  --radius-sm: 8px;
  --radius-md: 14px;
  --content: 1180px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--canvas);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
  touch-action: manipulation;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: rgba(18, 106, 90, 0.2);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

input::placeholder {
  color: #75827b;
}

input:hover,
select:hover {
  border-color: #75867d;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 72%, white);
  outline-offset: 2px;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
dl,
dd,
ul,
ol {
  margin-top: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.2;
  scroll-margin-top: 88px;
  text-wrap: balance;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: white;
}

.skip-link:focus {
  transform: translateY(0);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--text);
  color: white;
  font-size: 12px;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.boot-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  align-content: space-between;
}

.boot-copy {
  width: min(100%, 520px);
  margin: auto;
  padding-bottom: 14vh;
}

.boot-copy h1 {
  margin: 20px 0 8px;
  font-size: clamp(28px, 5vw, 42px);
}

.boot-copy p,
.supporting-copy,
.field-help,
.section-heading p,
.page-heading > div > p:last-child,
.empty-state p,
.loading-state p {
  color: var(--text-muted);
}

.activity-pulse {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

.public-header,
.app-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, var(--canvas));
}

.public-header {
  display: flex;
  min-height: 72px;
  padding: 16px max(24px, calc((100vw - var(--content)) / 2));
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.public-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.auth-shell {
  min-height: 100vh;
}

.auth-main {
  display: grid;
  width: min(100% - 48px, 980px);
  min-height: calc(100vh - 73px);
  margin: 0 auto;
  padding: 64px 0;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  align-items: center;
  gap: 72px;
}

.auth-intro h1 {
  max-width: 600px;
  margin-bottom: 20px;
  font-size: clamp(34px, 5vw, 54px);
  letter-spacing: -0.035em;
}

.auth-intro > p:not(.eyebrow) {
  max-width: 610px;
  color: var(--text-muted);
  font-size: 18px;
}

.auth-points {
  display: grid;
  margin: 28px 0 0;
  padding: 0;
  gap: 12px;
  list-style: none;
}

.auth-points li {
  position: relative;
  padding-left: 28px;
}

.auth-points li::before {
  position: absolute;
  left: 2px;
  color: var(--success);
  content: "✓";
  font-weight: 800;
}

.auth-card {
  display: grid;
  padding: 28px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  gap: 24px;
}

.auth-card h2 {
  margin-bottom: 6px;
  font-size: 24px;
}

.auth-card p {
  margin-bottom: 0;
}

.field-stack {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.field-stack label {
  font-size: 14px;
  font-weight: 700;
}

.field-help,
.form-error {
  margin: 0;
  font-size: 13px;
}

.form-error {
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  color: #792828;
}

.secret-field {
  position: relative;
}

.secret-field:focus-within {
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 35%, transparent);
}

.secret-field input {
  padding-right: 68px;
}

.secret-toggle {
  position: absolute;
  top: 0;
  right: 4px;
  min-width: 56px;
  height: 44px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 750;
}

.primary-button {
  padding: 10px 18px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.primary-button[aria-busy="true"]::after {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 9px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  content: "";
  vertical-align: -1px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.secondary-button {
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.text-button:active:not(:disabled) {
  filter: brightness(0.92);
}

.text-button {
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--accent);
}

.text-button:hover:not(:disabled) {
  background: var(--accent-soft);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
}

.header-inner {
  display: flex;
  width: min(100% - 48px, var(--content));
  min-height: 68px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-actions,
.connection-state {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 12px;
}

.connection-state {
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  gap: 7px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.connection-state[data-status="live"] .status-dot,
.status-badge[data-status="online"]::before {
  background: var(--success);
}

.connection-state[data-status="offline"] .status-dot,
.status-badge[data-status="offline"]::before {
  background: var(--text-muted);
}

.connection-state[data-status="error"] .status-dot,
.status-badge[data-status="degraded"]::before {
  background: var(--danger);
}

.dashboard-main {
  width: min(100% - 48px, var(--content));
  margin: 0 auto;
  padding: 40px 0 64px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
}

.page-heading h1 {
  margin-bottom: 6px;
  font-size: clamp(30px, 5vw, 44px);
  letter-spacing: -0.035em;
}

.page-heading > div > p:last-child {
  margin-bottom: 0;
}

.summary-strip {
  display: flex;
  margin-bottom: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.summary-strip > div {
  min-width: 100px;
  padding: 12px 16px;
}

.summary-strip > div + div {
  border-left: 1px solid var(--border);
}

.summary-strip dt {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-strip dd {
  margin: 1px 0 0;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.notice {
  display: flex;
  margin-top: 24px;
  padding: 14px 16px;
  border: 1px solid #dec078;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  gap: 12px;
}

.notice[data-tone="error"] {
  border-color: #d99b9b;
  background: var(--danger-soft);
}

.notice[data-tone="info"] {
  border-color: #a9c8be;
  background: var(--accent-soft);
}

.notice-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}

.notice strong,
.notice p {
  margin: 0;
}

.notice p {
  color: var(--text-muted);
  font-size: 14px;
}

.filters {
  margin-top: 24px;
  padding: 20px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-subtle) 60%, transparent);
}

.filter-heading,
.section-heading,
.device-heading,
.session-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.filter-heading h2,
.section-heading h2 {
  margin-bottom: 2px;
  font-size: 18px;
}

.filter-heading p,
.section-heading p {
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.filter-grid {
  display: grid;
  margin-top: 16px;
  grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(150px, 1fr));
  gap: 12px;
}

.activity-region {
  margin-top: 32px;
}

.loading-state {
  display: flex;
  margin-top: 20px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  align-items: center;
  gap: 16px;
}

.loading-state strong,
.loading-state p {
  margin: 0;
}

.empty-state {
  margin-top: 20px;
  padding: 56px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  text-align: center;
}

.empty-glyph {
  display: inline-grid;
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 26px;
}

.empty-state h3 {
  margin-bottom: 6px;
  font-size: 18px;
}

.empty-state p {
  margin-bottom: 0;
}

.device-list {
  display: grid;
  margin-top: 20px;
  gap: 18px;
}

.device-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(20, 35, 29, 0.04);
  content-visibility: auto;
  contain-intrinsic-size: auto 260px;
}

.device-panel[data-status="offline"] {
  background: #fafbfa;
}

.device-panel[data-status="degraded"] {
  border-color: #d8b366;
}

.device-heading {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
  align-items: center;
}

.device-title {
  min-width: 0;
}

.device-title h3 {
  margin-bottom: 2px;
  overflow-wrap: anywhere;
  font-size: 18px;
}

.device-title p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.status-badge,
.phase-badge,
.provider-badge,
.diagnostic-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-badge {
  padding: 6px 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  gap: 6px;
}

.status-badge::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  content: "";
}

.session-list,
.subagent-list,
.diagnostic-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.session-list > li + li {
  border-top: 1px solid var(--border);
}

.session-row {
  padding: 20px;
}

.session-row[data-stale="true"] {
  opacity: 0.78;
}

.session-heading {
  align-items: start;
}

.session-title {
  min-width: 0;
}

.session-title h4 {
  margin: 5px 0 4px;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.session-title p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.phase-badge {
  padding: 4px 8px;
  background: var(--accent-soft);
  color: #0b594c;
  text-transform: capitalize;
}

.session-meta {
  display: flex;
  margin: 14px 0 0;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.session-meta > div {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 5px;
}

.session-meta dt {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.session-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.provider-badge {
  padding: 3px 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-transform: capitalize;
}

.diagnostic-list {
  display: flex;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 7px;
}

.diagnostic-badge {
  padding: 4px 8px;
  border: 1px solid #d8b366;
  background: var(--warning-soft);
  color: #724906;
}

.subagent-group {
  margin-top: 18px;
  padding: 14px 0 0 18px;
  border-top: 1px solid var(--border);
  border-left: 2px solid var(--accent-soft);
}

.subagent-label {
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subagent-list {
  display: grid;
  gap: 8px;
}

.subagent-list .session-row {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fbfcfb;
}

.device-empty {
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .auth-main {
    gap: 40px;
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .page-heading {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 700px) {
  .public-header {
    padding: 14px 16px;
  }

  .public-header > p {
    display: none;
  }

  .auth-main {
    width: 100%;
    min-height: auto;
    padding: 28px 16px 48px;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 28px;
  }

  .auth-intro {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-subtle);
  }

  .auth-intro h1 {
    font-size: clamp(30px, 10vw, 42px);
  }

  .auth-intro > p:not(.eyebrow) {
    font-size: 16px;
  }

  .auth-card {
    width: 100%;
  }

  .header-inner,
  .dashboard-main {
    width: min(100% - 32px, var(--content));
  }

  .connection-state {
    padding: 5px 8px;
  }

  .summary-strip {
    width: 100%;
  }

  .summary-strip > div {
    min-width: 0;
    flex: 1 1 0;
    padding: 10px 12px;
  }

  .filters {
    margin-right: -16px;
    margin-left: -16px;
    padding: 18px 16px;
  }
}

@media (max-width: 520px) {
  .boot-shell {
    padding: 16px;
  }

  .app-header {
    position: static;
  }

  .header-inner {
    min-height: 64px;
  }

  .header-inner .brand-lockup > span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .header-actions {
    gap: 6px;
  }

  .connection-state {
    max-width: 152px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .secondary-button {
    padding: 9px 10px;
  }

  .dashboard-main {
    padding-top: 28px;
  }

  .summary-strip dt {
    font-size: 10px;
  }

  .summary-strip dd {
    font-size: 18px;
  }

  .filter-heading {
    align-items: center;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .search-field {
    grid-column: auto;
  }

  .device-heading,
  .session-heading {
    align-items: start;
    flex-direction: column;
  }

  .device-heading,
  .session-row {
    padding: 16px;
  }

  .status-badge {
    align-self: flex-start;
  }

  .session-meta {
    display: grid;
    grid-template-columns: 1fr;
  }

  .subagent-group {
    padding-left: 10px;
  }
}

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