:root {
  --bg0: #070d18;
  --bg1: #0f1a2e;
  --card: rgba(18, 28, 48, 0.92);
  --card-solid: #121c30;
  --line: rgba(140, 170, 210, 0.16);
  --line-strong: rgba(140, 170, 210, 0.28);
  --text: #e8eef8;
  --muted: #8fa3c3;
  --accent: #3dd6c6;
  --accent2: #5b8cff;
  --ok: #4ade80;
  --danger: #ff6b7a;
  --warn: #f0b429;
  --radius: 16px;
  --radius-sm: 12px;
  --touch: 44px;
  --space: 1rem;
  --header-h: 3.5rem;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + var(--safe-t) + 3.5rem);
}

body {
  margin: 0;
  font-family: Vazirmatn, system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 100% 0%, rgba(61, 214, 198, 0.12), transparent 55%),
    radial-gradient(800px 400px at 0% 10%, rgba(91, 140, 255, 0.12), transparent 50%),
    linear-gradient(180deg, var(--bg0), #0a1424);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.65;
  padding-bottom: var(--safe-b);
}

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

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* —— Header —— */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-t)) calc(1rem + var(--safe-r)) 0.75rem calc(1rem + var(--safe-l));
  border-bottom: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: calc(var(--header-h) + var(--safe-t));
}

.top-brand {
  min-width: 0;
  flex: 1;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.top h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.top-actions form {
  margin: 0;
}

.user {
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Mobile section nav —— */
.section-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.65rem calc(0.85rem + var(--safe-r)) 0.65rem calc(0.85rem + var(--safe-l));
  border-bottom: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.55);
  position: sticky;
  top: calc(var(--header-h) + var(--safe-t));
  z-index: 15;
}

.section-nav::-webkit-scrollbar {
  display: none;
}

.section-nav a {
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.4);
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.section-nav a:hover,
.section-nav a:focus-visible {
  color: var(--text);
  border-color: rgba(61, 214, 198, 0.4);
  outline: none;
}

/* —— Layout —— */
.layout {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 0.85rem calc(0.75rem + var(--safe-r)) 2.5rem calc(0.75rem + var(--safe-l));
  display: grid;
  gap: 0.85rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1rem 1.1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-lead {
  margin: -0.35rem 0 0.85rem;
}

/* —— Status —— */
.status-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.status-main .label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  margin-top: 0.4rem;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.85rem;
  border: 1px solid var(--line);
}

.status-pill.running {
  background: rgba(74, 222, 128, 0.15);
  color: var(--ok);
  border-color: rgba(74, 222, 128, 0.35);
}

.status-pill.stopped,
.status-pill.stopping {
  background: rgba(255, 107, 122, 0.12);
  color: var(--danger);
  border-color: rgba(255, 107, 122, 0.3);
}

.status-pill.starting {
  background: rgba(240, 180, 41, 0.12);
  color: var(--warn);
  border-color: rgba(240, 180, 41, 0.35);
}

.status-pill.error {
  background: rgba(255, 107, 122, 0.2);
  color: #ffb4bc;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.45);
  color: var(--muted);
}

.chip.ok {
  color: #b7f7cb;
  border-color: rgba(74, 222, 128, 0.3);
  background: rgba(74, 222, 128, 0.1);
}

.chip.warn {
  color: #ffd89a;
  border-color: rgba(240, 180, 41, 0.35);
  background: rgba(240, 180, 41, 0.1);
}

.chip.bad {
  color: #ffc0c7;
  border-color: rgba(255, 107, 122, 0.3);
  background: rgba(255, 107, 122, 0.1);
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

#status-meta {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.controls .btn {
  width: 100%;
}

/* —— Metrics —— */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
}

.metrics div {
  background: rgba(8, 14, 28, 0.45);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.55rem;
  text-align: center;
  min-width: 0;
}

.metrics b {
  display: block;
  font-size: 1.15rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  color: var(--accent);
  word-break: break-all;
}

.metrics span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

/* —— Buttons —— */
.btn {
  border: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.5);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  min-height: var(--touch);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:hover {
  border-color: rgba(61, 214, 198, 0.45);
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: linear-gradient(135deg, rgba(61, 214, 198, 0.28), rgba(91, 140, 255, 0.3));
  border-color: rgba(61, 214, 198, 0.4);
}

.btn.ok {
  background: rgba(74, 222, 128, 0.16);
  border-color: rgba(74, 222, 128, 0.35);
  color: #b7f7cb;
}

.btn.danger {
  background: rgba(255, 107, 122, 0.14);
  border-color: rgba(255, 107, 122, 0.35);
  color: #ffc0c7;
}

.btn.ghost {
  background: transparent;
  min-height: 40px;
  padding: 0.45rem 0.85rem;
}

/* —— Forms —— */
.grid-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.grid-form .full {
  grid-column: 1 / -1;
}

.form-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.85rem 0 0;
  border: none;
  margin: 0;
  min-width: 0;
  grid-column: 1 / -1;
}

.form-group + .form-group {
  border-top: 1px solid var(--line);
  margin-top: 0.25rem;
}

