/* ---------------------------------------------------------------------------
   Automation Health Monitor - visual system
   Near-black warm grey canvas (#0D0C0A), deep dark red accent (#4D0000).
   Editorial, flat, typographic. Motion is quiet: transform + opacity only.
--------------------------------------------------------------------------- */

:root {
  /* Brand palette (user-mandated dark theme) */
  --paper: #0d0c0a;
  --paper-deep: #080706;
  --panel: #161310;
  --accent: #4d0000;
  --accent-soft: #6b1010;
  --accent-wash: rgba(214, 69, 65, 0.08);
  /* Legible red for text and links on the dark canvas (fills stay #4D0000) */
  --accent-text: #e0655a;
  --on-accent: #f6ece2;

  /* Warm light ink ramp on dark */
  --ink: #ece5d8;
  --muted: #a49a8b;
  --faint: #6e665a;

  /* Hairlines tinted to the warm ink */
  --line: rgba(236, 229, 216, 0.16);
  --line-soft: rgba(236, 229, 216, 0.09);

  /* Semantic states, harmonized to the dark palette */
  --ok: #97c274;
  --ok-wash: rgba(122, 168, 87, 0.12);
  --warn: #d9a441;
  --warn-wash: rgba(217, 164, 65, 0.12);
  --bad: #e0655a;
  --bad-wash: rgba(224, 101, 90, 0.12);

  /* Type */
  --display: "Outfit", "DM Sans", system-ui, sans-serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  /* Motion (strong curves; UI stays under 300ms) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --reveal: cubic-bezier(0.16, 1, 0.3, 1);

  --radius: 12px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}

::selection { background: rgba(224, 101, 90, 0.3); }

/* Ambient background: fixed layer, extremely low opacity, slow drift */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1100px 600px at 8% -12%, rgba(214, 69, 65, 0.07), transparent 62%),
    radial-gradient(900px 520px at 104% 4%, rgba(217, 164, 65, 0.04), transparent 58%),
    linear-gradient(180deg, var(--paper-deep) 0%, var(--paper) 38%, #12100d 100%);
}

.bg::after {
  content: "";
  position: absolute;
  width: 60vw;
  height: 60vw;
  top: -30vw;
  left: 55vw;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(214, 69, 65, 0.06), transparent 70%);
  animation: drift 26s var(--ease-in-out) infinite alternate;
  will-change: transform;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-14vw, 10vh, 0); }
}

/* ------------------------------------------------------------------ header */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.6rem;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(13, 12, 10, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.mark {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.5rem;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  position: relative;
  flex: none;
}

/* Heartbeat tick inside the mark: the product in one glyph */
.mark::after {
  content: "";
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  top: 50%;
  height: 2px;
  background:
    linear-gradient(90deg,
      var(--on-accent) 0 22%, transparent 22% 34%,
      var(--on-accent) 34% 44%, transparent 44% 52%,
      var(--on-accent) 52% 100%);
  transform: translateY(-50%);
}

.product {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.02rem;
  line-height: 1.2;
}

.tag {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.health {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}

.health.ok { color: var(--ok); border-color: rgba(151, 194, 116, 0.35); }
.health.bad { color: var(--bad); border-color: rgba(224, 101, 90, 0.35); }

.nav-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-text);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}

@media (hover: hover) and (pointer: fine) {
  .nav-link:hover { background: var(--accent-wash); }
}

/* -------------------------------------------------------------------- main */
main {
  width: min(920px, calc(100% - 2.5rem));
  margin: 2.25rem auto 4rem;
}

.view { display: grid; gap: 1.4rem; }
.view[hidden] { display: none; }

/* HTML hidden must beat display rules like .form > div { display: grid } */
[hidden] { display: none !important; }

/* One-time entrance for view content. Transform + opacity only. */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  animation: rise 560ms var(--reveal) forwards;
  animation-delay: calc(var(--i, 0) * 70ms);
}

@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------------- hero */
.hero { padding: 0.6rem 0 0.4rem; }

.display {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.85rem, 4.4vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: -0.035em;
  max-width: 21ch;
}

.display .underline {
  color: var(--accent-text);
}

.hero .lede { max-width: 58ch; font-size: 1.02rem; }

.landing-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 1.4rem;
  align-items: start;
}

