:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1a1a1c;
  --muted: #6b6b73;
  --border: #e8e8ec;
  --accent: #111111;
  --accent-hover: #2d2d32;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 48px 24px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}

.brand {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand span {
  color: var(--muted);
  font-weight: 500;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.card + .card {
  margin-top: 20px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9375rem;
  margin: 0 0 24px;
}

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fafafa;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: #ccc;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
  background: #fff;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.row > * {
  flex: 1;
  min-width: 140px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: #fafafa;
  color: var(--text);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f0d4d0;
}

.btn-danger:hover {
  background: #fdf5f4;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.875rem;
}

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.875rem;
  margin-bottom: 20px;
}

.alert-error {
  background: #fdf5f4;
  color: #8b2e24;
  border: 1px solid #f0d4d0;
}

.alert-ok {
  background: #f4faf6;
  color: #1e5631;
  border: 1px solid #d4eadb;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

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

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

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

.slug {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.875rem;
  background: #f3f3f5;
  padding: 4px 8px;
  border-radius: 6px;
}

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

.meta-pill {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--muted);
  background: #f3f3f5;
  padding: 4px 10px;
  border-radius: 999px;
}

.public-url {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding: 14px 16px;
  background: #fafafa;
  border-radius: 10px;
  border: 1px dashed var(--border);
}

.public-url code {
  font-size: 0.875rem;
  word-break: break-all;
}

.checkbox-cell {
  width: 40px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.limit-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.limit-form input[type="number"] {
  width: 72px;
  padding: 8px 10px;
}

.back {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 20px;
  display: inline-block;
}

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

/* Loading screen */
.loading-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #ffffff 0%, #f5f5f7 100%);
  padding: 24px;
}

.loading-card {
  text-align: center;
  max-width: 360px;
}

.loading-card p {
  font-size: 1.125rem;
  font-weight: 500;
  color: #3a3a40;
  margin: 24px 0 0;
  letter-spacing: -0.01em;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid #ececef;
  border-top-color: #b8b8c0;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  margin: 0 auto;
}

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

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-wrap .card {
  width: 100%;
  max-width: 400px;
}

textarea {
  resize: vertical;
  min-height: 120px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8125rem;
  line-height: 1.45;
}

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

.visually-hidden-form {
  display: none;
}

