:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #151821;
  --surface-raised: #1b1f2a;
  --surface-soft: #202634;
  --surface-warm: #231f1b;
  --line: #2b3240;
  --line-strong: #3b4454;
  --text: #eef1f6;
  --text-muted: #a8b0bd;
  --text-soft: #737d8c;
  --primary: #5ee0a0;
  --primary-strong: #33c97f;
  --primary-soft: rgba(94, 224, 160, 0.14);
  --accent: #f2c166;
  --accent-soft: rgba(242, 193, 102, 0.13);
  --danger: #ff6b7a;
  --danger-soft: rgba(255, 107, 122, 0.14);
  --warning: #e6b450;
  --info: #70a7ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 10px 28px rgba(0, 0, 0, 0.2);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(94, 224, 160, 0.08), transparent 30rem),
    radial-gradient(circle at bottom right, rgba(242, 193, 102, 0.06), transparent 34rem),
    linear-gradient(180deg, #12151b 0%, var(--bg) 38rem);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--space-6);
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  padding: var(--space-8);
  background: color-mix(in srgb, var(--surface-raised) 94%, black);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.brand-lockup,
.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-lockup {
  margin-bottom: var(--space-8);
}

.brand-mark {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  background: var(--primary-soft);
  border: 1px solid rgba(94, 224, 160, 0.28);
  border-radius: var(--radius-md);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.brand-lockup h1,
.sidebar-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-lockup p,
.sidebar-header p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.author-link {
  display: inline-flex;
  margin-top: var(--space-1);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.author-link:hover {
  color: var(--primary-strong);
  text-decoration: underline;
}

.login-form {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-2);
}

.field label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 650;
}

.field input,
.form-grid input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 var(--space-3);
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.field input:hover,
.form-grid input:hover {
  border-color: var(--line-strong);
}

.field input:focus,
.form-grid input:focus {
  background: #11161f;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  outline: 0;
}

.error,
.message {
  min-height: 20px;
  margin-top: var(--space-3);
  color: var(--danger);
  font-size: 13px;
}

.message {
  color: var(--text-muted);
}

.app {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--space-5);
  background: rgba(15, 17, 21, 0.86);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.sidebar-header {
  min-height: 56px;
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--line);
}

