/* Cool Porcelain & Forge Slate + Ember Spark design tokens */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #dce2ea;
  --border-strong: #c5cfd9;
  --ink: #111827;
  --muted: #556275;
  --ember: #e8531e;
  --ember-hover: #cf4413;
  --ember-soft: #fff1eb;
  --ember-border: #f8c6b2;
  --ok: #15803d;
  --ok-soft: #edf9f1;
  --warn: #b45309;
  --warn-soft: #fef6e7;
  --err: #b91c1c;
  --err-soft: #fef0f0;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-plate: 0 1px 2px rgba(15, 23, 42, 0.04);
  --font-sans: "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

input[type="checkbox"] {
  accent-color: var(--ember);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

/* Toast notification */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 90;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.22);
}

.toast.ok {
  background: #14532d;
}

.toast.err {
  background: #991b1b;
}

/* Login View */
.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 392px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow-plate);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.flame-mark {
  display: inline-flex;
  flex-shrink: 0;
}

.login-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
}

.login-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.password-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 2px 6px 2px 12px;
}

.password-wrap:focus-within {
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--ember-soft);
}

.password-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 9px 0;
  outline: none;
}

.ghost-inline {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.ghost-inline:hover {
  color: var(--ink);
  background: var(--surface-subtle);
}

.inline-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--err-soft);
  color: var(--err);
  font-size: 12.5px;
}

/* App Shell */
.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-meta {
  min-width: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.mono-pill {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

.subtle-line {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.mono-muted {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
}

.btn-xs {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--ember);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--ember-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  background: rgba(17, 24, 39, 0.05);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--err);
  border-color: #f3c4c4;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--err-soft);
}

/* Status Pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.status-pill.ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.status-pill.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.status-pill.err {
  color: var(--err);
  background: var(--err-soft);
}

.status-pill.ember {
  color: var(--ember);
  background: var(--ember-soft);
}

.status-pill.neutral {
  color: var(--muted);
  background: #eaeff5;
}

/* Plates */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.plate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-plate);
}

.plate-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.plate-head h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.3;
}

.kicker {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Horizon Signature Instrument */
.horizon-plate {
  padding: 20px 22px 18px;
}

.horizon-top {
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) minmax(300px, 1.35fr);
  gap: 20px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.horizon-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.horizon-counter-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 4px 0 10px;
}

.hero-metric {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.horizon-hint {
  font-size: 13px;
  color: var(--muted);
}

.spark-progress {
  display: block;
  width: 100%;
  height: 8px;
  border: none;
  border-radius: 999px;
  background: #e6ebf1;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}

.spark-progress::-webkit-progress-bar {
  background: #e6ebf1;
  border-radius: 999px;
}

.spark-progress::-webkit-progress-value {
  background: var(--ember);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.spark-progress::-moz-progress-bar {
  background: var(--ember);
  border-radius: 999px;
}

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

.signal-cell {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.signal-label {
  font-size: 11.5px;
  color: var(--muted);
}

.signal-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signal-sub {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 30-Day Ember Matrix */
.matrix-section {
  padding-top: 14px;
}

.matrix-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.ember-matrix {
  display: grid;
  grid-template-columns: repeat(30, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  height: 30px;
}

.day-bar {
  height: 100%;
  border: none;
  padding: 0;
  border-radius: 4px;
  cursor: pointer;
  background: #e3e8ef;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.day-bar:hover,
.day-bar.selected {
  transform: translateY(-2px);
}

.day-bar.ok {
  background: var(--ember);
}

.day-bar.partial {
  background: #f59e0b;
}

.day-bar.failed {
  background: var(--err);
}

.day-bar.unobserved {
  height: 14px;
  background: #e2e7ee;
}

.matrix-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.matrix-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.dot.ok {
  background: var(--ember);
}

.dot.partial {
  background: #f59e0b;
}

.dot.failed {
  background: var(--err);
}

.dot.unobserved {
  background: #d5dce6;
}

.matrix-focus {
  margin-left: auto;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* Main Grid */
.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Target Editor Form */
.target-form {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="number"],
.field input:not([type]),
.field select {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
}

.field input:disabled {
  background: #eef2f6;
  color: var(--muted);
}

.check-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 22px;
  color: var(--ink);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.form-actions.between {
  justify-content: space-between;
  flex-wrap: wrap;
}

/* Target Roster Cards/Rows */
.target-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.target-row.disabled {
  background: var(--surface-subtle);
  opacity: 0.72;
}

.target-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.target-title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.target-name {
  font-weight: 600;
  font-size: 14px;
}

.target-uid {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}

.target-detail {
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}

.target-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* Quick Action Buttons */
.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.action-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: #edf1f6;
}

.action-btn.accent {
  background: var(--ember-soft);
  border-color: var(--ember-border);
}

.action-btn.accent:hover:not(:disabled) {
  background: #ffe4d8;
}

.action-btn strong {
  font-size: 13px;
  color: var(--ink);
}

.action-btn.accent strong {
  color: var(--ember-hover);
}

.action-btn span {
  font-size: 11.5px;
  color: var(--muted);
}

.danger-row {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  justify-content: flex-end;
}

/* Schedule Control */
.callout {
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-bottom: 10px;
}

.callout.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.schedule-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.timer-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.timer-controls input[type="time"] {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Session Renew & Settings */
.renew-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 14px;
}

.code-copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 8px 6px 10px;
  border-radius: var(--radius-sm);
  background: #111827;
  color: #f3f5f8;
}

.code-copy-row code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-x: auto;
}

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

.span-2 {
  grid-column: span 2;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 10px;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

/* Telemetry Tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -4px 0 14px;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--ember);
  border-bottom-color: var(--ember);
}

.jobs-split {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.55fr);
  gap: 12px;
}

.job-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.job-item {
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.job-item.selected {
  border-color: var(--ember);
  background: var(--ember-soft);
}

.job-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.terminal-wrap {
  border: 1px solid #263042;
  border-radius: var(--radius-md);
  background: #111827;
  color: #e5eaf2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.terminal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #1a2333;
  border-bottom: 1px solid #263042;
  font-size: 12px;
}

.terminal-body {
  margin: 0;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.inline-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.inline-select select {
  height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.event-list,
.backup-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.event-row,
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  font-size: 12.5px;
}

.event-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.event-meta {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  word-break: break-all;
}

.empty-state {
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Modal Dialog */
.modal-dialog {
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: transparent;
  max-width: min(420px, calc(100vw - 32px));
  width: 100%;
}

.modal-dialog::backdrop {
  background: rgba(17, 24, 39, 0.48);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
  .horizon-top {
    grid-template-columns: 1fr;
  }

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

  .jobs-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px 12px 32px;
  }

  .topbar {
    flex-wrap: wrap;
  }

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

  .plate {
    padding: 14px;
  }

  .horizon-signals {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .settings-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .target-row {
    grid-template-columns: 1fr;
  }

  .target-actions {
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }

  .timer-row {
    flex-direction: column;
    align-items: stretch;
  }

  .timer-controls {
    justify-content: space-between;
  }

  .ember-matrix {
    gap: 2px;
  }
}

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