:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --surface: #141a24;
  --surface-2: #1b2433;
  --border: #2a3548;
  --text: #e8edf5;
  --muted: #8b98ad;
  --accent: #5b9cff;
  --accent-dim: #3d6fb8;
  --danger: #f07178;
  --radius: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --btn-solid-fg: #0a0e14;
  --alert-err-border: #5c2d32;
  --alert-err-fg: #ffb4b9;
  --alert-ok-border: #2d4a3a;
  --alert-ok-fg: #9ddeb8;
  --modal-backdrop: rgba(6, 10, 16, 0.72);
  --modal-shadow: 0 20px 56px rgba(0, 0, 0, 0.55);
  --timeline-dot-ring: rgba(91, 156, 255, 0.2);
}

[data-theme="light"] {
  color-scheme: light;
  /* Светлая тема: «воздух», белый фон, мягкие тени (в духе editorjs.io) */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f6fa;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --danger: #dc2626;
  --btn-solid-fg: #ffffff;
  --alert-err-border: #fca5a5;
  --alert-err-fg: #991b1b;
  --alert-ok-border: #86efac;
  --alert-ok-fg: #166534;
  --modal-backdrop: rgba(15, 23, 42, 0.45);
  --modal-shadow: 0 24px 64px -16px rgba(15, 23, 42, 0.14);
  --timeline-dot-ring: rgba(37, 99, 235, 0.28);
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.045);
  --shadow-sm: 0 2px 12px rgba(15, 23, 42, 0.055);
  --shadow-md: 0 12px 40px -12px rgba(15, 23, 42, 0.1);
  --shadow-accent: 0 4px 16px -2px rgba(37, 99, 235, 0.22);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