.nav-list {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 42px;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 650;
  text-align: left;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item:active {
  transform: translateY(1px);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-icon {
  display: inline-grid;
  width: 26px;
  height: 26px;
  place-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}

.nav-item.active .nav-icon {
  border-color: rgba(94, 224, 160, 0.36);
  color: var(--primary);
}

.main {
  min-width: 0;
  padding: var(--space-6);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 72px;
  margin-bottom: var(--space-6);
  padding: var(--space-5);
  background: rgba(27, 31, 42, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 var(--space-1);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  color: var(--text);
  font-size: 26px;
  font-weight: 760;
  line-height: 1.1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: var(--space-5);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.metric-card,
.panel {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.metric-card {
  display: flex;
  min-height: 132px;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-6);
}

.metric-label {
  margin: 0 0 var(--space-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 650;
}

.metric-value {
  display: block;
  color: var(--text);
  font-size: 42px;
  font-weight: 780;
  line-height: 1;
}

.metric-compact {
  font-size: clamp(20px, 3vw, 34px);
}

.metric-domain {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(18px, 2.5vw, 30px);
  line-height: 1.15;
}

.metric-chip {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.panel {
  padding: var(--space-5);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.panel-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
}

.panel-header p {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.status-badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 750;
}

.status-badge span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 14%, transparent);
}

.status-running {
  border-color: rgba(94, 224, 160, 0.34);
  background: var(--primary-soft);
  color: var(--primary);
}

.status-stopped {
  border-color: rgba(255, 107, 122, 0.34);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-muted {
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-block {
  width: 100%;
}

.btn-inline {
  width: auto;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #08130e;
}

.btn-primary:hover {
  background: var(--primary-strong);
  box-shadow: 0 10px 24px rgba(51, 201, 127, 0.18);
}

.btn-secondary {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--line-strong);
  background: #262d3b;
}

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(255, 107, 122, 0.3);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 107, 122, 0.2);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: var(--space-4);
  align-items: end;
}

.settings-form,
.dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.settings-summary {
  display: grid;
  grid-column: 1 / -1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.settings-summary div {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-4);
  background: #161b24;
  border-bottom: 1px solid var(--line);
}

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

.settings-summary span {
  color: var(--text-muted);
  font-weight: 650;
}

.settings-summary strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 650;
  word-break: break-word;
}

.settings-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.form-actions {
  display: flex;
  gap: var(--space-2);
}

.users-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 48px;
  margin-bottom: var(--space-4);
  padding: 0 var(--space-4);
  background: #141922;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.users-toolbar div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.users-toolbar span,
.migration-note {
  color: var(--text-muted);
  font-size: 13px;
}

.users-toolbar strong {
  color: var(--primary);
  font-size: 13px;
}

.users-list {
  display: grid;
  gap: var(--space-3);
}

.user-row {
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(220px, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  min-height: 92px;
  padding: var(--space-4);
  background: #161b24;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.user-row:hover {
  background: #19202b;
  border-color: var(--line-strong);
}

.user-row.is-disabled {
  background: rgba(22, 27, 36, 0.62);
}

.user-main {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-3);
}

.user-avatar {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.user-identity {
  min-width: 0;
}

.user-title-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.user-title-line h3 {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 15px;
  font-weight: 760;
  line-height: 1.2;
}

.user-identity p {
  margin: var(--space-1) 0 0;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 13px;
}

.user-link {
  display: block;
  min-width: 0;
  overflow: hidden;
  padding: var(--space-3);
  background: #0f131a;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: #c5d0df;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-actions {
  justify-content: flex-end;
  min-width: 340px;
}

.migration-note {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #161b24;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

td {
  color: var(--text);
}

.row-subtle {
  display: block;
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 500;
}

.empty-state {
  height: 96px;
  color: var(--text-muted);
  text-align: center;
}

.user-status {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
}

.user-status.enabled {
  border-color: rgba(94, 224, 160, 0.32);
  background: var(--primary-soft);
  color: var(--primary);
}

.user-status.disabled {
  border-color: rgba(255, 107, 122, 0.3);
  background: var(--danger-soft);
  color: var(--danger);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.actions .btn {
  min-height: 34px;
  padding: 0 var(--space-3);
  font-size: 13px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.config-card {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  background: #161b24;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.config-card.disabled {
  opacity: 0.64;
}

.config-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.config-card h3 {
  margin: 0;
  font-size: 16px;
}

.config-card p {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.qr-frame {
  display: grid;
  place-items: center;
  padding: var(--space-3);
  background: #fff;
  border-radius: var(--radius-sm);
}

.qr-frame img {
  width: 180px;
  height: 180px;
  image-rendering: pixelated;
}

.config-link,
.config-output textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: var(--space-3);
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: #c5d0df;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.check-field {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: var(--space-2);
  align-self: end;
  color: var(--text-muted);
  font-weight: 650;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.logs-container {
  overflow: auto;
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: #c5d0df;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.logs-large {
  height: calc(100vh - 188px);
  min-height: 420px;
  padding: var(--space-4);
}

.log-line {
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
}

.service-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.service-output {
  min-height: 140px;
  margin: 0;
  padding: var(--space-4);
  overflow: auto;
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: #c5d0df;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.settings-list {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.user-dialog {
  width: min(760px, calc(100vw - 32px));
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text);
}

.user-dialog::backdrop {
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(6px);
}

.dialog-card {
  padding: var(--space-5);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.config-output {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.config-output img {
  width: 220px;
  height: 220px;
  padding: var(--space-3);
  background: #fff;
  border-radius: var(--radius-sm);
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: var(--space-4);
}

.settings-list div {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-4);
  border-bottom: 1px solid var(--line);
  background: #161b24;
}

.settings-list div:nth-child(even) {
  background: #141922;
}

.settings-list div:last-child {
  border-bottom: 0;
}

.settings-list span {
  color: var(--text-muted);
  font-weight: 650;
}

.settings-list strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
  word-break: break-word;
}

.toast-region {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 50;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  gap: var(--space-3);
}

.toast {
  padding: var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
}

.toast.success {
  border-color: rgba(94, 224, 160, 0.36);
}

.toast.error {
  border-color: rgba(255, 107, 122, 0.4);
}

@media (max-width: 1040px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: var(--space-4);
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
  }

  .nav-icon,
  .sidebar-header p {
    display: none;
  }

  .main {
    padding: var(--space-4);
  }
}

@media (max-width: 760px) {
  body {
    font-size: 13px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: space-between;
  }

  .stats-grid,
  .form-grid,
  .user-row,
  .settings-form,
  .dialog-grid,
  .config-output {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .service-actions,
  .panel-actions,
  .users-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .user-actions {
    min-width: 0;
    justify-content: stretch;
  }

  .user-link {
    white-space: normal;
  }

  .btn,
  .btn-inline {
    width: 100%;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .nav-item {
    justify-content: flex-start;
  }

  .metric-card {
    min-height: 112px;
  }

  .metric-value {
    font-size: 34px;
  }

  .settings-list div {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .settings-summary div {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .settings-list strong {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