.tg-loading-body {
  margin: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.tg-loading-screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--tg-bg, linear-gradient(180deg, #ffffff 0%, #f5f5f7 100%));
}

.tg-loading-screen .loading-card p {
  color: var(--tg-text, #3a3a40);
}

.tg-loading-screen .spinner {
  border-top-color: var(--tg-accent, #b8b8c0);
}

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

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-box {
  padding: 16px 14px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-card {
  margin-bottom: 20px;
}

.health-cell {
  min-width: 88px;
  vertical-align: middle;
}

.health-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: help;
}

.health-ok {
  background: #e8f5ec;
  color: #1e5631;
}

.health-frozen {
  background: #e8f0fa;
  color: #1a4d7a;
}

.health-blocked {
  background: #fdecea;
  color: #8b2e24;
}

.health-warn {
  background: #fff8e6;
  color: #7a5c00;
}

.health-error {
  background: #f3f3f5;
  color: #5c5c66;
}

.health-unknown {
  background: #f3f3f5;
  color: var(--muted);
}

.health-time {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 4px;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.admin-nav .back {
  margin-bottom: 0;
}

.nav-sep {
  color: var(--border);
}

.nav-current {
  font-size: 0.875rem;
  color: var(--muted);
}

.trigger-pill {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text);
  background: #eef0f4;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.log-table td.log-time {
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--muted);
}

.log-detail {
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.5;
  vertical-align: top;
}

.log-detail-main {
  display: block;
  color: var(--text);
  word-break: break-word;
}

.log-detail-sub {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ——— Admin layout v2 ——— */

.page-admin {
  background: linear-gradient(180deg, #f3f4f6 0%, var(--bg) 120px);
}

.shell-wide {
  max-width: 1080px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.admin-header-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-link {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.brand-link:hover {
  opacity: 0.85;
}

.brand-sub {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
}

.admin-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.admin-tab {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.admin-tab:hover {
  color: var(--text);
  background: #f5f5f7;
}

.admin-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.admin-tab.is-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

.system-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  padding: 12px 16px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.system-strip-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.system-label {
  color: var(--muted);
  font-weight: 500;
}

.system-value {
  color: var(--text);
  font-weight: 500;
}

.system-value.muted {
  color: var(--muted);
  font-weight: 400;
}

.warn-text {
  color: #8b2e24;
}

.system-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.system-dot-ok {
  background: #2d8a4e;
}

.system-dot-bad {
  background: #c0392b;
}

.system-dot-muted {
  background: #c8c8d0;
}

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

.card-head .subtitle {
  margin-bottom: 0;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.subtitle--tight {
  margin-bottom: 12px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
}

.count-badge--soft {
  background: #eef0f4;
  color: var(--text);
  font-weight: 500;
}

.empty-state {
  margin: 0;
  padding: 20px 0 8px;
  color: var(--muted);
  font-size: 0.9375rem;
}

.inline-code {
  font-family: ui-monospace, monospace;
  font-size: 0.875em;
  background: #f3f3f5;
  padding: 2px 6px;
  border-radius: 4px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.form-stack label + input,
.form-stack label + textarea {
  margin-bottom: 12px;
}

.form-actions {
  margin-top: 4px;
}

.row-action {
  flex: 0 0 auto;
  min-width: auto;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.alert-warn {
  background: #fff8e6;
  color: #6b4e00;
  border: 1px solid #f0e0a8;
}

.input-mono {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
}

textarea:focus {
  outline: none;
  border-color: #ccc;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
  background: #fff;
}

.public-url-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.public-url-bar-inner {
  flex: 1;
  min-width: 0;
}

.public-url-label {
  display: block;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.public-url-code {
  display: block;
  font-size: 0.875rem;
  word-break: break-all;
  line-height: 1.4;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.grid-2 .card {
  margin-top: 0;
}

.info-panel {
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.info-panel summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
  user-select: none;
}

.info-panel p {
  margin: 10px 0 0;
  line-height: 1.55;
}

.data-table tbody tr:nth-child(even) {
  background: #fafafb;
}

.data-table tbody tr.row-muted {
  opacity: 0.72;
}

.table-wrap--rounded {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.table-wrap--sticky thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5f5f7;
  box-shadow: 0 1px 0 var(--border);
}

.table-wrap--sticky {
  max-height: min(520px, 60vh);
  overflow: auto;
}

.col-narrow {
  width: 72px;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
}

.col-time {
  width: 88px;
}

.col-trigger {
  width: 140px;
}

.col-status {
  width: 100px;
}

.col-bot {
  min-width: 120px;
  max-width: 220px;
}

.col-detail {
  min-width: 200px;
}

.cell-mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8125rem;
  word-break: break-all;
  vertical-align: top;
}

.cell-url {
  max-width: 280px;
}

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

.text-link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.progress-pill {
  display: inline-block;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  background: #eef0f4;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.progress-sep {
  color: var(--muted);
  margin: 0 1px;
}

.health-badge {
  font-size: 0.6875rem;
  white-space: nowrap;
}

.trigger-auto {
  background: #e8f0fa;
  color: #1a4d7a;
}

.trigger-manual {
  background: #fff3e0;
  color: #7a4d00;
}

.trigger-on_add {
  background: #e8f5ec;
  color: #1e5631;
}

.trigger-probe {
  background: #f3e8ff;
  color: #5c3d7a;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fafafa;
}

.result-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.result-label {
  font-size: 0.8125rem;
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.result-meta {
  margin: 0;
  display: grid;
  gap: 10px;
}

.result-meta dt {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.result-meta dd {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text);
}

.result-detail-text {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.stat-box--accent {
  background: linear-gradient(135deg, #fafafa 0%, #f0f0f4 100%);
  border-color: #ddd;
}

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

.page-login .login-card {
  max-width: 400px;
  width: 100%;
}

.login-brand {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-title {
  font-size: 1.375rem;
  margin: 0 0 4px;
}

@media (max-width: 640px) {
  .shell {
    padding: 24px 16px 48px;
  }

  .admin-header {
    flex-direction: column;
  }

  .admin-logout {
    align-self: flex-end;
  }

	.table-wrap--sticky {
	    max-height: none;
	  }

	  th,
	  td {
	    padding: 10px 8px;
	  }
	}

	.system-strip-item--toggle {
	  flex: 1.4;
	  min-width: 220px;
	  align-items: center;
	  flex-wrap: wrap;
	  gap: 8px 12px;
	}

	.system-value--stack {
	  display: flex;
	  flex-direction: column;
	  gap: 2px;
	  align-items: flex-start;
	}

	.system-sub {
	  font-size: 0.6875rem;
	  color: var(--muted);
	  font-weight: 400;
	  line-height: 1.35;
	  max-width: 420px;
	}

	.toggle-switch {
	  position: relative;
	  display: inline-flex;
	  width: 44px;
	  height: 26px;
	  flex-shrink: 0;
	}

	.toggle-switch input {
	  opacity: 0;
	  width: 0;
	  height: 0;
	  position: absolute;
	}

	.toggle-slider {
	  position: absolute;
	  inset: 0;
	  background: #c8cad0;
	  border-radius: 999px;
	  transition: background 0.2s;
	  cursor: pointer;
	}

	.toggle-slider::before {
	  content: "";
	  position: absolute;
	  width: 20px;
	  height: 20px;
	  left: 3px;
	  top: 3px;
	  background: #fff;
	  border-radius: 50%;
	  transition: transform 0.2s;
	  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
	}

	.toggle-switch input:checked + .toggle-slider {
	  background: #2e7d4a;
	}

	.toggle-switch input:checked + .toggle-slider::before {
	  transform: translateX(18px);
	}

	.toggle-switch input:disabled + .toggle-slider {
	  opacity: 0.6;
	  cursor: wait;
	}

	.admin-toast {
	  position: sticky;
	  top: 12px;
	  z-index: 20;
	  margin-bottom: 12px;
	  padding: 12px 16px;
	  border-radius: 10px;
	  font-size: 0.875rem;
	  font-weight: 500;
	  box-shadow: var(--shadow);
	}

	.admin-toast--ok {
	  background: #e8f5ec;
	  color: #1e5631;
	  border: 1px solid #c5e6d0;
	}

	.admin-toast--error {
	  background: #fdecea;
	  color: #8b2e24;
	  border: 1px solid #f5c4be;
	}

	.admin-ajax-form.is-busy {
	  opacity: 0.72;
	  pointer-events: none;
	}

	.rotation-current {
	  display: flex;
	  flex-wrap: wrap;
	  align-items: center;
	  gap: 10px 14px;
	  margin-bottom: 16px;
	  padding: 12px 16px;
	  border-radius: 10px;
	  background: var(--surface);
	  border: 1px solid var(--border);
	  box-shadow: var(--shadow);
	}

	.rotation-current-label {
	  font-size: 0.8125rem;
	  color: var(--muted);
	  font-weight: 500;
	}

	.rotation-current-url {
	  font-size: 0.875rem;
	  word-break: break-all;
	}

	.data-table tbody tr.row-current {
	  background: rgba(46, 125, 50, 0.1) !important;
	}

	.data-table tbody tr.row-disabled {
	  opacity: 0.88;
	}

	.current-marker {
	  color: #2e7d32;
	  font-weight: 700;
	  margin-left: 4px;
	}

	.rotation-off-badge {
	  display: inline-block;
	  margin-left: 6px;
	  padding: 2px 6px;
	  border-radius: 4px;
	  font-size: 0.6875rem;
	  font-weight: 600;
	  text-transform: uppercase;
	  letter-spacing: 0.02em;
	  background: #fff3e0;
	  color: #e65100;
	}

	.rotation-off-reason {
	  display: block;
	  max-width: 280px;
	  white-space: nowrap;
	  overflow: hidden;
	  text-overflow: ellipsis;
	}