/* ------------------------------------------------------------------ panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.6rem 1.7rem 1.75rem;
  transition: box-shadow 200ms var(--ease-out);
}

h1, h2, h3 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: -0.025em;
  font-weight: 700;
}

h1 { font-size: 1.55rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }

.lede {
  margin: 0.5rem 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.94rem;
  max-width: 52ch;
}

.section-head { margin-bottom: 1.1rem; }

.section-head.row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------- forms */
.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1rem;
  margin-top: 1.2rem;
}

.form label,
.login-form label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.form label:nth-child(1),
.form > div,
.form > p,
.form button {
  grid-column: 1 / -1;
}

.form > div {
  display: grid;
  gap: 0.9rem;
}

.opt { font-weight: 400; opacity: 0.8; }

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

input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #1b1814;
  border-radius: var(--radius-sm);
  padding: 0.72rem 0.85rem;
  color: var(--ink);
  transition: border-color 150ms ease, background-color 150ms ease;
}

input::placeholder { color: var(--faint); }

input:focus-visible, select:focus-visible {
  outline: 2px solid rgba(224, 101, 90, 0.5);
  outline-offset: 1px;
  border-color: rgba(224, 101, 90, 0.45);
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  padding: 0.8rem 1.1rem;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  button:hover { background: var(--accent-soft); }
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.55; cursor: wait; transform: none; }

button:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(224, 101, 90, 0.55);
  outline-offset: 2px;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
}

@media (hover: hover) and (pointer: fine) {
  button.ghost:hover { background: var(--accent-wash); color: var(--accent-text); border-color: rgba(224, 101, 90, 0.35); }
}

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.status {
  margin: 0.95rem 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.status.err { color: var(--bad); }

/* ------------------------------------------------------------- login panel */
.login-panel { position: sticky; top: 5.4rem; }

.login-form { display: grid; gap: 0.9rem; margin-top: 1.1rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--faint);
  font-size: 0.72rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.2rem 0 0;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

/* ------------------------------------------------------------------- lists */
.stack { display: grid; gap: 0.9rem; }

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

.item:first-child { border-top: 0; padding-top: 0; }

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.name {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.mono {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* ------------------------------------------------------------------ badges */
.badge {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}

.badge.high, .badge.bad { color: var(--bad); border-color: rgba(224, 101, 90, 0.3); background: var(--bad-wash); }
.badge.medium, .badge.warn { color: var(--warn); border-color: rgba(217, 164, 65, 0.3); background: var(--warn-wash); }
.badge.low, .badge.ok { color: var(--ok); border-color: rgba(151, 194, 116, 0.3); background: var(--ok-wash); }
.badge.preview {
  color: var(--warn);
  border-color: rgba(217, 164, 65, 0.35);
  background: var(--warn-wash);
  text-transform: none;
  letter-spacing: 0.02em;
  white-space: normal;
  max-width: 18rem;
  line-height: 1.35;
}

/* --------------------------------------------------------- monitoring strip */
.monitor-strip {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1.1rem 1.7rem;
}

.monitor-cell { display: grid; gap: 0.15rem; }

.monitor-label {
  font-family: var(--mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.monitor-value {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.monitor-value .mono { font-size: 0.85rem; }

.pulse-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--ok);
  position: relative;
  flex: none;
}

.pulse-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid var(--ok);
  opacity: 0;
  animation: ping 2.4s var(--ease-out) infinite;
}

.pulse-dot.stale { background: var(--warn); }
.pulse-dot.stale::after { border-color: var(--warn); }
.pulse-dot.down { background: var(--bad); }
.pulse-dot.down::after { animation: none; }

@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.7; }
  70%, 100% { transform: scale(1.5); opacity: 0; }
}

.monitor-spacer { flex: 1; }

/* -------------------------------------------------------- workflow rows */
.account-group { margin-top: 1.3rem; }
.account-group:first-child { margin-top: 0; }

.account-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line);
}

.account-head .name { font-family: var(--display); letter-spacing: -0.02em; }
.account-head .mono { color: var(--faint); }

.wf-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem 1rem;
  align-items: center;
  padding: 0.8rem 0.6rem;
  margin: 0 -0.6rem;
  border-radius: var(--radius-sm);
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none;
  color: inherit;
  transition: background-color 150ms ease, transform 160ms var(--ease-out);
}

.wf-row:last-child { border-bottom: 0; }

@media (hover: hover) and (pointer: fine) {
  .wf-row:hover { background: var(--accent-wash); }
}

.wf-row:active { transform: scale(0.995); }

.wf-name {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
}

.wf-name span.txt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wf-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

.wf-sub {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------- detail view */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--accent-text);
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  width: fit-content;
}

