:root {
  --bg: #f4f1eb;
  --bg-accent: #e6eef7;
  --surface: #ffffff;
  --surface-2: #f7f5f2;
  --surface-3: #f1f5f9;
  --text: #111827;
  --muted: #475467;
  --accent: #0f766e;
  --accent-strong: #0a5c55;
  --accent-warm: #ea580c;
  --danger: #b42318;
  --warning: #b45309;
  --success: #15803d;
  --border: rgba(17, 24, 39, 0.12);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.08);
  --focus: rgba(14, 116, 144, 0.35);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(14, 116, 144, 0.15), transparent 40%),
    radial-gradient(circle at 90% 6%, rgba(234, 88, 12, 0.14), transparent 38%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

h1, h2, h3 {
  font-family: 'Space Grotesk', 'IBM Plex Sans', sans-serif;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  padding: 28px 22px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-soft);
}

.brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-strong);
}

.sidebar-user {
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: 18px;
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.sidebar nav {
  display: grid;
  gap: 10px;
}

.sidebar nav a {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.sidebar nav a:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 118, 110, 0.25);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.12);
}

.main { min-height: 100vh; animation: pageIn 0.4s ease both; }
.main.with-sidebar { margin-left: 280px; padding: 36px 36px 60px; }
.main.centered { display: grid; place-items: center; padding: 32px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow-soft);
  animation: cardIn 0.45s ease both;
}

.grid { display: grid; gap: 20px; margin: 20px 0; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.top-align { align-items: start; }

.grid > .card:nth-child(2) { animation-delay: 0.04s; }
.grid > .card:nth-child(3) { animation-delay: 0.08s; }
.grid > .card:nth-child(4) { animation-delay: 0.12s; }

.stat-value { margin-top: 8px; font-size: 24px; font-weight: 700; word-break: break-word; }
.muted { color: var(--muted); }
.danger { color: var(--danger); }
.subtext { font-size: 12px; margin-top: 4px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #16a34a;
  color: #16a34a;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
  animation: pulse 1.6s ease-out infinite;
}

.status-dot.ok {
  background: #16a34a;
  color: #16a34a;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
}

.status-dot.warn {
  background: #f59e0b;
  color: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55);
}

.status-dot.down {
  background: #dc2626;
  color: #dc2626;
  box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55);
}

.flash {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: var(--surface-3);
}

.flash.success { border-color: rgba(21, 128, 61, 0.25); background: rgba(21, 128, 61, 0.08); }
.flash.error { border-color: rgba(180, 35, 24, 0.25); background: rgba(180, 35, 24, 0.08); }

.form-grid { display: grid; gap: 14px; }
.password-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.password-row input {
  flex: 1 1 220px;
}
label span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  background: var(--surface);
  color: var(--text);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 4px var(--focus);
}

.btn {
  border: 1px solid rgba(15, 118, 110, 0.35);
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--accent);
  color: #f8fafc;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: 0 10px 18px rgba(15, 118, 110, 0.16);
}

.btn:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
  box-shadow: 0 14px 26px rgba(15, 118, 110, 0.2);
}

.btn-primary {
  background: linear-gradient(180deg, #0f766e 0%, #0b5f57 100%);
  border-color: rgba(15, 118, 110, 0.5);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(15, 23, 42, 0.14);
  box-shadow: none;
}

.btn-warning {
  background: rgba(234, 88, 12, 0.15);
  color: #9a3412;
  border: 1px solid rgba(234, 88, 12, 0.35);
  box-shadow: none;
}

.btn-danger {
  background: rgba(180, 35, 24, 0.12);
  color: #7f1d1d;
  border: 1px solid rgba(180, 35, 24, 0.3);
  box-shadow: none;
}

.btn-success {
  background: rgba(21, 128, 61, 0.14);
  color: #0f4c2a;
  border: 1px solid rgba(21, 128, 61, 0.35);
  box-shadow: none;
}

.btn-success:hover {
  background: rgba(21, 128, 61, 0.2);
}

.btn-block { width: 100%; }
.btn-small { padding: 9px 12px; font-size: 13px; }
button[disabled] { opacity: 0.6; cursor: not-allowed; box-shadow: none; }

.table-wrap { overflow-x: auto; border-radius: 16px; }

table { width: 100%; border-collapse: collapse; }
table.users-table { table-layout: fixed; }
table.users-table td,
table.users-table th { vertical-align: middle; }
table.users-table td { word-break: break-word; }

thead {
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  vertical-align: top;
  font-size: 14px;
}

th {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #334155;
}

tbody tr:hover { background: rgba(15, 118, 110, 0.06); }

.sortable a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.sortable.active a { color: var(--accent-strong); }

.sort-indicator {
  font-size: 12px;
  opacity: 0.7;
}

.badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.12);
  color: #0f766e;
  font-size: 12px;
  font-weight: 600;
}

