:root {
  color-scheme: dark;
  --bg: #12161a;
  --card: #1c2329;
  --text: #edf1f4;
  --muted: #8b97a3;
  --accent: #3d9cf0;
  --ok: #3ecf8e;
  --warn: #e6b35c;
  --danger: #e25b5b;
  --line: #2a333b;
  --radius: 16px;
  font-family: "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: radial-gradient(120% 80% at 50% -10%, #243040 0%, var(--bg) 55%);
  color: var(--text);
}

body {
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  transition: background-color 0.35s ease;
}

body.has-fixed-bar {
  padding-top: calc(var(--live-bar-h, 3rem) + 12px);
}

body.logs-open {
  padding-bottom: calc(var(--log-drawer-h, 220px) + env(safe-area-inset-bottom));
}

.live-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.5rem;
  padding-top: max(0.22rem, env(safe-area-inset-top));
  background: color-mix(in srgb, #12161a 88%, black);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 0.65rem;
}

.live-bar .header-online {
  margin-left: 0;
  font-size: 0.6rem;
  padding: 0.08rem 0.38rem;
  flex-shrink: 0;
}

.live-bar .logs-btn {
  margin-left: 0;
  padding: 0.12rem 0.4rem;
  font-size: 0.65rem;
  min-height: 0;
  flex-shrink: 0;
}

.live-bar .tx-chip {
  margin-left: auto;
}

.live-bar[hidden] { display: none !important; }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a4550;
  flex-shrink: 0;
  box-shadow: none;
}

.live-dot.sse-off {
  background: #6b3030;
}

.live-dot.rx {
  animation: link-rx 0.4s ease-out;
}

@keyframes link-rx {
  0%, 100% {
    background: #3a4550;
    box-shadow: none;
    transform: scale(1);
  }
  40% {
    background: #5cff9a;
    box-shadow: 0 0 10px #3ecf8e, 0 0 16px rgba(62, 207, 142, 0.5);
    transform: scale(1.35);
  }
}

.live-dot.tx {
  background: #3a4550;
}

.live-dot.tx-blink {
  animation: link-tx 0.4s ease-out;
}

@keyframes link-tx {
  0%, 100% {
    background: #3a4550;
    box-shadow: none;
    transform: scale(1);
  }
  40% {
    background: #f0b35c;
    box-shadow: 0 0 10px #e6b35c, 0 0 16px rgba(230, 179, 92, 0.5);
    transform: scale(1.35);
  }
}

.tx-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
}

.tx-chip strong { color: var(--text); font-weight: 600; }

.live-bar-text {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-bar-text strong { color: var(--text); font-weight: 600; }

.btn.edit-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.grid .cell.hidden-field { display: none; }

.grid .cell.field-masked {
  opacity: 0.62;
  outline: 1px dashed color-mix(in srgb, var(--danger) 55%, transparent);
  border-radius: 10px;
  padding: 0.15rem;
}

.grid .cell.field-masked dt {
  color: #ffb4b4;
}

.edit-hint .btn.ghost {
  display: block;
  width: 100%;
  margin-top: 0.45rem;
  min-height: 36px;
  font-size: 0.82rem;
}

.grid .cell.edit-mode dt {
  padding-right: 2rem;
}

.field-vis {
  appearance: none;
  border: 1px solid var(--line);
  background: #27313a;
  color: var(--muted);
  border-radius: 8px;
  min-width: 28px;
  min-height: 28px;
  padding: 0 0.35rem;
  font-size: 0.75rem;
  line-height: 1;
  flex-shrink: 0;
}

.field-vis.off {
  background: #3a2424;
  color: #ffb4b4;
  border-color: #5a3030;
}

.edit-hint {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: #b8daf8;
  font-size: 0.78rem;
}

.screen {
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  overflow-x: clip;
}

h1 { font-size: 1.35rem; margin: 0.2rem 0 0.4rem; font-weight: 650; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin: 1.4rem 0 0.35rem; }

.badge {
  display: inline-block;
  margin: 0;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #5a3b14;
  color: #ffd39a;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.muted { color: var(--muted); margin: 0.25rem 0 1rem; }
.tiny { font-size: 0.78rem; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 0.75rem;
}

.top-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.top-title-row h1 {
  margin: 0;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.view-opts {
  margin: 0 0 1rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  overflow: hidden;
}

.view-opts > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 0.85rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  user-select: none;
}

.view-opts > summary::-webkit-details-marker { display: none; }
.view-opts > summary::after {
  content: "▾";
  float: right;
  opacity: 0.7;
}
.view-opts[open] > summary::after { content: "▴"; }

.view-opts-body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0 0.85rem 0.85rem;
  border-top: 1px solid var(--line);
}

.chk {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.25;
  user-select: none;
}

.chk.num {
  justify-content: space-between;
  gap: 0.75rem;
}

.chk.num input[type="number"] {
  width: 4.5rem;
  margin: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #151a1f;
  color: var(--text);
  text-align: center;
}

.opts-hint { margin: 0; }

.chk input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.grid .cell.changed dd {
  border-radius: 8px;
  padding: 0.15rem 0.35rem;
  margin-left: -0.35rem;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn) 55%, transparent);
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  color: #ffe7b0;
}

