:root {
  --bg: #071017;
  --panel: #101923;
  --panel-2: #13202b;
  --panel-3: #0d151d;
  --line: #283544;
  --line-soft: #1d2a36;
  --text: #f2f5f8;
  --muted: #9aa6b5;
  --muted-2: #718092;
  --blue: #4a90ff;
  --green: #67e274;
  --amber: #f4a51c;
  --red: #ff665c;
  --radius: 8px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
  --maxw: 1420px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.app {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 20px 28px;
}

.icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
  stroke: currentColor;
  vertical-align: -0.16em;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 46px;
  padding: 0 6px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-wrap,
.top-actions,
.secure-label,
.link,
.refresh-link,
.top-link {
  display: inline-flex;
  align-items: center;
}

.brand-wrap {
  gap: 18px;
}

.brand {
  font-size: 1.52rem;
  font-weight: 760;
  letter-spacing: 0;
}

.secure-label {
  gap: 9px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
  color: var(--green);
  font-size: 0.92rem;
  font-weight: 650;
}

.top-actions {
  gap: 22px;
  color: var(--muted);
}

.link {
  gap: 8px;
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  text-decoration: none;
}

.link:hover {
  color: var(--text);
}

.panel,
.card,
.status-rail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  width: 350px;
  max-width: 100%;
  padding: 22px;
}

.card .btn {
  width: 100%;
  background: var(--blue);
  border-color: transparent;
}

.card h1 {
  margin: 0 0 12px;
  font-size: 1.45rem;
}

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

.status-rail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 0 -20px 14px;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  box-shadow: none;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 70px;
  padding: 16px 22px;
  border-left: 1px solid var(--line);
  color: var(--muted);
}

.rail-item:first-child {
  border-left: 0;
}

.rail-item strong {
  display: block;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 720;
  letter-spacing: 0;
}

.rail-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.rail-icon {
  width: 26px;
  height: 26px;
  stroke-width: 1.8;
}

.rail-item.is-ok strong,
.rail-item.is-ok .rail-icon,
.rail-item.is-secure strong,
.rail-item.is-secure .rail-icon {
  color: var(--green);
}

.rail-item.is-attention strong,
.rail-item.is-attention .rail-icon {
  color: var(--amber);
}

.rail-item.is-danger strong,
.rail-item.is-danger .rail-icon {
  color: var(--red);
}

.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(380px, 0.98fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

h2,
h3 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 1.06rem;
}
h3 {
  font-size: 1.05rem;
}

.panel-kicker {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 690;
}

.lock-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.82fr) minmax(330px, 1.1fr);
  min-height: 352px;
}

.state-core {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.state-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 170px;
  height: 170px;
  margin-bottom: 18px;
  border: 3px solid var(--muted-2);
  border-radius: 999px;
  color: var(--muted);
}

.state-icon {
  display: none;
  width: 58px;
  height: 58px;
  stroke-width: 1.45;
}

.lock-panel.is-locked .state-icon-lock,
.lock-panel.is-error .state-icon-lock {
  display: inline-block;
}
.lock-panel.is-unlocked .state-icon-unlock {
  display: inline-block;
}
.lock-panel.is-busy .state-icon-busy {
  display: inline-block;
}

.lock-panel.is-locked .state-ring {
  border-color: var(--green);
  color: var(--green);
}
.lock-panel.is-unlocked .state-ring {
  border-color: var(--amber);
  color: var(--amber);
}
.lock-panel.is-busy .state-ring {
  border-color: var(--blue);
  color: var(--blue);
}
.lock-panel.is-error .state-ring {
  border-color: var(--red);
  color: var(--red);
}

.state-badge {
  font-size: 1.06rem;
  font-weight: 790;
  text-transform: uppercase;
  letter-spacing: 0;
}

.state-badge.is-locked {
  color: var(--green);
}
.state-badge.is-unlocked {
  color: var(--amber);
}
.state-badge.is-busy {
  color: var(--blue);
}
.state-badge.is-error {
  color: var(--red);
}

.state-core p {
  margin: 6px 0 0;
  color: var(--muted);
}

