:root {
  --bg: #f7f8f5;
  --paper: #ffffff;
  --ink: #14211f;
  --muted: #65716d;
  --line: #d9e1dc;
  --soft: #edf3ef;
  --teal: #0d7a6c;
  --teal-dark: #08594f;
  --amber: #bf7a12;
  --red: #b94a3f;
  --charcoal: #182321;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

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

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin-right: 8px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink);
  line-height: 1.45;
}

.checkbox-row a,
.legal-document a,
.app-footer a {
  color: var(--teal-dark);
  font-weight: 800;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 245, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 850;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: block;
  border-radius: 8px;
  object-fit: contain;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 0.94rem;
}

.app-nav a:hover {
  color: var(--teal-dark);
}

.app-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(30px, 6vw, 64px) 0;
}

.loading-shell {
  position: fixed;
  inset: 61px 0 0;
  z-index: 9;
  width: 100%;
  max-width: none;
  min-height: calc(100vh - 61px);
  margin: 0;
  padding: clamp(30px, 6vw, 64px) 16px;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.loading-card {
  width: min(620px, 100%);
  display: flex;
  align-items: center;
  gap: 18px;
}

.loading-card h1 {
  margin: 4px 0 6px;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
}

.loader-ring {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: 4px solid var(--soft);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: loader-spin 0.85s linear infinite;
}

@keyframes loader-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader-ring {
    animation: none;
    border-color: var(--teal);
  }
}

.app-footer {
  width: min(1180px, calc(100% - 32px));
  display: flex;
  flex-wrap: wrap;
  column-gap: 22px;
  row-gap: 10px;
  margin: 0 auto;
  padding: 24px 0 34px;
  color: var(--muted);
}

.app-footer a {
  position: relative;
  line-height: 1.2;
}

.app-footer a + a::before {
  content: "";
  position: absolute;
  top: 0.1em;
  bottom: 0.1em;
  left: -11px;
  width: 1px;
  background: var(--line);
}

.legal-page {
  max-width: 980px;
}

.legal-document {
  line-height: 1.65;
}

