:root {
  color-scheme: light;
  --bg: #e8f7f8;
  --panel: rgba(255, 255, 255, 0.68);
  --panel-strong: rgba(255, 255, 255, 0.82);
  --text: #162123;
  --ink: #101617;
  --muted: #587174;
  --line: rgba(92, 126, 132, 0.32);
  --line-strong: rgba(64, 98, 104, 0.48);
  --green: #0d7a5f;
  --green-strong: #075f4a;
  --red: #b3261e;
  --amber: #a76812;
  --cyan: #0c8494;
  --shadow: 0 18px 42px rgba(41, 71, 78, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.74), rgba(202, 240, 244, 0.78)),
    repeating-linear-gradient(90deg, rgba(12, 132, 148, 0.08) 0 1px, transparent 1px 54px),
    repeating-linear-gradient(0deg, rgba(13, 122, 95, 0.05) 0 1px, transparent 1px 42px),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
}

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

button,
input,
select,
.metric,
.quality-block,
.panel,
.chart-block,
  .profile-band,
  .identity-band,
  .status-band,
.twin-bed-wrap,
.twin-side,
.dialog {
  border-radius: 8px;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

button:active {
  transform: translateY(1px);
}

button.primary,
.tab-button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

button.danger {
  background: var(--red);
  color: #ffffff;
  border-color: var(--red);
}

button:disabled {
  opacity: 0.58;
}

.shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(232, 247, 248, 0.94), rgba(198, 239, 242, 0.92)),
    repeating-linear-gradient(90deg, rgba(12, 132, 148, 0.08) 0 1px, transparent 1px 52px);
}

.auth-screen[hidden] {
  display: none;
}

.auth-panel {
  width: min(520px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-panel h1 {
  margin-bottom: 0;
  font-size: 26px;
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-switch button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.tab-button {
  min-height: 42px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
}

.tab-panel {
  display: none;
  min-height: 0;
  height: 100%;
}

.tab-panel.active {
  display: grid;
  gap: 10px;
}

body.keyboard-open .dialog-backdrop {
  place-items: start center;
  padding-bottom: 182px;
  padding-top: 10px;
}

body.keyboard-open[data-keyboard-layout="number"] .dialog-backdrop,
body.keyboard-open[data-keyboard-layout="ip"] .dialog-backdrop {
  padding-bottom: 166px;
}

.eyebrow,
.muted {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 28px;
}

h2 {
  margin-bottom: 4px;
  font-size: 19px;
}

.status-band,
.metric,
.quality-block,
.panel,
.chart-block,
  .profile-band,
  .identity-band,
  .twin-bed-wrap,
.twin-side,
.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.status-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 16px;
  align-items: center;
  padding: 16px;
}

.status-band p {
  margin-bottom: 5px;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

#progress-label {
  font-size: 30px;
  font-weight: 800;
  text-align: right;
}

.progress-bar {
  width: 100%;
  height: 18px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--cyan));
  transition: width 180ms ease;
}

.metrics-grid,
.quality-grid,
.control-grid,
.panel-actions,
.step-row,
.jog-grid,
.calc-grid,
.chart-grid,
.profile-grid,
.network-grid,
.wifi-picker,
.prompt-grid,
form,
.file-row,
.voice-row,
.dialog-actions,
.twin-readouts {
  display: grid;
  gap: 10px;
}

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

.metric {
  min-width: 0;
  min-height: 82px;
  padding: 12px;
  text-align: left;
}

.metric-button {
  display: grid;
  align-content: start;
  gap: 4px;
}

.metric-button small {
  color: var(--cyan);
  font-weight: 700;
}

.metric span,
.quality-block span,
.chart-block span,
.z-card span {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.metric strong,
.quality-block strong {
  display: block;
  font-size: 21px;
  overflow-wrap: anywhere;
}

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

.quality-block,
.profile-band {
  padding: 12px;
}

.identity-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  border-radius: 8px;
}

.identity-band h2 {
  margin: 0 0 4px;
}

.key-text {
  margin: 0;
  font-weight: 800;
  color: var(--green-strong);
  word-break: break-word;
}

.identity-actions {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px;
}

.quality-block p,
.advisor-note {
  margin: 0;
  color: var(--muted);
}

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

.control-panel {
  display: none;
}

.control-panel.active {
  display: grid;
  gap: 10px;
}

.control-dialog {
  width: min(760px, 100%);
}

.panel-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.step-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.step-row button.active {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.jog-grid {
  grid-template-columns: 54px repeat(2, minmax(0, 1fr));
  align-items: center;
}

.jog-grid span,
.calc-grid label span {
  color: var(--muted);
  font-weight: 700;
}

.calc-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) 130px;
  align-items: end;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 42px;
}