.form-group-title {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0.02em;
  margin: 0;
  padding: 0;
}

.stack {
  display: grid;
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: #d5e0f5;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.55);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 16px; /* prevent iOS zoom */
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238fa3c3' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.85rem center;
  padding-left: 2.2rem;
}

textarea {
  min-height: 8rem;
  resize: vertical;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(61, 214, 198, 0.55);
  outline-offset: 1px;
  border-color: rgba(61, 214, 198, 0.45);
}

.flash {
  margin-top: 0.6rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  font-size: 0.9rem;
}

.flash.ok {
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: #baf7cc;
}

.flash.bad {
  background: rgba(255, 107, 122, 0.12);
  border: 1px solid rgba(255, 107, 122, 0.3);
  color: #ffc2c9;
}

/* —— Log —— */
.log-box {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #070d18;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  line-height: 1.55;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

/* —— Tables → cards on mobile —— */
.table-wrap {
  overflow: visible;
  margin: 0 -0.15rem;
}

.table-cards {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.table-cards thead {
  display: none;
}

.table-cards tbody {
  display: grid;
  gap: 0.55rem;
}

.table-cards tr {
  display: grid;
  gap: 0.35rem;
  background: rgba(8, 14, 28, 0.45);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
}

.table-cards td {
  display: grid;
  grid-template-columns: minmax(5.5rem, 35%) 1fr;
  gap: 0.5rem;
  align-items: start;
  border: none;
  padding: 0.2rem 0;
  text-align: right;
  word-break: break-word;
}

.table-cards td::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.table-cards td[colspan] {
  display: block;
  text-align: center;
  grid-template-columns: 1fr;
}

.table-cards td[colspan]::before {
  content: none;
}

.account-head {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.account-head .metrics {
  margin-top: 0.5rem;
  grid-template-columns: repeat(2, minmax(0, 8rem));
  justify-content: start;
}

.form-group legend {
  padding: 0;
  float: none;
}

/* —— Auth —— */
.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-r)) calc(1rem + var(--safe-b)) calc(1rem + var(--safe-l));
}

.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.5rem 1.25rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.brand {
  margin-bottom: 1.25rem;
  text-align: center;
}

.brand h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.45rem;
  font-weight: 800;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.pulse {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(61, 214, 198, 0.2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.15);
    opacity: 0.7;
  }
}

.auth-card .btn {
  width: 100%;
  margin-top: 0.25rem;
}

.auth-card .stack label {
  font-size: 0.9rem;
}

/* —— Tablet+ —— */
@media (min-width: 480px) {
  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .log-box {
    max-height: 260px;
    font-size: 0.78rem;
  }
}

@media (min-width: 768px) {
  .layout {
    padding: 1.1rem 1rem 2.5rem;
    gap: 1rem;
  }

  .card {
    padding: 1.15rem 1.2rem;
  }

  .section-nav {
    display: none;
  }

  html {
    scroll-padding-top: calc(var(--header-h) + var(--safe-t) + 1rem);
  }

  .status-row {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .controls {
    display: flex;
    flex-wrap: wrap;
    max-width: 22rem;
  }

  .controls .btn {
    width: auto;
    flex: 1 1 auto;
    min-width: 6.5rem;
  }

  .metrics {
    grid-template-columns: repeat(6, 1fr);
    gap: 0.55rem;
  }

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

  .form-group {
    grid-template-columns: 1fr 1fr;
  }

  .account-head {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .account-head .controls {
    max-width: none;
  }

  .account-head .controls .btn {
    width: auto;
  }

  /* Tables as real tables on desktop */
  .table-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0;
  }

  .table-cards thead {
    display: table-header-group;
  }

  .table-cards tbody {
    display: table-row-group;
  }

  .table-cards tr {
    display: table-row;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
  }

  .table-cards th,
  .table-cards td {
    display: table-cell;
    border-bottom: 1px solid var(--line);
    padding: 0.55rem 0.4rem;
    text-align: right;
    grid-template-columns: none;
  }

  .table-cards th {
    color: #c9d7f2;
    font-weight: 600;
  }

  .table-cards td::before {
    content: none;
  }

  .log-box {
    max-height: 300px;
  }

  input,
  select,
  textarea {
    font-size: inherit;
  }

  textarea {
    font-size: 0.8rem;
  }
}

@media (min-width: 900px) {
  .top {
    padding-left: 1.4rem;
    padding-right: 1.4rem;
  }

  .layout {
    width: min(1100px, calc(100% - 1.5rem));
  }

  .user {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .pulse {
    animation: none;
  }

  .btn:active {
    transform: none;
  }
}

/* —— pooryabot extras —— */
.ledger-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.ledger-list li {
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(8, 14, 28, 0.45);
  font-size: 0.88rem;
}

.ledger-kind {
  color: var(--accent);
  font-weight: 700;
}

.table-cards tr.hot {
  border-color: rgba(255, 107, 122, 0.45);
  background: rgba(255, 107, 122, 0.1);
}

.controls form {
  margin: 0;
}
