:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #d9e1ea;
  --brand: #258255;
  --brand-hover: #1d6944;
  --brand-dark: #185a3a;
  --brand-soft: #e9f5ee;
  --on-brand: #ffffff;
  --green: #16803c;
  --green-bg: #e8f6ee;
  --amber: #8a5a00;
  --amber-bg: #fff4d6;
  --red: #b42318;
  --red-bg: #ffe7e4;
  --blue-bg: #eaf1ff;
  --focus: rgba(37, 130, 85, 0.22);
  --chat-bg: #eef1f5;
  --shadow: 0 8px 26px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 72px rgba(15, 23, 42, 0.22);
}

body[data-theme="dark"] {
  --bg: #0b1120;
  --panel: #121a2b;
  --panel-soft: #1b2638;
  --text: #dce5ef;
  --muted: #9eafc4;
  --line: #35445a;
  --brand: #49b879;
  --brand-hover: #61ca8d;
  --brand-dark: #bcebd0;
  --brand-soft: #18382a;
  --on-brand: #07140d;
  --green: #74e29a;
  --green-bg: #123c27;
  --amber: #ffd166;
  --amber-bg: #443414;
  --red: #ff8b9a;
  --red-bg: #4b1e29;
  --blue-bg: #18345f;
  --focus: rgba(73, 184, 121, 0.3);
  --chat-bg: #0e1625;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable", "Segoe UI", Inter, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button {
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  touch-action: manipulation;
}

button:not(:disabled):hover {
  cursor: pointer;
  filter: none;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.sidebar {
  display: none;
  background: #111827;
  color: #e5e7eb;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 8px;
}

.brand-sub {
  color: #9ca3af;
  font-size: 13px;
  margin-bottom: 26px;
}

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

.nav a,
.nav span {
  display: block;
  padding: 11px 12px;
  border-radius: 8px;
  color: #cbd5e1;
}

.nav a.active,
.nav span.active {
  background: #253044;
  color: #fff;
  font-weight: 700;
}

.content {
  min-width: 0;
  padding: 24px;
}

.auth-page {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
  padding: 24px 0;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.14);
  padding: 28px;
  display: grid;
  gap: 18px;
}

.wide-auth-card {
  width: min(760px, 100%);
}

.auth-card h1 {
  margin: 6px 0 8px;
  font-size: 30px;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.auth-form,
.load-error-card {
  display: grid;
  gap: 14px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  min-height: 44px;
}

.activation-card {
  width: min(520px, 100%);
  border-radius: 8px;
}

.activation-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 24px;
  font-weight: 900;
}

.password-requirements {
  margin-top: -4px;
  color: var(--muted);
  font-size: 13px;
}

.activation-logout {
  width: 100%;
  justify-content: center;
}

.temporary-credentials {
  display: grid;
  gap: 10px;
}

.credential-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1.3fr);
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
}

.credential-row span {
  color: var(--muted);
}

.credential-row strong,
.credential-row a {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.credential-row a {
  color: var(--brand);
  text-decoration: underline;
}

@media (max-width: 560px) {
  .credential-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  animation: myuchet-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 0;
}

h2 {
  font-size: 18px;
  margin: 0 0 14px;
}

h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.userbox {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}

.userbox strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 4px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

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

.metric {
  display: grid;
  gap: 8px;
}

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

.metric-value {
  font-size: 26px;
  font-weight: 800;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.green {
  background: var(--green-bg);
  color: var(--green);
}

.pill.amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.pill.red {
  background: var(--red-bg);
  color: var(--red);
}

.pill.blue {
  background: var(--blue-bg);
  color: var(--brand-dark);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

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

.btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn.secondary {
  border-color: var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.btn.success {
  background: var(--brand);
  color: var(--on-brand);
}

.btn.danger {
  background: var(--red);
  color: #ffffff;
}

.btn:not(:disabled):hover,
.btn.success:not(:disabled):hover {
  background: var(--brand-hover);
  box-shadow: 0 6px 16px var(--focus);
}

.btn.secondary:not(:disabled):hover {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: var(--brand-soft);
  color: var(--brand-dark);
  box-shadow: none;
}

.btn.danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--red) 86%, #000);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--red) 22%, transparent);
}

.btn.is-loading::before {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: myuchet-spin 0.7s linear infinite;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  min-width: 780px;
}

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

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

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

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

.amount {
  font-weight: 800;
  white-space: nowrap;
}

.split {
  display: grid;
  grid-template-columns: 1.35fr 0.85fr;
  gap: 16px;
}

.section {
  margin-top: 16px;
}

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

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

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

.progress {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--brand);
}

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

.form-divider {
  grid-column: 1 / -1;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
}

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

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
  background: var(--panel);
  color: var(--text);
}

.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
  outline: 0;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.mobile-cards {
  display: none;
}

.mobile-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 13px;
  display: grid;
  gap: 8px;
}

.mobile-row .pair {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
}

.mobile-row .pair strong {
  color: var(--text);
  text-align: right;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal-backdrop.open {
  display: flex;
}

body.modal-open,
body.menu-open,
body.page-editor-open {
  overflow: hidden;
}

.modal {
  width: min(760px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  animation: modal-pop 0.16s ease-out;
}

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

.modal.wide {
  width: min(1180px, 100%);
}

.modal-head {
  position: sticky;
  top: 0;
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
  z-index: 2;
}

.modal-title {
  font-size: 19px;
  font-weight: 800;
}

.modal-body {
  padding: 18px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  background: var(--panel-soft);
}

.icon-btn {
  border: 0;
  background: #e2e8f0;
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
  cursor: default;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: auto;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: 0.18s ease;
  z-index: 200;
  max-width: 360px;
}

body[data-theme="dark"] .toast {
  background: #e5edf8;
  color: #0f172a;
}

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

.hint-box {
  background: var(--blue-bg);
  border: 1px solid #c7d7fe;
  color: var(--brand-dark);
  border-radius: 9px;
  padding: 12px;
  margin-bottom: 12px;
}

.landing {
  min-height: 100vh;
  padding: 28px;
  display: grid;
  place-items: center;
}

.landing-card {
  width: min(980px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.landing-links {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.landing-links a {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel-soft);
}

.landing-links strong {
  display: block;
  margin-bottom: 6px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .grid.cols-4,
  .grid.cols-3,
  .grid.cols-2,
  .split {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .content,
  .landing {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

  .userbox {
    text-align: left;
  }

  h1 {
    font-size: 23px;
  }

  .card {
    padding: 14px;
  }

  .desktop-table {
    display: none;
  }

  .mobile-cards {
    display: grid;
    gap: 10px;
  }

  .form-grid,
  .landing-links,
  .nav {
    grid-template-columns: 1fr;
  }

  .modal-foot {
    display: grid;
  }
}