.twin-controls {
  display: grid;
  grid-template-columns: repeat(3, 104px);
  gap: 8px;
}

.twin-controls button {
  min-height: 40px;
}

.twin-controls button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.toolbar {
  display: grid;
  grid-template-columns: auto 140px auto;
  gap: 8px;
  align-items: center;
}

.toolbar label {
  color: var(--muted);
  font-weight: 700;
}

.chart-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  min-height: 0;
}

.chart-block {
  min-width: 0;
  min-height: 0;
  padding: 10px;
  cursor: zoom-in;
}

.chart-block div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
}

.chart-block strong {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.chart-block.expanded {
  position: fixed;
  inset: 18px;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 18px;
  cursor: zoom-out;
}

.chart-block.expanded canvas {
  height: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: 100px;
  border: 1px solid rgba(92, 126, 132, 0.24);
  border-radius: 8px;
  background: rgba(250, 254, 255, 0.88);
}

.full-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
}

[data-tab-panel="ai"] .full-panel {
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto;
}

form,
.file-row {
  grid-template-columns: minmax(0, 1fr) 150px;
  align-items: center;
}

#chat-form {
  grid-template-columns: minmax(0, 1fr) 128px 118px;
}

.voice-row.compact {
  grid-template-columns: 76px 76px;
}

input,
select,
textarea {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
}

textarea {
  min-height: 58px;
  padding: 9px 12px;
  resize: none;
}

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

.prompt-grid button {
  min-height: 40px;
}

.model-maker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 8px 10px;
  align-items: end;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.model-maker label {
  color: var(--muted);
  font-weight: 700;
}

.model-maker > label,
.model-maker textarea,
.model-maker .muted {
  grid-column: 1 / 2;
}

.model-actions {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.model-actions button {
  grid-column: 1 / -1;
}

.chat-log {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 254, 255, 0.78);
  padding: 8px;
}

.msg {
  margin: 0 0 7px;
  padding: 7px 9px;
  border-left: 4px solid var(--line);
  overflow-wrap: anywhere;
  background: rgba(255, 255, 255, 0.46);
}

.msg.user {
  border-color: var(--amber);
}

.msg.assistant {
  border-color: var(--green);
}

.touch-keyboard {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 20px;
  z-index: 90;
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 4px;
  max-height: 150px;
  padding: 7px;
  overflow: hidden;
  background: rgba(232, 247, 248, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 10px 34px rgba(16, 28, 31, 0.28);
  backdrop-filter: blur(16px);
}

.touch-keyboard[hidden] {
  display: none;
}

.touch-keyboard.number,
.touch-keyboard.ip {
  left: auto;
  width: min(340px, calc(100vw - 20px));
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-height: 144px;
}

.touch-keyboard button {
  min-height: 25px;
  padding: 0 4px;
  font-size: 12px;
}

.touch-keyboard:not(.number):not(.ip) button {
  grid-column: span 2;
}

.touch-keyboard .key-spacer {
  min-width: 0;
}

.touch-keyboard .key-spacer.half {
  grid-column: span 1;
}

.touch-keyboard .key-spacer.z-offset {
  grid-column: span 4;
}

.touch-keyboard:not(.number):not(.ip) .narrow {
  grid-column: span 1;
}

.touch-keyboard:not(.number):not(.ip) .wide3 {
  grid-column: span 3;
}

.touch-keyboard .wide {
  grid-column: span 2;
}

.touch-keyboard .space {
  grid-column: span 2;
}

.touch-keyboard .close-key {
  background: var(--red);
  color: #ffffff;
  border-color: var(--red);
}

.touch-keyboard button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.profile-band {
  display: grid;
  grid-template-columns: minmax(0, 0.62fr) minmax(0, 1.55fr);
  gap: 8px;
  align-items: center;
}

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

.profile-grid span {
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(92, 126, 132, 0.2);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

[data-tab-panel="system"].active {
  grid-template-rows: 44px minmax(0, 1fr);
}

.system-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.system-tabs button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.system-page {
  display: none;
  min-height: 0;
}

.system-page.active {
  display: grid;
  gap: 10px;
}

.system-page[data-system-panel="printer"].active {
  grid-template-rows: auto auto;
  align-content: start;
}

.system-page[data-system-panel="network"].active {
  grid-template-rows: minmax(0, 1fr);
}

.network-panel {
  display: grid;
  grid-template-rows: auto minmax(68px, 1fr) auto auto;
  gap: 8px;
  min-height: 0;
  padding: 10px;
}

.network-actions {
  display: grid;
  grid-template-columns: repeat(2, 120px);
  gap: 8px;
}

.network-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 140px;
  align-items: end;
  min-height: 0;
}

.wifi-picker {
  grid-auto-flow: column;
  grid-auto-columns: minmax(150px, 1fr);
  overflow: hidden;
}

.wifi-picker button {
  min-width: 0;
  min-height: 56px;
  display: grid;
  align-content: center;
  text-align: left;
  padding: 8px 10px;
}

.wifi-picker button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.wifi-picker strong,
.wifi-picker span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wifi-picker span {
  font-size: 13px;
  opacity: 0.82;
}

.network-grid label {
  min-width: 0;
}

.network-grid label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-weight: 700;
}

