:root {
  --lime-500: #b1e346;
  --lime-700: #5c7e13;
  --ink-950: #12140f;
  --ink-800: #282c24;
  --paper-50: #f6f8f1;
  --surface: #ffffff;
  --surface-soft: #f0f3ea;
  --stage: #0d0f0c;
  --line: #e2e7dc;
  --line-dark: #343a30;
  --muted: #697065;
  --warning: #a76408;
  --danger: #b42318;
  color: var(--ink-950);
  background: var(--paper-50);
  font-family:
    Inter,
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper-50);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--paper-50);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  color: inherit;
}

button {
  cursor: pointer;
  min-height: 2.5rem;
  padding: 0.58rem 0.75rem;
  font-weight: 720;
}

button:hover:not(:disabled) {
  border-color: #bdc7b4;
  background: var(--surface-soft);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--lime-500);
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.68rem 0.75rem;
}

textarea {
  resize: vertical;
}

.session-bar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(12rem, 1fr) auto auto;
  align-items: center;
  min-height: 4.75rem;
  padding: 0.8rem clamp(1rem, 2vw, 1.75rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: block;
  padding-right: 1.5rem;
  border-right: 1px solid var(--line);
}

.brand img {
  display: block;
}

.session-identity {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  padding: 0 1.5rem;
}