[data-theme="light"] body {
  background: linear-gradient(165deg, #f4f8fc 0%, #ffffff 38%, #ffffff 100%);
  background-color: var(--bg);
  background-attachment: fixed;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

[data-theme="light"] .topbar {
  border-bottom-color: rgba(15, 23, 42, 0.06);
  box-shadow: 0 4px 28px -14px rgba(15, 23, 42, 0.08);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.lang-switch__label {
  font-size: 0.72rem;
  margin-right: 0.15rem;
}

.lang-switch__btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.lang-switch__btn:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.lang-switch__btn.is-active {
  background: rgba(91, 156, 255, 0.2);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.theme-switch__label {
  font-size: 0.72rem;
  margin-right: 0.15rem;
}

.theme-switch__btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.theme-switch__btn:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.theme-switch__btn.is-active {
  background: rgba(91, 156, 255, 0.2);
  color: var(--accent);
  border-color: var(--accent-dim);
}

[data-theme="light"] .lang-switch__btn.is-active,
[data-theme="light"] .theme-switch__btn.is-active {
  background: rgba(37, 99, 235, 0.14);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.brand {
  font-weight: 400;
  letter-spacing: 0;
  font-size: 1.32rem;
  line-height: 1.15;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover {
  text-decoration: none;
  color: var(--accent);
}
.brand-accent {
  color: #38a8e8;
  font-weight: 400;
}
[data-theme="dark"] .brand-accent {
  color: #63bfff;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}
.nav a {
  font-size: 0.95rem;
  color: var(--muted);
}
.nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

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

/* Гостевая заглушка на главной: без навигации по разделам */
.portal-gate {
  max-width: 28rem;
}

.portal-gate__title {
  margin-bottom: 0.35rem;
}

.portal-gate__lead {
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 0.5rem;
}

.lead {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.card {
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 110px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-1px);
}
.card h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.card p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  flex: 1;
}
.card .go {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

.badge-soon {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
}

.form {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

input[type="email"] {
  width: 100%;
  padding: 0.48rem 0.65rem;
  line-height: 1.35;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  box-sizing: border-box;
}
input[type="email"]:focus,
input[type="email"]:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: -2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.46rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--btn-solid-fg);
  text-decoration: none;
}
.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

[data-theme="light"] .btn:not(.btn-ghost):not(.btn-danger):not(.btn-soft) {
  box-shadow: var(--shadow-accent);
}
[data-theme="light"] .btn:not(.btn-ghost):not(.btn-danger):not(.btn-soft):hover {
  filter: brightness(1.04);
  box-shadow: 0 6px 20px -4px rgba(37, 99, 235, 0.28);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

[data-theme="light"] .btn-ghost {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-xs);
}
[data-theme="light"] .btn-ghost:hover {
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Вторичная кнопка: контур + лёгкая тень (страницы, тулбары, «Редактировать») */
.btn-soft {
  background: var(--surface);
  color: var(--accent);
  border-color: rgba(91, 156, 255, 0.42);
}
.btn-soft:hover {
  filter: none;
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] .btn-soft {
  background: #ffffff;
  border-color: rgba(37, 99, 235, 0.26);
  box-shadow: var(--shadow-xs);
}
[data-theme="light"] .btn-soft:hover {
  border-color: rgba(37, 99, 235, 0.42);
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  filter: brightness(1.08);
}

[data-theme="light"] .btn-danger {
  box-shadow: 0 6px 20px -4px rgba(220, 38, 38, 0.35);
}

.input,
select.input,
textarea.input {
  width: 100%;
  padding: 0.48rem 0.65rem;
  line-height: 1.35;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  box-sizing: border-box;
}
.input:focus,
.input:focus-visible,
select.input:focus,
select.input:focus-visible,
textarea.input:focus,
textarea.input:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: -2px;
}

[data-theme="light"] .input,
[data-theme="light"] select.input,
[data-theme="light"] textarea.input {
  border-color: #e2e8f0;
  box-shadow: var(--shadow-xs);
}
[data-theme="light"] input[type="email"] {
  border-color: #e2e8f0;
  box-shadow: var(--shadow-xs);
}

.alert {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  background: var(--surface);
}
.alert-err {
  border-color: var(--alert-err-border);
  color: var(--alert-err-fg);
}
.alert-ok {
  border-color: var(--alert-ok-border);
  color: var(--alert-ok-fg);
}

[data-theme="light"] .alert {
  box-shadow: var(--shadow-xs);
}

.magic-link-box {
  word-break: break-all;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

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

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

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

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

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

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 520px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}


/* --- Страница входа (центрированная карточка) --- */
.page-portal-auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1rem 2rem;
  position: relative;
  overflow-x: hidden;
}

.portal-auth-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 55% at 50% -15%, rgba(91, 156, 255, 0.28), transparent 55%),
    radial-gradient(ellipse 50% 45% at 100% 30%, rgba(91, 156, 255, 0.1), transparent 50%),
    radial-gradient(ellipse 45% 40% at 0% 70%, rgba(139, 92, 246, 0.08), transparent 50%),
    var(--bg);
}

[data-theme="light"] .portal-auth-bg {
  background:
    radial-gradient(ellipse 90% 55% at 50% -15%, rgba(37, 99, 235, 0.18), transparent 55%),
    radial-gradient(ellipse 50% 45% at 100% 25%, rgba(37, 99, 235, 0.08), transparent 50%),
    radial-gradient(ellipse 45% 40% at 0% 75%, rgba(124, 58, 237, 0.06), transparent 50%),
    var(--bg);
}

.portal-auth-frame {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 26rem;
}

.portal-auth-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 0;
  border: none;
}

.portal-auth-topbar .brand {
  font-size: 1.05rem;
}

.portal-auth-card {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.65rem 1.5rem 1.5rem;
  box-shadow: var(--modal-shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

[data-theme="light"] .portal-auth-card {
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.portal-auth-card__eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.35rem;
}

.portal-auth-card__title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.portal-auth-card__subtitle {
  margin: 0 0 1.35rem;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.5;
}

.page-portal-auth .form {
  max-width: none;
  gap: 1rem;
}

.page-portal-auth .form label {
  display: block;
  margin-bottom: 0.35rem;
}

.page-portal-auth input[type="email"] {
  padding: 0.72rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

[data-theme="light"] .page-portal-auth input[type="email"] {
  background: var(--surface);
}

.page-portal-auth .btn--block {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-size: 0.95rem;
}

.page-portal-auth .alert {
  border-radius: 10px;
  font-size: 0.88rem;
}

.page-portal-auth .magic-link-box {
  word-break: break-all;
  font-size: 0.78rem;
}
