:root {
  --bg: #0b1220;
  --bg-soft: #0f182a;
  --panel: #131d31;
  --panel-2: #17233a;
  --line: #24324c;
  --text: #e9eefc;
  --muted: #93a4c3;
  --accent: #5b93ff;
  --accent-2: #2f6fe4;
  --ok: #35c58d;
  --warn: #f0a92e;
  --danger: #ef5a5a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0 0 0.4rem;
  line-height: 1.2;
  font-weight: 650;
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.95rem;
}

p {
  margin: 0 0 0.6rem;
}

code,
pre,
textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.subtle {
  color: var(--muted);
  font-size: 0.85rem;
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(91, 147, 255, 0.18), transparent 60%),
    radial-gradient(700px 400px at 110% 10%, rgba(53, 197, 141, 0.12), transparent 55%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 22px;
}

.auth-card h1 {
  font-size: 1.5rem;
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 1rem;
  outline: none;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 147, 255, 0.25);
}

textarea {
  resize: vertical;
  min-height: 180px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  min-height: 42px;
}

.btn:hover {
  border-color: #35507a;
  background: #1c2a45;
}

.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: rgba(239, 90, 90, 0.5);
  color: #ffb4b4;
}

.btn.small {
  padding: 6px 10px;
  min-height: 34px;
  font-size: 0.8rem;
}

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

.message {
  min-height: 1.2rem;
  margin: 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.message.ok {
  color: var(--ok);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  color: #fff;
  flex: none;
}

.brand-name {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-name {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: none;
  gap: 6px;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}

main {
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
  max-width: 1180px;
  margin: 0 auto;
}

.view[hidden] {
  display: none !important;
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px;
}

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.card .label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.metric {
  font-size: 1.45rem;
  font-weight: 750;
  line-height: 1.1;
}

.metric small {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg-soft);
  white-space: nowrap;
}

.badge.ok {
  color: #9ff0ce;
  border-color: rgba(53, 197, 141, 0.35);
  background: rgba(53, 197, 141, 0.1);
}

.badge.warn {
  color: #ffdc9e;
  border-color: rgba(240, 169, 46, 0.35);
  background: rgba(240, 169, 46, 0.1);
}

.badge.bad {
  color: #ffb4b4;
  border-color: rgba(239, 90, 90, 0.35);
  background: rgba(239, 90, 90, 0.1);
}

progress {
  width: 100%;
  height: 8px;
  appearance: none;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-soft);
}

progress::-webkit-progress-bar {
  background: var(--bg-soft);
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent), #7a5cff);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.progress-row {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.progress-row .line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 560px;
}

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

th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

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

td.mono,
th.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.nowrap {
  white-space: nowrap;
}

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

.docitem {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.docitem.active {
  border-color: var(--accent);
  background: rgba(91, 147, 255, 0.1);
}

.docitem .title {
  font-weight: 650;
  font-size: 0.9rem;
}

.docitem .meta {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 2px;
}

.docs-layout {
  display: grid;
  gap: 14px;
}

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

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

.editor-title {
  font-weight: 700;
  font-size: 0.95rem;
  word-break: break-word;
}

textarea.editor {
  min-height: 46vh;
  font-size: 0.88rem;
  line-height: 1.55;
}

.md-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--bg-soft);
  min-height: 200px;
  overflow-wrap: anywhere;
}

.md-preview h1,
.md-preview h2,
.md-preview h3 {
  margin-top: 1rem;
}

.md-preview pre {
  overflow: auto;
  background: #0a101c;
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 10px;
}

.md-preview code {
  background: #0a101c;
  padding: 2px 5px;
  border-radius: 5px;
}

.md-preview pre code {
  background: transparent;
  padding: 0;
}

.md-preview table {
  min-width: 0;
}

.md-preview blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.6rem 0;
  padding: 0.2rem 0 0.2rem 0.8rem;
  color: var(--muted);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.note {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(15, 24, 42, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.bottom-nav button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 650;
  padding: 7px 4px;
  border-radius: 9px;
  cursor: pointer;
}

.bottom-nav button.active {
  color: var(--text);
  background: var(--panel-2);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 7, 15, 0.7);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(760px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  padding: 14px;
  overflow: auto;
}

.modal-body pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  background: #1d2b45;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

.toast[hidden] {
  display: none;
}

.toast.ok {
  border-color: rgba(53, 197, 141, 0.45);
}

.toast.bad {
  border-color: rgba(239, 90, 90, 0.45);
}

.history-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (min-width: 860px) {
  .tabs {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  main {
    padding-bottom: 32px;
  }

  .docs-layout {
    grid-template-columns: 300px minmax(0, 1fr);
    align-items: start;
  }

  .doclist {
    max-height: 70vh;
    overflow: auto;
  }

  textarea.editor {
    min-height: 52vh;
  }

  .user-name {
    max-width: 180px;
  }
}