.session-identity__label,
.metric small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.session-identity strong {
  overflow: hidden;
  font-size: 0.95rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-metrics {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.metric {
  display: grid;
  gap: 0.05rem;
  min-width: 5.3rem;
  padding: 0 0.8rem;
  border-left: 1px solid var(--line);
}

.metric strong {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.state-pill,
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d4e7aa;
  border-radius: 999px;
  background: #f1f9df;
  color: var(--lime-700);
  font-size: 0.72rem;
  font-weight: 800;
}

.state-pill {
  min-height: 1.9rem;
  padding: 0.3rem 0.65rem;
}

.state-pill[data-state='error'] {
  border-color: #f2c3bd;
  background: #fff1ef;
  color: var(--danger);
}

.state-pill[data-state='connecting'] {
  border-color: #ead7bd;
  background: #fff8e8;
  color: var(--warning);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(13rem, 17rem) minmax(30rem, 1fr) minmax(20rem, 25rem);
  min-height: calc(100vh - 4.75rem);
  overflow: hidden;
}

.fleet-panel,
.tools-panel,
.viewer {
  min-width: 0;
  background: var(--surface);
}

.fleet-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.panel-heading,
.viewer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-heading {
  min-height: 5.3rem;
  padding: 1.15rem;
  border-bottom: 1px solid var(--line);
}

.panel-heading h1,
.viewer__head h2,
.tool-heading h2 {
  margin: 0.2rem 0 0;
}

.panel-heading h1 {
  font-size: 1.05rem;
}

.count-badge {
  min-width: 1.8rem;
  min-height: 1.8rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.device-picker {
  display: none;
}

.device-list {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  padding: 0.75rem;
}

.device-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.7rem;
  min-height: 3.8rem;
  padding: 0.7rem;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.device-item:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--paper-50);
}

.device-item.is-selected {
  border-color: #d5e7ad;
  background: #f2f9e3;
}

.device-avatar {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border-radius: 0.5rem;
  background: var(--ink-950);
  color: var(--lime-500);
  font-size: 0.74rem;
  font-weight: 850;
}

.device-copy {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.device-copy strong,
.device-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-copy strong {
  font-size: 0.83rem;
}

.device-copy span {
  color: var(--muted);
  font-size: 0.67rem;
}

.fleet-note {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.fleet-note p {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.45;
}

.fleet-note strong {
  color: var(--ink-950);
}

.secure-dot {
  width: 0.55rem;
  height: 0.55rem;
  margin-top: 0.25rem;
  border-radius: 50%;
  background: var(--lime-500);
  box-shadow: 0 0 0 0.22rem #edf7da;
}

.viewer {
  display: grid;
  grid-template-rows: auto minmax(28rem, 1fr) auto auto;
  min-height: calc(100vh - 4.75rem);
  background: var(--paper-50);
}

.viewer__head {
  min-height: 5.3rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.viewer__head h2 {
  font-size: 1.05rem;
}

.viewer__head > p {
  max-width: 22rem;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screen-stage {
  position: relative;
  display: grid;
  min-height: 28rem;
  place-items: center;
  overflow: hidden;
  background: var(--stage);
  touch-action: none;
}

.screen-stage::before {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
  content: '';
  pointer-events: none;
}

.screen-stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: calc(100vh - 16.5rem);
  object-fit: contain;
  user-select: none;
}

.screen-overlay {
  position: absolute;
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  width: min(22rem, calc(100% - 2rem));
  padding: 1.1rem;
  border: 1px solid var(--line-dark);
  border-radius: 0.75rem;
  background: #171a15;
  color: var(--surface);
  text-align: center;
}

.screen-overlay__pulse {
  width: 0.65rem;
  height: 0.65rem;
  margin-bottom: 0.2rem;
  border-radius: 50%;
  background: var(--lime-500);
}

.screen-overlay span:last-child {
  color: #b6bdb0;
  font-size: 0.78rem;
}

.screen-stage[data-state='live'] .screen-overlay {
  display: none;
}

.command-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 4.6rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.button {
  min-height: 2.55rem;
}

.button--primary {
  border-color: #9ecb3e;
  background: var(--lime-500);
  color: var(--ink-950);
}

.button--primary:hover:not(:disabled) {
  border-color: #88b22f;
  background: #a7d63f;
}

.button--dark {
  border-color: var(--ink-950);
  background: var(--ink-950);
  color: var(--surface);
}

.button--dark:hover:not(:disabled) {
  border-color: var(--ink-800);
  background: var(--ink-800);
}

.button--quiet {
  background: var(--surface);
}

.button--warning {
  border-color: #d79943;
  background: #fff5e3;
  color: #7b4500;
}

.gesture-modes {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.gesture-modes legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.gesture-mode {
  min-width: 0;
  min-height: 2.35rem;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.gesture-mode:first-of-type {
  border-radius: 0.5rem 0 0 0.5rem;
}

.gesture-mode:last-of-type {
  border-radius: 0 0.5rem 0.5rem 0;
}

.gesture-mode + .gesture-mode {
  margin-left: -1px;
}

.gesture-mode.is-selected {
  position: relative;
  z-index: 1;
  border-color: #9ecb3e;
  background: #edf7d8;
  color: var(--lime-700);
}

.action-status {
  max-width: 10rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-status[data-state='error'] {
  color: var(--danger);
}

.activity-drawer {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.activity-drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.8rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  list-style: none;
}

.activity-drawer summary::-webkit-details-marker {
  display: none;
}

.activity-drawer ol {
  max-height: 9rem;
  margin: 0;
  padding: 0 1.2rem 0.9rem 2.6rem;
  overflow: auto;
  color: var(--muted);
  font-size: 0.72rem;
}

.activity-drawer li + li {
  margin-top: 0.4rem;
}

.tools-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
}

.tool-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: 5.3rem;
  padding: 0 0.45rem;
  border-bottom: 1px solid var(--line);
}

.tool-tab {
  position: relative;
  min-width: 0;
  min-height: 5.3rem;
  padding: 0.65rem 0.3rem;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.67rem;
  text-overflow: ellipsis;
}

.tool-tab::after {
  position: absolute;
  right: 0.55rem;
  bottom: -1px;
  left: 0.55rem;
  height: 3px;
  background: transparent;
  content: '';
}

.tool-tab:hover:not(:disabled) {
  border: 0;
  background: var(--paper-50);
}

.tool-tab.is-selected {
  color: var(--ink-950);
}

.tool-tab.is-selected::after {
  background: var(--lime-500);
}

.tool-panel {
  min-height: 0;
  padding: 1.15rem;
  overflow-y: auto;
}

.tool-panel[hidden] {
  display: none;
}

.tool-heading {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.tool-heading h2 {
  font-size: 1.2rem;
}

.tool-heading > p:last-child {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 1rem;
}

.preset-grid button {
  background: var(--paper-50);
  font-size: 0.78rem;
}

.tool-form,
.result-block,
.danger-zone,
.usage-panel {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.tool-form {
  display: grid;
  gap: 0.55rem;
}

.tool-form > label,
.device-picker > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.field-row {
  display: flex;
  gap: 0.45rem;
}

.field-row > :first-child {
  min-width: 0;
  flex: 1;
}

.modifier-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.35rem;
}

.modifier-list label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.modifier-list input {
  width: auto;
}

.result-block__head,
.upload-state__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.result-block__head strong {
  font-size: 0.82rem;
}

.result-block pre,
.result-block output {
  display: block;
  width: 100%;
  min-height: 3.2rem;
  margin: 0.6rem 0 0;
  padding: 0.7rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper-50);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.text-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--lime-700);
  font-size: 0.7rem;
}

.text-button:hover:not(:disabled) {
  border: 0;
  background: transparent;
  text-decoration: underline;
}

.result-block > .text-button {
  margin-top: 0.55rem;
}

.upload-form > p,
.danger-zone > p:not(.eyebrow),
.usage-panel > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.45;
}

.upload-state {
  display: grid;
  gap: 0.45rem;
}

.upload-state[hidden] {
  display: none;
}

.upload-progress {
  height: 0.42rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.upload-progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--lime-500);
}

.upload-state__meta {
  color: var(--muted);
  font-size: 0.68rem;
}

.danger-zone h3 {
  margin: 0.25rem 0 0.35rem;
  font-size: 0.92rem;
}

.danger-zone .field-row {
  margin-top: 0.75rem;
}

.usage-panel summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
}

.usage-panel dl {
  display: grid;
  gap: 0.55rem;
  margin: 0.85rem 0 0.55rem;
}

.usage-panel dl > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.usage-panel dd {
  margin: 0;
  color: var(--ink-950);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.confirm-dialog {
  width: min(28rem, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  box-shadow: 0 1.5rem 4rem rgba(18, 20, 15, 0.22);
}

.confirm-dialog::backdrop {
  background: rgba(18, 20, 15, 0.66);
}

.confirm-dialog form {
  padding: 1.25rem;
}

.confirm-dialog h2 {
  margin: 0.35rem 0 0.6rem;
  font-size: 1.2rem;
}

.confirm-dialog p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

@media (max-width: 1179px) {
  .session-bar {
    grid-template-columns: auto minmax(8rem, 1fr) auto auto;
  }

  .session-metrics .metric:not(.session-budget) {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(29rem, 1fr) minmax(20rem, 23rem);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .fleet-panel {
    position: static;
    grid-row: 1;
    grid-column: 1 / -1;
    width: auto;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
  }

  .fleet-panel .panel-heading,
  .device-list,
  .fleet-note {
    display: none;
  }

  .device-picker {
    display: grid;
    grid-template-columns: auto minmax(12rem, 22rem);
    align-items: center;
    justify-content: start;
    gap: 1rem;
    padding: 0.55rem 1rem;
    background: var(--surface);
  }

  .viewer {
    grid-column: 1;
    grid-row: 2;
    min-height: calc(100vh - 8.65rem);
  }

  .tools-panel {
    grid-column: 2;
    grid-row: 2;
  }
}

@media (max-width: 799px) {
  .session-bar {
    position: sticky;
    top: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.6rem;
    min-height: 4.25rem;
    padding: 0.65rem 0.8rem;
  }

  .brand {
    border: 0;
  }

  .brand img {
    width: 142px;
    height: auto;
  }

  .session-identity,
  .session-metrics {
    display: none;
  }

  .workspace {
    display: block;
    min-height: calc(100vh - 4.25rem);
    overflow: visible;
  }

  .fleet-panel {
    position: static;
    width: auto;
    border-width: 0 0 1px;
    box-shadow: none;
  }

  .device-picker {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .viewer {
    min-height: auto;
    grid-template-rows: auto minmax(28rem, 70vh) auto auto;
  }

  .viewer__head {
    min-height: 4.2rem;
    padding: 0.75rem 0.9rem;
  }

  .viewer__head > p {
    max-width: 45%;
  }

  .screen-stage img {
    max-height: 70vh;
  }

  .command-strip {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .gesture-modes {
    overflow-x: auto;
  }

  .action-status {
    grid-column: 1 / -1;
    max-width: none;
    text-align: left;
  }

  .tools-panel {
    display: grid;
    min-height: 32rem;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .tool-tabs,
  .tool-tab {
    min-height: 3.7rem;
  }
}

@media (max-width: 470px) {
  .viewer {
    grid-template-rows: auto minmax(24rem, 64vh) auto auto;
  }

  .viewer__head > p {
    display: none;
  }

  .command-strip {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .gesture-mode {
    flex: 1 0 auto;
  }

  .preset-grid,
  .modifier-list {
    grid-template-columns: 1fr;
  }
}

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