.badge.active { background: rgba(21, 128, 61, 0.12); color: #0f4c2a; }
.badge.blocked { background: rgba(180, 35, 24, 0.12); color: #7f1d1d; }
.badge.expired { background: rgba(234, 88, 12, 0.16); color: #9a3412; }

.inline-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  color: var(--accent-strong);
  font-weight: 600;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.table-actions .btn {
  min-width: 110px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.inline-form { margin: 0; }
.plain-list { padding-left: 18px; }
.guide-copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.guide-emphasis {
  color: #dc2626;
  font-weight: 700;
}

pre {
  overflow: auto;
  white-space: pre-wrap;
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

details.spoiler summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  margin-bottom: 12px;
}

details.spoiler summary::-webkit-details-marker {
  display: none;
}

details.spoiler summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s ease;
}

details.spoiler[open] summary::before {
  transform: rotate(90deg);
}

.logout-form { margin-top: auto; }

.toolbar-card,
.compact-card { padding: 16px 22px; }

.form-inline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.button-link {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.button-link[disabled] { color: var(--muted); cursor: not-allowed; }

.stacked-actions { gap: 10px; }

.popover {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
}

.popover-card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.menu-custom-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.menu-custom .btn-success { margin-top: 12px; }

.service-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.service-actions form {
  margin: 0;
}

.service-section h3 {
  margin-bottom: 10px;
}
.service-section + .service-section { margin-top: 14px; }
.service-note-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.service-note input { width: 100%; }

.chart-card .section-header { margin-bottom: 12px; }
.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.chart-tab {
  border: 1px solid rgba(15, 118, 110, 0.25);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chart-tab:hover {
  border-color: rgba(15, 118, 110, 0.5);
  color: var(--accent-strong);
}
.chart-tab.is-active {
  background: var(--accent);
  color: #f8fafc;
  border-color: rgba(15, 118, 110, 0.65);
  box-shadow: 0 8px 16px rgba(15, 118, 110, 0.18);
}
.chart-wrap {
  width: 100%;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(15, 23, 42, 0.02));
  padding: 12px;
  border: 1px solid rgba(15, 23, 42, 0.08);
}
#trafficChart {
  width: 100%;
  display: block;
}

.public-wrap {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

.public-language-switch {
  justify-self: end;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.lang-button {
  min-width: 48px;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

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

.public-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.public-identity {
  display: grid;
  gap: 4px;
}

.public-username {
  font-size: 22px;
  font-weight: 700;
}

.app-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.app-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
}

.app-icon svg {
  width: 18px;
  height: 18px;
}

.qr-import-card {
  overflow: hidden;
}

.qr-import-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 28px;
  align-items: center;
}

.qr-steps {
  display: grid;
  gap: 18px;
}

.qr-step {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.qr-panel {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(241, 245, 249, 0.9));
  border: 1px solid rgba(15, 118, 110, 0.14);
}

.qr-frame {
  display: grid;
  place-items: center;
  width: min(320px, 100%);
  aspect-ratio: 1;
  padding: 14px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: var(--shadow-soft);
}

.qr-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.qr-fallback {
  color: var(--muted);
  font-weight: 700;
}

.qr-caption {
  display: grid;
  gap: 2px;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.qr-caption strong {
  color: var(--text);
}

.qr-alternative {
  display: grid;
  gap: 12px;
}

.separator {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.separator::before,
.separator::after {
  content: '';
  height: 1px;
  background: rgba(15, 23, 42, 0.12);
}

.qr-action-row,
.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

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

.connection-item {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 112px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: var(--surface-2);
}

.connection-item > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.connection-item strong {
  word-break: break-word;
}

.copy-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.copy-status {
  font-size: 12px;
  color: var(--muted);
}

.guide-image {
  width: 100%;
  border-radius: 18px;
  border: 1px solid var(--border);
  margin-top: 14px;
  box-shadow: var(--shadow-soft);
}

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  width: min(760px, calc(100vw - 32px));
  z-index: 1;
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-actions { margin-top: 14px; }
textarea[readonly] { min-height: 140px; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 currentColor; }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (max-width: 1080px) {
  .cards-4, .cards-3, .cards-2 { grid-template-columns: 1fr; }
  .qr-import-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; width: auto; box-shadow: none; }
  .main.with-sidebar { margin-left: 0; padding: 24px; }
}

@media (max-width: 760px) {
  .form-inline-grid,
  .menu-custom-row,
  .connection-grid { grid-template-columns: 1fr; }
  .modal-header,
  .modal-actions,
  .section-header { flex-direction: column; align-items: stretch; }
  .main.centered { display: block; padding: 18px; }
  .public-language-switch { justify-self: stretch; justify-content: center; }
  .public-hero { flex-direction: column; align-items: stretch; }
  .qr-step { grid-template-columns: 1fr; }
  .qr-panel { padding: 12px; }
  .qr-frame { width: min(280px, 100%); }
  th { text-transform: none; letter-spacing: 0.02em; font-size: 12px; }
}