.grid .cell.changed.flash dd {
  animation: flash-change 0.9s ease;
}

@keyframes flash-change {
  0% {
    background: color-mix(in srgb, var(--warn) 55%, transparent);
    transform: scale(1.02);
  }
  100% {
    background: color-mix(in srgb, var(--warn) 18%, transparent);
    transform: scale(1);
  }
}

label { display: block; margin-bottom: 0.35rem; color: var(--muted); font-size: 0.9rem; }

input[type="password"] {
  width: 100%;
  font-size: 1.1rem;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  margin-bottom: 0.9rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 0.95rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: #2a343d;
  min-height: 52px;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.98); opacity: 0.92; }
.btn:disabled { opacity: 0.45; }

.btn.primary {
  width: 100%;
  background: linear-gradient(180deg, #4aa3f5, #2f7fd0);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  min-height: 40px;
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
}

.btn.action { background: #27313a; }
.btn.action.danger { background: #4a2428; color: #ffd0d0; }

.card {
  background: color-mix(in srgb, var(--card) 92%, black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.85rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #2b3540;
  font-size: 0.85rem;
  font-weight: 600;
}

.pill.on { background: #1d3d30; color: var(--ok); }
.pill.off { background: #3a2a2a; color: #ffb4b4; }
.pill.lock0 { background: #1d3d30; color: var(--ok); }
.pill.lock1 { background: #3d3420; color: var(--warn); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.65rem 0.75rem;
  margin: 0;
  width: 100%;
  max-width: 100%;
}

.grid dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
}

.grid .field-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.25;
}

.grid .field-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.2rem;
}

.grid dd {
  margin: 0.1rem 0 0;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.grid .empty dd { color: #5c6772; }

.grid .cell {
  position: relative;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.note-btn {
  appearance: none;
  border: 0;
  background: #313b45;
  color: #9eb0c0;
  border-radius: 8px;
  min-width: 28px;
  min-height: 28px;
  padding: 0 0.35rem;
  font-size: 0.85rem;
  line-height: 1;
}
.note-btn.has { background: #3d4a2a; color: #d7f0a8; }
.note-btn.on-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
}
.note-preview {
  display: block;
  width: 100%;
  margin: 0.15rem 0 0;
  color: #c9b27a;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  max-height: calc(1.25em * 2);
}
.note-preview.under-btn {
  grid-column: 1 / -1;
  margin: -0.35rem 0 0.2rem;
  padding: 0 0.2rem;
}
.note-preview.in-btn {
  display: -webkit-box;
  margin-top: 0.35rem;
  color: #c9b27a;
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: pre-wrap;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.trust {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 6px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  line-height: 1;
  flex: 0 0 auto;
}
.trust.ok { background: #1d3d30; color: #8fd9b0; }
.trust.partial { background: #3d3420; color: #e6c97a; }
.trust.conflict { background: #3d2433; color: #e6a0c8; }
.trust.suspect { background: #3d2a18; color: #f0a868; }
.trust.broken { background: #3a2a2a; color: #ffb4b4; }
.trust.none { background: #2a3138; color: #6b7884; }

.status-picker-label { margin: 0.6rem 0 0.35rem; }
.status-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.status-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  cursor: pointer;
}
.status-opt input { margin: 0; }

.trust-summary { margin: 0.15rem 0 0.5rem; }
.view-opts-body select {
  margin-left: 0.35rem;
  background: #1a2229;
  color: var(--text);
  border: 1px solid #313b45;
  border-radius: 8px;
  padding: 0.2rem 0.4rem;
}

.btn.action {
  position: relative;
  padding-right: 4.4rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  text-align: left;
  border-left: 3px solid #3a4550;
}
.btn.action.trust-ok { border-left-color: #4a9e75; }
.btn.action.trust-partial { border-left-color: #c9a84a; }
.btn.action.trust-conflict { border-left-color: #c97aa8; }
.btn.action.trust-suspect { border-left-color: #d4894a; }
.btn.action.trust-broken { border-left-color: #d46a6a; }
.btn.action.trust-none { border-left-color: #3a4550; }

.btn.action .action-label {
  display: block;
  width: 100%;
  padding-right: 0.2rem;
}

.btn.action .action-tools {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn.action .action-tools .note-btn.on-btn {
  position: static;
  top: auto;
  right: auto;
}

.btn.action .action-tools .trust {
  min-width: 1.7rem;
  height: 1.35rem;
  font-size: 0.68rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(480px, 100%);
  background: #1c2329;
  border: 1px solid var(--line);
  border-radius: 18px 18px 12px 12px;
  padding: 1rem;
  margin-bottom: env(safe-area-inset-bottom);
}
.modal-card h2 { margin: 0.35rem 0 0.2rem; font-size: 1.1rem; }
.modal-card textarea {
  width: 100%;
  margin-top: 0.7rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #12161a;
  color: var(--text);
  padding: 0.8rem;
  font-size: 1rem;
  resize: vertical;
  min-height: 110px;
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.modal-actions .btn.primary { width: auto; }


.block { margin-top: 0.95rem; }
.block:first-child { margin-top: 0.35rem; }
.block h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #a9b7c4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

#actions {
  display: block;
}

.cmd-group {
  margin-top: 0.9rem;
}

.cmd-group h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #a9b7c4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ac-form h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.ac-form label {
  display: block;
  margin: 0.45rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.ac-form input[type="range"] { width: 100%; }

.ac-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.65rem;
  margin: 0.5rem 0 0.75rem;
}

.ac-grid select {
  width: 100%;
  margin-top: 0.15rem;
  background: #0d1114;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem;
}

.btn.action.danger {
  border-color: color-mix(in srgb, var(--danger) 70%, var(--line));
  color: #ffb4b4;
}

.log {
  margin-top: 1.2rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: #0d1114;
  border: 1px solid var(--line);
  color: #9eb0c0;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

.log.history { max-height: 480px; }
.log.tall { max-height: 160px; margin-top: 0.6rem; }

.log-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: block;
  pointer-events: none;
  background: none;
}

.log-drawer[hidden] { display: none !important; }

.log-drawer-panel {
  pointer-events: auto;
  width: 100%;
  height: var(--log-drawer-h, 220px);
  max-height: 85vh;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  background: #151a1f;
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.3);
  padding-bottom: env(safe-area-inset-bottom);
}

.log-resize-handle {
  flex-shrink: 0;
  height: 14px;
  cursor: ns-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, #151a1f 80%, #2a333b);
  border-bottom: 1px solid var(--line);
}

.log-resize-handle::before {
  content: "";
  width: 36px;
  height: 3px;
  border-radius: 999px;
  background: #4a5560;
}

.log-drawer-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.68rem;
  color: var(--muted);
}

.log-follow-chk {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}

.log-follow-chk input {
  margin: 0;
}

.log-clear-btn {
  padding: 0.15rem 0.45rem;
  font-size: 0.65rem;
  min-height: 0;
}

.catalog-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.72rem;
  color: #8ec8ff;
}

.badge.core {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: #1a3a52;
  color: #8ec8ff;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.field-name .catalog-tag {
  display: block;
  margin-top: 0.12rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.62rem;
  font-weight: 500;
  color: #6f8faa;
  letter-spacing: 0;
}

.log-drawer-body.log {
  margin: 0;
  border: none;
  border-radius: 0;
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

h2.inline {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

details.raw {
  margin-top: 0.9rem;
  color: var(--muted);
  font-size: 0.85rem;
}

details.raw summary {
  cursor: pointer;
  margin-bottom: 0.4rem;
}



#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  background: #243041;
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  max-width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}


/* Critical remote-command confirmation. */
.critical-confirm-card { border: 1px solid color-mix(in srgb, var(--danger) 70%, var(--line)); box-shadow: 0 18px 60px rgba(0,0,0,.55); }
.danger-badge { color: #ffb7b7; }
.critical-command-warning { margin: 1rem 0; padding: .9rem 1rem; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--line)); background: color-mix(in srgb, var(--danger) 14%, var(--card)); color: var(--text); }
.critical-command-warning strong { color: #ffd0d0; }
.critical-command-warning p { margin: .45rem 0 0; line-height: 1.45; }
.critical-confirm-help { margin: .9rem 0 .35rem; color: var(--muted); }
.critical-confirm-phrase { margin: 0 0 .55rem; font-weight: 800; letter-spacing: .08em; color: #ffd0d0; }
.critical-confirm-input { width: 100%; box-sizing: border-box; font-size: 1.05rem; padding: .85rem .95rem; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--line)); background: #151a1f; color: var(--text); }
.btn.danger-confirm { background: #6a292f; color: #ffe1e1; }
