:root {
  --bg: #0c0e0d;
  --surface: #131615;
  --surface-soft: #191d1b;
  --line: #2b302e;
  --text: #f4f2ea;
  --muted: #929993;
  --green: #91f28d;
  --green-dark: #122b19;
  --amber: #f5bd66;
  --red: #ff766d;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 3%, rgba(145, 242, 141, 0.1), transparent 27rem),
    var(--bg);
  font-family: var(--sans);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  background-image:
    repeating-radial-gradient(
      circle at 17% 23%,
      #fff 0,
      #fff 0.5px,
      transparent 0.8px,
      transparent 4px
    );
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(12, 14, 13, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--green);
  border-radius: 50%;
  color: var(--bg);
  background: var(--green);
  font-weight: 850;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: -0.02em;
}

.brand small,
.eyebrow {
  color: var(--green);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
}

.topbar-actions,
.hero-actions,
.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.section-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.section-nav-button {
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 700;
}

.section-nav-button span {
  margin-left: 5px;
  color: inherit;
  font-family: var(--mono);
}

.section-nav-button.is-active {
  color: var(--text);
  background: var(--surface-soft);
}

.live-indicator {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.live-indicator i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.live-indicator.is-live i {
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(145, 242, 141, 0.08);
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 54px clamp(20px, 4vw, 64px) 80px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  font-size: clamp(2.6rem, 6vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: -0.065em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  letter-spacing: -0.035em;
}

.eyebrow {
  margin-bottom: 15px;
  text-transform: uppercase;
}

.lead {
  max-width: 640px;
  margin-bottom: 0;
  color: #b2b8b3;
  font-size: 1.05rem;
  line-height: 1.65;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 60px;
  min-height: calc(100vh - 210px);
  align-items: center;
}

.auth-card form,
.dialog-card {
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(19, 22, 21, 0.9);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.3);
}

label {
  display: block;
  margin-bottom: 10px;
  color: #bec3bf;
  font-size: 0.82rem;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 0 15px;
  border: 1px solid #3a403d;
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: #0d100f;
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(145, 242, 141, 0.1);
}

textarea {
  width: 100%;
  padding: 14px 15px;
  resize: vertical;
  border: 1px solid #3a403d;
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: #0d100f;
  line-height: 1.55;
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(145, 242, 141, 0.1);
}

.input-row input {
  flex: 1;
}

.button {
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 720;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.5;
  transform: none;
}

.button-primary {
  color: #081009;
  background: var(--green);
}

.button-ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.button-danger {
  border-color: rgba(255, 118, 109, 0.38);
  color: #ffaaa4;
  background: rgba(255, 118, 109, 0.07);
}

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 0.82rem;
}

.dashboard {
  display: block;
}

.view-stack {
  display: grid;
  gap: 22px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  align-items: end;
  padding: 34px 0 24px;
}

.hero h1 {
  margin-bottom: 12px;
  font-size: clamp(2.6rem, 5vw, 5rem);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(19, 22, 21, 0.82);
}

.metric {
  min-height: 170px;
  padding: 22px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  display: block;
  margin: 24px 0 10px;
  font-size: 3.1rem;
  line-height: 1;
  letter-spacing: -0.06em;
}

.metric-featured {
  color: #0a100b;
  border-color: var(--green);
  background: var(--green);
}

.metric-featured span,
.metric-featured small {
  color: #29452c;
}

.metric-alert strong {
  color: var(--red);
}

.split-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 12px;
}

.panel {
  padding: 24px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
}

.status-pill,
.job-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.status-muted {
  border-color: #3d4340;
  color: var(--muted);
}

.status-good,
.job-status-delivered,
.job-status-sent {
  border-color: rgba(145, 242, 141, 0.35);
  color: var(--green);
  background: rgba(145, 242, 141, 0.06);
}

.status-warn,
.job-status-unknown,
.job-status-retry_wait {
  border-color: rgba(245, 189, 102, 0.4);
  color: var(--amber);
  background: rgba(245, 189, 102, 0.06);
}

.status-bad,
.job-status-failed,
.job-status-expired {
  border-color: rgba(255, 118, 109, 0.4);
  color: var(--red);
  background: rgba(255, 118, 109, 0.06);
}

.device-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin: 40px 0 0;
}

.device-stats div {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.device-stats dt {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.7rem;
}

.device-stats dd {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
}

.webhook-time {
  margin: 40px 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
}

.templates-header {
  padding: 34px 0 10px;
}

.templates-header h1 {
  margin-bottom: 12px;
  font-size: clamp(2.6rem, 5vw, 4.5rem);
}

.template-workspace {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.automation-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.8fr)
    minmax(180px, 0.8fr) auto;
  gap: 14px;
  align-items: end;
}

