:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #dfe4dc;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --success: #166534;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #b9c4b7;
  background: #fbfcfa;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.primary:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
}

.ghost {
  background: transparent;
}

.danger-btn {
  border-color: #fecaca;
  color: var(--danger);
}

.full {
  width: 100%;
}

.mobile-topbar,
.sidebar-backdrop,
.sidebar-close {
  display: none;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 22px 16px;
  background: #17211f;
  color: #e5efe8;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 30;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d9f99d;
  color: #1f2933;
  font-weight: 800;
}

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

.brand span {
  margin-top: 2px;
  color: #aebbb3;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  padding: 11px 12px;
  border-radius: 7px;
  color: #cad7d0;
}

.nav a.active,
.nav a:hover {
  background: #25332f;
  color: #fff;
  box-shadow: inset 3px 0 0 #d9f99d;
}

.logout {
  margin-top: auto;
}

.logout button {
  width: 100%;
  border-color: #34443f;
  background: transparent;
  color: #dce7e1;
}

.main {
  margin-left: 248px;
  padding: 34px;
  min-width: 0;
}

.auth-main {
  min-height: 100vh;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(28px, 4vw, 38px);
}

h2 {
  font-size: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

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

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

.panel {
  padding: 20px;
}

.section-gap {
  margin-bottom: 18px;
}

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

.text-link {
  color: var(--brand);
  font-weight: 700;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  max-width: 100%;
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfd8cc;
  border-radius: 7px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--brand);
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #374151;
  font-size: 14px;
}

.check input {
  width: 16px;
  min-height: 16px;
}

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

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid #edf0ea;
  text-align: left;
  vertical-align: top;
}

th {
  color: #647067;
  font-size: 12px;
  font-weight: 800;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

code {
  display: inline-block;
  max-width: 100%;
  padding: 3px 6px;
  border-radius: 5px;
  background: #eef3ed;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.on {
  background: #dcfce7;
  color: #166534;
}

.pill.off {
  background: #f1f5f9;
  color: #475569;
}

.pill.fail {
  background: #fee2e2;
  color: #991b1b;
}

.muted-text {
  color: var(--muted);
  max-width: min(320px, 100%);
  overflow-wrap: anywhere;
}

.append-preview {
  display: grid;
  gap: 7px;
}

.append-preview span {
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.append-preview pre {
  min-height: 82px;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid #d7dfd3;
  border-radius: 7px;
  background: #f8faf7;
  padding: 12px;
  color: #334155;
  font: inherit;
}

.help-grid,
.support-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.help-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.help-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e0f2f1;
  color: var(--brand-dark);
  font-weight: 900;
  margin-bottom: 12px;
}

.help-card p,
.help-card small,
.support-grid p {
  margin: 8px 0 0;
  color: var(--muted);
}

.help-card small {
  display: block;
  font-size: 13px;
}

.guide-list {
  display: grid;
  gap: 10px;
}

.guide-list div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #edf0ea;
}

.guide-list div:last-child {
  border-bottom: 0;
}

.guide-list span {
  color: var(--muted);
}

.support-grid > div {
  border: 1px solid #edf0ea;
  border-radius: 8px;
  padding: 14px;
}

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

.settings-list > div {
  display: grid;
  grid-template-columns: minmax(110px, 160px) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #edf0ea;
}

.settings-list > div:last-child {
  border-bottom: 0;
}

.settings-list p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.flow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.flow span {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 7px;
  background: #eef3ed;
  font-weight: 700;
}

.flow b {
  color: var(--brand);
}

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

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 7px;
  border: 1px solid;
}

.alert.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.alert.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(246, 247, 244, 0.88), rgba(246, 247, 244, 0.98)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cpath fill='%23dfe4dc' d='M0 89h180v2H0zM89 0h2v180h-2z'/%3E%3C/svg%3E");
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
}

.login-brand {
  margin-bottom: 24px;
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

@media (max-width: 1020px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

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

  .help-grid,
  .support-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  body {
    overflow-x: hidden;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 58px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(246, 247, 244, 0.96);
    backdrop-filter: blur(8px);
  }

  .mobile-menu-btn,
  .sidebar-close {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 28;
    display: block;
    background: rgba(15, 23, 42, 0.46);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    max-width: 320px;
    min-width: 0;
    height: 100dvh;
    padding: 16px;
    gap: 18px;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 18px 0 45px rgba(15, 23, 42, 0.24);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-flex;
    border-color: #34443f;
    background: transparent;
    color: #e5efe8;
  }

  .nav {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .nav a {
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 11px 12px;
    font-size: 15px;
  }

  .logout button {
    min-height: 46px;
  }

  .main {
    margin-left: 0;
    padding: 16px 12px 22px;
    width: 100%;
    max-width: 100vw;
  }

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

  .metric,
  .panel,
  .help-card {
    box-shadow: none;
  }

  .panel {
    padding: 16px;
  }

  .page-head {
    margin-bottom: 16px;
  }

  h1 {
    font-size: 26px;
  }

  input,
  textarea,
  select {
    font-size: 16px;
  }

  button,
  .button {
    min-height: 42px;
  }

  .actions > button,
  .actions > .button {
    flex: 1 1 150px;
  }

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

  .row-actions form {
    width: 100%;
  }

  .row-actions button,
  .row-actions .button {
    width: 100%;
  }

  .table-wrap {
    overflow-x: hidden;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    display: block;
    width: 100%;
    border: 1px solid #e5e9e1;
    border-radius: 8px;
    background: #fff;
    padding: 10px 12px;
  }

  td {
    display: grid;
    grid-template-columns: minmax(86px, 36%) minmax(0, 1fr);
    gap: 10px;
    width: 100%;
    padding: 9px 0;
    border-bottom: 1px solid #edf0ea;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: #647067;
    font-size: 12px;
    font-weight: 800;
  }

  td:last-child {
    border-bottom: 0;
  }

  td.row-actions {
    display: block;
  }

  td.row-actions::before {
    display: block;
    margin-bottom: 8px;
  }

  td.empty,
  td[colspan] {
    display: block;
    border-bottom: 0;
    text-align: center;
  }

  td.empty::before,
  td[colspan]::before {
    content: none;
  }

  .guide-list div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

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

  .flow span {
    justify-content: center;
    width: 100%;
  }

  .flow b {
    text-align: center;
    transform: rotate(90deg);
  }

  .page-head {
    align-items: start;
    flex-direction: column;
  }

  .settings-list > div {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 8px;
  }

  .login-shell {
    padding: 14px;
    align-items: center;
  }

  .login-panel {
    padding: 20px;
    box-shadow: none;
  }
}
