:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-alt: #edf4f0;
  --ink: #252525;
  --muted: #66716d;
  --line: #d8e2dc;
  --primary: #0b7a75;
  --primary-dark: #075a56;
  --coral: #c94f47;
  --yellow: #d99b2b;
  --ok: #167647;
  --bad: #a43838;
  --shadow: 0 16px 40px rgb(37 37 37 / 0.08);
  --radius: 8px;
  --tap: 44px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgb(11 122 117 / 0.07), transparent 290px),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button,
label.file-button {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr minmax(240px, 320px);
  grid-template-rows: auto auto 1fr;
  gap: 20px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgb(11 122 117 / 0.24);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.15rem;
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbar-actions,
.control-row,
.panel-title-row,
.band-head,
.log-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  justify-content: flex-end;
}

.network-pill,
.count-pill,
.status-dot {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.network-pill.is-offline,
.status-dot.is-bad {
  border-color: rgb(164 56 56 / 0.28);
  background: rgb(164 56 56 / 0.1);
  color: var(--bad);
}

.status-dot.is-ok {
  border-color: rgb(22 118 71 / 0.26);
  background: rgb(22 118 71 / 0.1);
  color: var(--ok);
}

.view-tabs {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.78);
  box-shadow: var(--shadow);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  gap: 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab-button.is-active {
  background: var(--ink);
  color: #fff;
}

.main {
  grid-column: 1;
  min-width: 0;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 18px;
}

.section-head h1,
.band-head h2,
.tool-panel h2,
.log-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.section-head h1 {
  max-width: 850px;
  font-size: clamp(1.7rem, 4vw, 3.2rem);
  line-height: 1.02;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.work-grid,
.device-grid {
  display: grid;
  gap: 14px;
}

.work-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
}

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

.tool-panel,
.inbox-band,
.event-log {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.86);
  box-shadow: var(--shadow);
}

.tool-panel,
.inbox-band {
  padding: 16px;
}

.tool-panel h2 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.panel-title-row {
  justify-content: space-between;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input {
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  padding: 12px;
  resize: vertical;
}

input:focus,
textarea:focus,
.drop-zone:focus-visible,
button:focus-visible,
.file-button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(11 122 117 / 0.18);
  outline: none;
}

form.tool-panel {
  display: grid;
  gap: 12px;
}

.control-row {
  flex-wrap: wrap;
  margin-top: 4px;
}

.primary-button,
.secondary-button,
.danger-button,
.quiet-button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  gap: 8px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 800;
  text-decoration: none;
  user-select: none;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button,
.file-button,
.quiet-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  background: rgb(201 79 71 / 0.12);
  color: var(--bad);
}

.quiet-button {
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button.compact {
  width: 34px;
  height: 34px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone {
  display: grid;
  min-height: 148px;
  margin-top: 14px;
  padding: 18px;
  place-items: center;
  border: 1px dashed rgb(11 122 117 / 0.5);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  text-align: center;
}

.drop-zone strong {
  color: var(--ink);
}

.drop-zone.is-over {
  border-color: var(--primary);
  background: rgb(11 122 117 / 0.12);
}

.inbox-band {
  margin-top: 14px;
}

.band-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.entry-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.entry-card {
  display: grid;
  min-height: 168px;
  align-content: start;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.entry-card.empty {
  grid-column: 1 / -1;
  min-height: 120px;
  place-items: center;
  color: var(--muted);
}

.entry-header {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.entry-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  background: rgb(244 185 66 / 0.22);
  color: #7b5310;
}

.entry-title {
  overflow-wrap: anywhere;
  font-weight: 800;
  line-height: 1.2;
}

.entry-meta,
.entry-body {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.entry-body {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.entry-card img,
.entry-card video {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-alt);
}

.entry-card audio {
  width: 100%;
}

.entry-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.entry-actions a,
.entry-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.camera-stage {
  position: relative;
  display: grid;
  overflow: hidden;
  min-height: 320px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: #121716;
}

.camera-stage video,
.camera-stage img,
.empty-stage {
  grid-area: 1 / 1;
}

.camera-stage video,
.camera-stage img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.empty-stage {
  display: grid;
  place-items: center;
  color: rgb(255 255 255 / 0.72);
  font-weight: 800;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 12px 0 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.segmented-control button {
  min-height: 36px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented-control button.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 12px rgb(37 37 37 / 0.08);
}

.meter {
  overflow: hidden;
  height: 18px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--surface-alt);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--yellow), var(--coral));
  transition: width 90ms linear;
}

.readout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.readout-grid div {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.readout-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.readout-grid dd {
  margin: 7px 0 0;
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 800;
}

.narrow-panel {
  max-width: 680px;
}

.inline-input {
  grid-template-columns: auto minmax(88px, 140px);
  align-items: center;
  justify-content: start;
  margin-bottom: 12px;
}

.capability-list {
  display: grid;
  gap: 9px;
}

.cap-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.86);
}

.cap-row strong,
.cap-row span {
  display: block;
}

.cap-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.cap-row svg {
  width: 20px;
  height: 20px;
}

.cap-row.is-ok svg {
  color: var(--ok);
}

.cap-row.is-bad svg {
  color: var(--bad);
}

.event-log {
  grid-column: 2;
  grid-row: 2 / span 2;
  align-self: start;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

.log-header {
  justify-content: space-between;
  padding: 12px 12px 8px;
}

.log-header h2 {
  font-size: 0.95rem;
}

#log-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 96px);
  margin: 0;
  padding: 0 12px 12px;
  overflow: auto;
  list-style: none;
}

#log-list li {
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

#log-list time {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .view-tabs,
  .main,
  .event-log {
    grid-column: 1;
  }

  .event-log {
    position: static;
    grid-row: auto;
    max-height: 280px;
  }

  #log-list {
    max-height: 210px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    gap: 12px;
    padding-inline: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand small,
  .network-pill {
    font-size: 0.76rem;
  }

  .view-tabs {
    position: sticky;
    z-index: 5;
    top: max(8px, env(safe-area-inset-top));
    gap: 5px;
    padding: 5px;
  }

  .tab-button {
    min-height: 50px;
    gap: 4px;
    padding: 0 4px;
    flex-direction: column;
    font-size: 0.72rem;
  }

  .tab-button svg {
    width: 18px;
    height: 18px;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
    margin-top: 6px;
  }

  .section-head h1 {
    font-size: 1.85rem;
  }

  .work-grid,
  .device-grid,
  .entry-list {
    grid-template-columns: 1fr;
  }

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

  .camera-stage {
    min-height: 260px;
  }

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

  .cap-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .cap-row .status-dot {
    grid-column: 2;
    justify-self: start;
  }
}
