:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar: #0f172a;
  --sidebar-2: #111c33;
  --sidebar-text: #cbd5e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 0.6rem;
  line-height: 1.25;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
  margin-top: 1.2rem;
}

p {
  margin: 0.4rem 0 0.8rem;
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

code {
  background: #eef2ff;
  color: #3730a3;
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
}

pre {
  margin: 0.5rem 0;
  padding: 0.85rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.45;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  padding: 0 8px 20px;
}

.brand span {
  color: #60a5fa;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  color: var(--sidebar-text);
  padding: 9px 10px;
  border-radius: 8px;
  font-weight: 500;
}

.nav a:hover {
  background: var(--sidebar-2);
  text-decoration: none;
  color: #fff;
}

.nav a.active {
  background: #1d4ed8;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e2e8f0;
  font-weight: 600;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.link-button {
  background: none;
  border: 0;
  color: #93c5fd;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 60px;
}

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

.page-header p {
  margin: 0;
}

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

.small {
  font-size: 12px;
}

.nowrap {
  white-space: nowrap;
}

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

.card h2:first-child,
.card h3:first-child {
  margin-top: 0;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  margin: 0;
  padding: 16px 18px;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 6px;
}

.stat-error .stat-value {
  color: var(--danger);
}

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 7px 14px;
  margin: 0;
}

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

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.kv.compact {
  grid-template-columns: 170px minmax(0, 1fr);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

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

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: var(--surface-2);
}

.actions-cell {
  text-align: right;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-ok {
  background: #dcfce7;
  color: #166534;
}

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

.badge-muted {
  background: #e2e8f0;
  color: #475569;
}

.badge-admin {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-user {
  background: #e0f2fe;
  color: #075985;
}

.badge-pending,
.badge-queued {
  background: #fef3c7;
  color: #92400e;
}

.badge-dry {
  background: #fae8ff;
  color: #86198f;
}

.flash {
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.flash-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.flash-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.flash-info {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

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

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

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

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

.btn-ghost {
  background: transparent;
}

.btn-small {
  padding: 5px 9px;
  font-size: 12px;
}

.btn:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.form label {
  display: block;
  margin-bottom: 12px;
  font-weight: 600;
}

.form input,
.form select,
.form textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--primary);
}

.form textarea {
  resize: vertical;
  min-height: 64px;
}

.form .checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.form .checkbox input {
  width: auto;
  margin: 0;
}

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

.hint {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  margin-top: 4px;
}

.form-card {
  max-width: 820px;
}

.danger-zone {
  border-color: #fecaca;
  background: #fffafa;
}

.danger-zone h2 {
  color: var(--danger);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
}

.filters input,
.filters select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.filters input {
  min-width: 280px;
  flex: 1;
}

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

.help-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 14px 0;
}

.help-box p {
  margin: 0.4rem 0;
}

.link-box {
  background: #f1f5f9;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0 14px;
  overflow-wrap: anywhere;
}

.small-pre {
  max-height: 260px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-input {
  flex: 1;
  min-width: 240px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.console-output {
  max-height: 620px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.login-wrap,
.error-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card,
.error-card {
  width: 100%;
  max-width: 420px;
  padding: 28px;
}

.error-card {
  text-align: center;
}

.error-status {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 8px;
}

details summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}

details[open] summary {
  margin-bottom: 6px;
}

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    padding: 14px 16px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-footer {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .main {
    padding: 20px 16px 50px;
  }

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

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

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

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

  .kv dt {
    margin-top: 6px;
  }

  .filters input {
    min-width: 0;
  }
}