.control-flow {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 34px 54px;
}

.control-flow .muted {
  max-width: 36ch;
  margin: 10px 0 18px;
}

.confirm-steps {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
}

.confirm-steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
}

.confirm-steps span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.confirm-steps li.is-active {
  color: var(--text);
}
.confirm-steps li.is-active span {
  border-color: var(--green);
  background: var(--green);
  color: #06200c;
  font-weight: 800;
}

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

.action-btn,
.btn {
  appearance: none;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  letter-spacing: 0;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    opacity 0.16s ease,
    transform 0.16s ease;
}

.action-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px 12px;
  min-height: 84px;
  padding: 16px 20px;
  text-align: left;
}

.action-icon {
  grid-row: span 2;
  width: 23px;
  height: 23px;
}

.action-label {
  font-size: 1.02rem;
  font-weight: 740;
}

.action-btn small {
  color: var(--muted);
  font-size: 0.82rem;
}

.btn-lock {
  color: var(--muted);
}
.btn-unlock {
  color: var(--amber);
  border-color: rgba(244, 165, 28, 0.8);
  background: rgba(244, 165, 28, 0.05);
}

.action-btn:hover:not(:disabled),
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: currentColor;
}

.action-btn:disabled,
.btn:disabled {
  opacity: 0.43;
  cursor: not-allowed;
  transform: none;
}

.action-btn.is-armed {
  border-color: var(--amber);
  background: rgba(244, 165, 28, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 14px;
  font-size: 0.92rem;
  font-weight: 690;
}

.compact-save {
  min-width: 70px;
  background: var(--blue);
  border-color: transparent;
}

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

.hint {
  min-height: 1.35em;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-list {
  padding: 10px 16px 14px;
}

.setting-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 54px;
  margin: 0;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}

.setting-row:last-of-type {
  border-bottom: 0;
}

.setting-row strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 680;
}

.setting-row small {
  display: block;
  color: var(--muted);
  font-size: 0.83rem;
}

.row-icon {
  width: 22px;
  height: 22px;
  color: var(--muted);
}

.row-chevron {
  color: var(--muted);
}

input[type="password"],
input[type="text"],
input[type="time"],
input[type="date"],
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-3);
  color: var(--text);
  font: inherit;
}

input[type="time"],
input[type="date"] {
  width: 148px;
}

label {
  display: block;
  margin: 12px 0;
}

.card label input {
  margin-top: 7px;
}

.switch {
  cursor: pointer;
  position: relative;
}

.switch-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  transition:
    background 0.16s ease,
    border-color 0.16s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    transform 0.16s ease,
    background 0.16s ease;
}

.switch-input:checked + .switch-track {
  border-color: var(--green);
  background: rgba(103, 226, 116, 0.22);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(18px);
  background: var(--green);
}

.alert {
  padding: 11px 12px;
  border: 1px solid rgba(255, 102, 92, 0.42);
  border-radius: var(--radius);
  background: rgba(255, 102, 92, 0.12);
  color: #ffc1bc;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(113, 128, 146, 0.16);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.status-tag.is-success {
  background: rgba(103, 226, 116, 0.15);
  color: var(--green);
}
.status-tag.is-failed {
  background: rgba(255, 102, 92, 0.16);
  color: var(--red);
}

.accessories-panel {
  margin-bottom: 14px;
}

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

.accessory-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  min-height: 82px;
  padding: 16px 22px;
  border-left: 1px solid var(--line-soft);
}

.accessory-row:first-child {
  border-left: 0;
}

.accessory-row strong {
  display: block;
  color: var(--text);
  font-size: 0.96rem;
}