@media (hover: hover) and (pointer: fine) {
  .back-link:hover { text-decoration: underline; }
}

.detail-title {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem 1.5rem;
  margin-top: 1.1rem;
}

.kv { display: grid; gap: 0.2rem; }

.kv .k {
  font-family: var(--mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.kv .v { font-weight: 600; font-size: 0.94rem; }
.kv .v.mono { font-weight: 500; }

/* ------------------------------------------------------------ guided fixes */
.fix-row {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.fix-action {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.fix-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .fix-btn:hover { background: var(--accent-soft); }
}

.fix-btn:active { transform: scale(0.97); }

/* -------------------------------------------------------------- skeletons */
.skeleton {
  display: grid;
  gap: 0.7rem;
}

.skeleton .bone {
  height: 0.95rem;
  border-radius: 4px;
  background: var(--line-soft);
  animation: breathe 1.4s var(--ease-in-out) infinite alternate;
}

.skeleton .bone.wide { width: 72%; }
.skeleton .bone.mid { width: 48%; }
.skeleton .bone.slim { width: 30%; }

@keyframes breathe {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

/* -------------------------------------------------------------- empty state */
.empty {
  text-align: center;
  padding: 2.2rem 1rem;
  color: var(--muted);
}

.empty .glyph {
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--faint);
  letter-spacing: 0.3em;
  margin-bottom: 0.6rem;
}

.empty p { margin: 0.2rem 0; }
.empty .hint { font-size: 0.85rem; color: var(--faint); }

/* ------------------------------------------------------------- misc rows */
.confirm-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.8rem;
  align-items: center;
}

.confirm-row select { width: auto; min-width: 8rem; }
.confirm-row input { flex: 1; min-width: 12rem; }
.confirm-row button { width: auto; padding: 0.62rem 0.9rem; }

.muted { color: var(--muted); margin: 0; }

.token-box {
  border: 1px solid rgba(224, 101, 90, 0.3);
  background: var(--accent-wash);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.95rem;
  margin-top: 0.45rem;
  word-break: break-all;
}

.check-row {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

.check-row input {
  width: auto;
  margin-top: 0.2rem;
  accent-color: var(--accent);
}

button.danger {
  background: #6b1010;
}

button.danger:hover { background: #8a1717; }

.recovery-panel { width: min(560px, 100%); margin: 0 auto; }

/* ----------------------------------------------------------- scan progress */
.scan-progress {
  margin-top: 0.85rem;
}

.scan-progress-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.scan-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

.scan-progress .meta {
  margin: 0.45rem 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ------------------------------------------------------------------- toast */
.toast-host {
  position: fixed;
  z-index: 80;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  font-size: 0.9rem;
  line-height: 1.35;
  box-shadow: 0 10px 28px rgba(20, 16, 12, 0.12);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-ok { border-left-color: #2f6b4f; }
.toast-err { border-left-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
  .scan-progress-bar { transition: none; }
}

a.name { color: inherit; text-decoration: none; }
a.name:hover { color: var(--accent-text); text-decoration: underline; }

.meta a,
.status a,
.recovery-panel a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.meta a:hover,
.status a:hover,
.recovery-panel a:hover { color: var(--ink); }

/* ----------------------------------------------------------- one-time modal */
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.modal[hidden] { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 7, 6, 0.72);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  border-color: rgba(224, 101, 90, 0.28);
  animation: modal-in 220ms var(--ease-out) both;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal-dialog { animation: none; }
}

kbd {
  font-family: var(--mono);
  font-size: 0.72rem;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
  padding: 0.1rem 0.4rem;
}

footer {
  width: min(920px, calc(100% - 2.5rem));
  margin: 0 auto 2.25rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
}

footer a { color: var(--accent-text); }

/* ----------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .reveal { animation-duration: 1ms; animation-delay: 0ms; }
  .bg::after, .pulse-dot::after { animation: none; }
  .wf-row, button, .fix-btn { transition-duration: 1ms; }
  .skeleton .bone { animation: none; opacity: 0.6; }
}

/* -------------------------------------------------------------- responsive */
@media (max-width: 760px) {
  .landing-grid { grid-template-columns: 1fr; }
  .login-panel { position: static; }
  .form { grid-template-columns: 1fr; }
  .form label:nth-child(1),
  .form > div,
  .form > p,
  .form button { grid-column: auto; }
  .top { padding: 0.9rem 1rem; }
  .tag { display: none; }
  .monitor-strip { gap: 1rem 1.4rem; }
}