.legal-document h2 {
  margin-top: 30px;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.legal-document ul {
  color: var(--muted);
  line-height: 1.6;
}

.page-heading {
  max-width: 760px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.3rem, 7vw, 5.1rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1.05;
}

h3 {
  margin-bottom: 8px;
}

.muted,
.page-heading p,
.card p {
  color: var(--muted);
  line-height: 1.55;
}

.grid-2,
.grid-3,
.detail-grid,
.dashboard-grid,
.admin-grid,
.settings-stack {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  align-items: start;
}

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

.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.detail-grid div,
.token-box {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-grid strong,
.token-box strong,
.token-box code {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-weight: 850;
}

.token-box {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  background: #fbfcfb;
}

.token-code {
  font-size: 1.15rem;
}

.token-box[hidden] {
  display: none;
}

.connection-site {
  display: grid;
  gap: 3px;
  margin-bottom: 14px;
}

.connection-site strong {
  color: var(--ink);
}

.connection-steps {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.connection-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.connection-step strong {
  display: block;
  margin-bottom: 4px;
}

.connection-step p {
  margin-bottom: 10px;
  font-size: 0.94rem;
}

.step-number {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--soft);
  color: var(--teal-dark);
  font-size: 0.86rem;
  font-weight: 850;
}

.connection-actions,
.pairing-code-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.pairing-code-row {
  justify-content: space-between;
}

.token-hint {
  display: block;
  margin-top: 5px;
  font-size: 0.86rem;
}

.button.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.dashboard-grid {
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  align-items: start;
}

.admin-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.settings-stack {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.card,
.table-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 14px 40px rgba(25, 38, 34, 0.07);
}

.card {
  padding: 22px;
}

.table-card {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-toolbar h2 {
  margin-bottom: 0;
}

.table-toolbar input {
  max-width: 260px;
}

.card-header,
.metric-row,
.site-row,
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-header {
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
}

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

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
}

.button-primary {
  background: var(--teal);
  color: #fff;
}

.button-secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button-danger {
  border-color: rgba(185, 74, 63, 0.28);
  background: #fff5f3;
  color: var(--red);
}

.button-small {
  min-height: 34px;
  margin-top: 8px;
  padding: 7px 10px;
  font-size: 0.82rem;
}

.plan-toggle,
.segmented-control,
.restore-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.restore-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
}

.segmented-control label {
  display: block;
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.segmented-control input:checked + span {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(25, 38, 34, 0.07);
}

.segmented-control input:focus-visible + span {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.toggle-option,
.scope-option {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.toggle-option.active,
.scope-option.active {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.form-grid {
  display: grid;
  gap: 14px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

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

.setting-check {
  align-self: stretch;
  min-height: 46px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.setting-check small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.45;
}

.notice,
.activity-log {
  border-radius: 8px;
  padding: 12px;
}

.notice {
  border: 1px solid rgba(13, 122, 108, 0.24);
  background: #edf8f4;
  color: var(--teal-dark);
}

.activity-log {
  margin-top: 14px;
  background: var(--charcoal);
  color: #d7ebe5;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.5;
}

.admin-settings-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
}

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

.admin-settings-panel summary h2 {
  margin-bottom: 0;
}

.admin-settings-panel summary::after {
  content: "Edit";
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.admin-settings-panel[open] summary {
  margin-bottom: 16px;
}

.admin-settings-panel[open] summary::after {
  content: "Close";
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 6px 10px;
  background: #e4f4ee;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 850;
}

.badge-warning {
  background: #fff3df;
  color: var(--amber);
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.site-list,
.snapshot-list,
.plain-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-row,
.list-row {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.snapshot-button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.snapshot-button.active {
  border-color: rgba(13, 122, 108, 0.45);
  background: #eef8f4;
}

.backup-job {
  cursor: default;
}

.backup-job.is-active {
  border-color: rgba(13, 122, 108, 0.45);
  background: #f4fbf8;
}

.backup-job.is-failed {
  border-color: rgba(185, 74, 63, 0.28);
  background: #fff8f6;
}

.backup-job-row {
  align-items: flex-start;
}

.job-row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: right;
}

.job-detail-panel {
  display: grid;
  gap: 14px;
  margin: 14px 0;
  padding: 16px;
  border: 1px solid rgba(13, 122, 108, 0.24);
  border-radius: 8px;
  background: #f7fbf9;
}

.job-detail-panel[hidden] {
  display: none;
}

.activity-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(13, 122, 108, 0.18);
  border-radius: 8px;
  background: #f7fbf9;
}

.activity-history-card {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.activity-history-section h2,
.settings-stack h2 {
  margin-bottom: 0;
}

.preference-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.activity-panel-header,
.pager-controls,
.activity-row,
.activity-row-meta {
  display: flex;
  align-items: center;
}

.activity-panel-header {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.activity-panel-header h2,
.activity-panel-header h3 {
  margin-bottom: 0;
}

.pager-controls {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.activity-row {
  width: 100%;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.activity-row > div:first-child {
  display: grid;
  gap: 3px;
}

.activity-row-meta {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  text-align: right;
}

.activity-row.is-active {
  border-color: rgba(13, 122, 108, 0.45);
  background: #f4fbf8;
}

.activity-row.is-failed {
  border-color: rgba(185, 74, 63, 0.28);
  background: #fff8f6;
}

.backup-progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce8e2;
}

.backup-progress span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  animation: backup-progress 1.3s ease-in-out infinite alternate;
}

@keyframes backup-progress {
  from {
    transform: translateX(-35%);
  }
  to {
    transform: translateX(160%);
  }
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--soft);
  color: var(--muted);
  font-size: 0.84rem;
}

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

@media (max-width: 860px) {
  .grid-2,
  .dashboard-grid,
  .admin-grid,
  .settings-stack,
  .grid-3,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .restore-options {
    grid-template-columns: 1fr;
  }

  .activity-panel-header,
  .activity-row,
  .table-toolbar,
  .pairing-code-row,
  .admin-settings-panel summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .activity-row-meta,
  .pager-controls {
    justify-content: flex-start;
    text-align: left;
  }

  .job-row-actions {
    align-items: flex-start;
    flex-direction: column;
    text-align: left;
  }

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

  .table-toolbar input {
    max-width: none;
  }

  .card-header,
  .metric-row,
  .site-row,
  .list-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .button {
    width: 100%;
  }
}