.accessory-row small {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.accessory-row.is-ok .row-icon,
.accessory-row.is-ok .accessory-metric {
  color: var(--green);
}
.accessory-row.is-attention .row-icon,
.accessory-row.is-attention .accessory-metric {
  color: var(--amber);
}
.accessory-row.is-danger .row-icon,
.accessory-row.is-danger .accessory-metric {
  color: var(--red);
}

.accessory-metric {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 740;
  white-space: nowrap;
}

.history-panel {
  margin-bottom: 14px;
}

.history-tabs {
  display: flex;
  gap: 28px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.history-tab {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.history-tab.is-active {
  border-color: var(--blue);
  color: var(--text);
}

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.history-table th,
.history-table td {
  padding: 11px 22px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

.history-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.history-table td {
  color: #cbd5e1;
}

.history-row.is-lock td:nth-child(3),
.history-row.is-cron td:nth-child(3) {
  color: var(--green);
}
.history-row.is-unlock td:nth-child(3) {
  color: var(--amber);
}
.history-row.is-error td:nth-child(3),
.history-row.is-error td:nth-child(5) {
  color: var(--red);
}

.diagnostics-panel {
  margin-bottom: 0;
}

.diagnostics-panel summary {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 70px;
  padding: 0 22px;
  cursor: pointer;
  list-style: none;
}

.diagnostics-panel summary::-webkit-details-marker {
  display: none;
}

.diagnostics-panel summary strong {
  display: block;
  font-size: 0.95rem;
}

.diagnostics-panel summary small {
  color: var(--muted);
}

.diagnostics-panel[open] .row-chevron {
  transform: rotate(90deg);
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
}

.diagnostics-grid div {
  padding: 15px 22px;
  border-left: 1px solid var(--line-soft);
}

.diagnostics-grid div:first-child {
  border-left: 0;
}
.diagnostics-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}
.diagnostics-grid strong {
  font-size: 0.95rem;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(74, 144, 255, 0.48);
  outline-offset: 3px;
}

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

  .rail-item {
    border-top: 1px solid var(--line-soft);
  }

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

  .state-core {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .accessory-row {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .accessory-row:first-child {
    border-top: 0;
  }
}

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

  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 0 2px 14px;
  }

  .brand-wrap,
  .top-actions {
    justify-content: space-between;
  }

  .secure-label {
    padding-left: 12px;
    font-size: 0.82rem;
  }

  .status-rail {
    grid-template-columns: 1fr 1fr;
    margin: 0 -10px 10px;
  }

  .rail-item {
    min-height: 64px;
    padding: 13px 14px;
    gap: 11px;
  }

  .rail-icon {
    width: 21px;
    height: 21px;
  }

  .panel-head {
    padding: 14px;
  }

  .state-core {
    padding: 26px 18px;
  }

  .state-ring {
    width: 132px;
    height: 132px;
  }

  .state-icon {
    width: 46px;
    height: 46px;
  }

  .control-flow {
    padding: 22px 14px;
  }

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

  .settings-list {
    padding: 6px 14px 12px;
  }

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

  .setting-row > input,
  .setting-row > output,
  .setting-row > .switch-track,
  .setting-row > .status-tag,
  .setting-row > .row-chevron {
    grid-column: 2;
    justify-self: start;
  }

  .accessory-row {
    grid-template-columns: 24px minmax(0, 1fr);
    padding: 14px;
  }

  .accessory-row > .accessory-metric,
  .accessory-row > .status-tag {
    grid-column: 2;
    justify-self: start;
  }

  input[type="time"],
  input[type="date"] {
    width: min(100%, 180px);
  }

  .history-tabs {
    gap: 20px;
    overflow-x: auto;
    padding: 0 14px;
  }

  .history-table {
    min-width: 0;
  }

  .history-table thead {
    display: none;
  }

  .history-table,
  .history-table tbody,
  .history-table tr,
  .history-table td {
    display: block;
    width: 100%;
  }

  .history-table tr {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line-soft);
  }

  .history-table td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 12px;
    padding: 5px 0;
    border-bottom: 0;
    overflow-wrap: anywhere;
  }

  .history-table td::before {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 720;
  }

  .history-table td:nth-child(1)::before {
    content: "Time";
  }
  .history-table td:nth-child(2)::before {
    content: "Source";
  }
  .history-table td:nth-child(3)::before {
    content: "Event";
  }
  .history-table td:nth-child(4)::before {
    content: "Result";
  }
  .history-table td:nth-child(5)::before {
    content: "Details";
  }

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

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