.automation-create-form label {
  display: grid;
  gap: 8px;
  margin: 0;
}

.automation-create-form .form-error {
  grid-column: 1 / -1;
  margin: 0;
}

.automation-list {
  display: grid;
  gap: 12px;
}

.automation-card {
  display: grid;
  gap: 20px;
}

.automation-url {
  display: flex;
  gap: 10px;
  align-items: center;
}

.automation-url code {
  min-width: 0;
  flex: 1;
  padding: 12px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--green);
  background: rgba(145, 242, 141, 0.04);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-meta,
.automation-actions {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
}

.automation-meta {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 0.78rem;
}

.automation-meta strong {
  color: var(--text);
}

.template-library,
.template-editor-panel {
  display: grid;
  gap: 20px;
}

.template-library {
  position: sticky;
  top: 98px;
  padding: 18px;
}

.template-library-heading {
  padding: 4px 4px 0;
}

.template-list {
  display: grid;
  gap: 6px;
}

.template-list-item {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.template-list-item:hover {
  background: rgba(255, 255, 255, 0.025);
}

.template-list-item.is-selected {
  border-color: rgba(145, 242, 141, 0.28);
  background: rgba(145, 242, 141, 0.06);
}

.template-list-item strong,
.template-list-item small {
  display: block;
}

.template-list-item strong {
  margin-bottom: 5px;
  font-size: 0.82rem;
}

.template-list-item small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.template-list-item i {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.template-list-item i.is-enabled {
  background: var(--green);
}

.compact-empty {
  padding: 18px;
}

.template-form {
  display: grid;
  gap: 18px;
}

.template-field {
  display: grid;
  gap: 8px;
}

.template-field label {
  margin: 0;
}

.template-actions,
.checkbox-row,
.variable-list {
  display: flex;
  gap: 12px;
  align-items: center;
}

.template-actions {
  justify-content: space-between;
}

.template-save-actions {
  display: flex;
  gap: 8px;
}

.checkbox-row {
  margin: 0;
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--green);
}

.variable-list {
  flex-wrap: wrap;
  margin-top: 9px;
}

.variable-list code {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green);
  background: rgba(145, 242, 141, 0.05);
  font-size: 0.76rem;
}

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

.table-panel {
  overflow: hidden;
  padding: 0;
}

.table-panel > .panel-heading {
  padding: 24px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th,
td {
  padding: 15px 18px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.015);
  font-size: 0.68rem;
  font-weight: 550;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.8rem;
}

.phone {
  font-family: var(--mono);
}

.message-preview {
  display: block;
  max-width: 390px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

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

.row-action {
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.74rem;
}

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

.event-list {
  border-top: 1px solid var(--line);
}

.event-item {
  display: grid;
  grid-template-columns: 160px 100px 190px minmax(0, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
}

.event-route {
  overflow: hidden;
  color: var(--green);
  font-family: var(--mono);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-full {
  margin: 0;
  padding: 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: #0d100f;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.event-item:last-child {
  border-bottom: 0;
}

.event-detail {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
}

.dialog-card {
  display: grid;
  gap: 18px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 1.4rem;
}

.pairing-result {
  padding: 18px;
  border: 1px solid rgba(145, 242, 141, 0.3);
  border-radius: 14px;
  background: var(--green-dark);
  text-align: center;
}

.pairing-result small,
.pairing-result strong {
  display: block;
}

.pairing-result strong {
  margin: 10px 0 16px;
  font-family: var(--mono);
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  word-break: break-all;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: 340px;
  padding: 13px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  opacity: 0;
  background: var(--surface-soft);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
  transform: translateY(12px);
  transition: 160ms ease;
  pointer-events: none;
  font-size: 0.82rem;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .auth-card,
  .split-grid,
  .template-workspace {
    grid-template-columns: 1fr;
  }

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

  .auth-card {
    gap: 36px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .device-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .template-library {
    position: static;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 66px;
  }

  .live-indicator,
  #refresh-button {
    display: none;
  }

  .topbar {
    gap: 12px;
  }

  .brand small {
    display: none;
  }

  main {
    padding-top: 32px;
  }

  .hero {
    display: grid;
    align-items: start;
  }

  .hero-actions {
    flex-wrap: wrap;
  }

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

  .metric {
    min-height: 130px;
  }

  .metric strong {
    margin-top: 16px;
  }

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

  .template-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .automation-url,
  .automation-actions,
  .automation-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .template-save-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .event-item {
    grid-template-columns: 1fr auto;
  }

  .event-detail,
  .event-route {
    grid-column: 1 / -1;
  }
}