.advanced-network {
  min-height: 0;
}

.advanced-network summary {
  min-height: 38px;
  display: grid;
  align-items: center;
  padding: 0 10px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.advanced-grid label {
  min-width: 0;
}

.advanced-grid label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-weight: 700;
}

.check-line {
  min-height: 44px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.check-line input {
  width: 20px;
  min-height: 20px;
  margin: 0;
}

.twin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 10px;
  min-height: 0;
}

.twin-bed-wrap {
  min-width: 0;
  min-height: 0;
  padding: 12px;
}

#twin-bed {
  height: 100%;
}

.twin-side {
  display: grid;
  grid-template-rows: 78px minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  padding: 10px;
}

.z-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 4px 10px;
  min-height: 0;
  height: 100%;
}

.z-card span,
.z-card strong {
  grid-column: 1 / 2;
}

.z-card strong {
  align-self: end;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.z-gauge {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  position: relative;
  width: 30px;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.z-gauge i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(0deg, var(--green), var(--cyan));
}

.twin-readouts {
  grid-template-columns: 1fr;
  align-content: start;
  gap: 4px;
  min-height: 0;
}

.twin-readouts span {
  min-height: 26px;
  padding: 4px 7px;
  border: 1px solid rgba(92, 126, 132, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 28, 31, 0.34);
  backdrop-filter: blur(8px);
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog {
  width: min(640px, 100%);
  padding: 16px;
}

#heat-target {
  min-height: 68px;
  text-align: center;
  font-size: 30px;
  font-weight: 800;
}

.heat-stepper,
.heat-presets {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.heat-stepper {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.heat-stepper button {
  min-height: 70px;
  font-size: 24px;
}

.heat-presets {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.heat-presets button {
  min-height: 52px;
}

.heat-help {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.field-label {
  display: block;
  margin: 8px 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.dialog-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0 10px;
}

@media (max-width: 820px) {
  body {
    font-size: 15px;
  }

  .shell {
    grid-template-rows: 48px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .tabbar,
  .metrics-grid,
  .control-grid,
  .panel-actions,
  .step-row,
  .chart-grid {
    gap: 6px;
  }

  .tab-button {
    min-height: 40px;
    font-size: 13px;
    padding: 0 4px;
  }

  .status-band {
    grid-template-columns: minmax(0, 1fr) 178px;
    padding: 12px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 17px;
  }

  .metric,
  .quality-block,
  .panel,
  .profile-band {
    padding: 10px;
  }

  .metric strong,
  .quality-block strong {
    font-size: 18px;
  }

  .metric {
    min-height: 76px;
  }

  .chart-block {
    padding: 8px;
  }

  canvas {
    height: 86px;
  }

  .twin-layout {
    grid-template-columns: minmax(0, 1fr) 190px;
  }

  .twin-side,
  .twin-bed-wrap {
    padding: 10px;
  }

  .twin-readouts span {
    padding: 7px;
  }

  .touch-keyboard button {
    min-height: 30px;
    font-size: 13px;
  }

  .network-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 120px;
  }

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

  .wifi-picker {
    grid-auto-columns: minmax(124px, 1fr);
  }

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

  .network-actions {
    grid-template-columns: repeat(2, 102px);
  }

  .heat-stepper button {
    min-height: 62px;
  }
}

@media (max-width: 620px) {
  .tabbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .shell {
    grid-template-rows: 92px minmax(0, 1fr);
  }

  .status-band,
  .profile-band,
  .twin-layout {
    grid-template-columns: 1fr;
  }

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

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

  .dialog-actions,
  .heat-presets,
  .panel-actions,
  .step-row,
  .jog-grid,
  .calc-grid,
  .model-maker,
  .model-actions,
  .network-grid,
  .advanced-grid,
  .wifi-picker,
  #chat-form {
    grid-template-columns: 1fr;
  }

  .wifi-picker {
    grid-auto-flow: row;
    grid-auto-columns: auto;
  }

  .model-maker > label,
  .model-maker textarea,
  .model-maker .muted,
  .model-actions {
    grid-column: 1 / -1;
  }

  .model-actions {
    grid-row: auto;
  }

  .network-actions {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .twin-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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