/**
 * AI Research Digest — admin UI (data-dense dark dashboard)
 * Fonts: Fira Sans + Fira Code — link Google Fonts in base.html / login.html
 */

:root {
  --bg-deep: #0f172a;
  --bg-surface: #1e293b;
  --bg-elevated: #334155;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #3b82f6;
  --accent: #f97316;
  --accent-hover: #fb923c;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #eab308;
  --radius-card: 8px;
  --radius-btn: 6px;
  --radius-input: 4px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.45);
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --transition: 150ms ease-out;
  --font-ui: "Fira Sans", system-ui, sans-serif;
  --font-mono: "Fira Code", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body.admin-body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.5;
}

a {
  color: var(--primary-hover);
  text-decoration: none;
  transition: color var(--transition);
  cursor: pointer;
}

a:hover {
  color: var(--accent);
}

code,
kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-input);
  border: 1px solid var(--border-subtle);
}

/* ---- Mobile sidebar toggle ---- */
.nav-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nav-toggle-input:focus-visible + .sidebar {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  transform: translateX(0);
  transition: transform var(--transition);
}

.nav-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .nav-toggle-input:checked ~ .sidebar {
    transform: translateX(0);
  }

  .nav-toggle-input:checked ~ .nav-scrim {
    display: block;
  }
}

.sidebar__brand {
  padding: 0 1rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.5rem;
}

.sidebar__brand a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1rem;
}

.sidebar__brand a:hover {
  color: var(--primary-hover);
}

.sidebar__nav {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar__section {
  padding: 0.9rem 1rem 0.35rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1rem;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9375rem;
  border-left: 3px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.sidebar__link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar__link--active {
  color: var(--text-primary);
  background: rgba(37, 99, 235, 0.15);
  border-left-color: var(--primary);
}

.sidebar__icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  opacity: 0.9;
}

.layout-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .layout-main {
    margin-left: 0;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
}

.menu-btn:hover {
  background: var(--bg-elevated);
}

@media (max-width: 900px) {
  .menu-btn {
    display: flex;
  }
}

.topbar__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* POST logout: форма ведёт себя как flex-элемент рядом с кнопками */
.logout-form {
  display: contents;
}

.page-content {
  flex: 1;
  padding: 1.25rem 1.5rem 2rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ---- Cards ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card__header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 1rem;
}

.card__body {
  padding: 1rem 1.1rem;
}

.card__body--flush {
  padding: 0;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 40px;
  padding: 0 1rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition),
    transform var(--transition);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-hover);
}

.btn--accent {
  background: var(--accent);
  color: #0f172a;
}

.btn--accent:hover {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn--secondary:hover {
  background: #475569;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-subtle);
}

.btn--ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.btn--danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.35);
}

.btn--success {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
}

.btn--success:hover {
  background: rgba(34, 197, 94, 0.35);
}

.btn--sm {
  min-height: 34px;
  padding: 0 0.65rem;
  font-size: 0.8125rem;
}

.admin-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 1rem;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data-table th,
table.data-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

table.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.2);
}

table.data-table tbody tr {
  transition: background var(--transition);
}

table.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

table.data-table td {
  font-family: var(--font-ui);
}

table.data-table .mono {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* ---- Forms ---- */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-stack label,
label.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-stack input[type="text"],
.form-stack input[type="url"],
.form-stack input[type="password"],
.form-stack input[type="number"],
.form-stack input[type="date"],
.form-stack input[type="time"],
.form-stack select,
.form-stack textarea,
label.field input,
label.field select,
label.field textarea {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  color: var(--text-primary);
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  padding: 0.55rem 0.75rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-stack input:focus,
.form-stack select:focus,
.form-stack textarea:focus,
label.field input:focus,
label.field select:focus,
label.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.form-stack textarea,
label.field textarea {
  min-height: 6rem;
  resize: vertical;
}

.form-stack label:has(> input[type="checkbox"]),
form label.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

.form-stack input[type="checkbox"],
form input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

select[multiple],
select.multi-select {
  min-height: 8rem;
  padding: 0.35rem;
}

select[multiple] option {
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
}

select[multiple] option:checked {
  background: linear-gradient(0deg, var(--primary) 0%, var(--primary) 100%);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge--success {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.badge--neutral {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.badge--warning {
  background: rgba(234, 179, 8, 0.2);
  color: #fde047;
}

.badge--error {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* ---- Alerts / toast strip ---- */
.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
}

.alert--info {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.35);
}

.alert--success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
}

.alert--error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
}

.alert strong {
  color: var(--text-primary);
}

/* ---- Dashboard grid ---- */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.overview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  padding: 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}

.stat-card__label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.stat-card__value {
  margin-top: 0.35rem;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.empty-state {
  padding: 1rem;
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-card);
  color: var(--text-muted);
}

.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.wizard-step {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.82rem;
}

.wizard-step--active {
  background: rgba(37, 99, 235, 0.18);
  color: var(--text-primary);
}

.info-list {
  margin: 0;
  padding-left: 1.1rem;
}

.info-list li + li {
  margin-top: 0.35rem;
}

.split-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .split-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.kpi-pill {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
}

.dash-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  color: var(--text-primary);
  text-decoration: none;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-card);
}

.dash-tile:hover {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: var(--shadow-elevated);
  transform: translateY(-2px);
  color: var(--text-primary);
}

.dash-tile__label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.dash-tile__title {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

/* ---- Utilities ---- */
.text-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

pre.wrapped {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: var(--bg-deep);
  padding: 1rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.stack-sm > * + * {
  margin-top: 0.5rem;
}

.stack-md > * + * {
  margin-top: 1rem;
}

.inline-forms {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* ---- Standalone login ---- */
body.login-page {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  font-family: var(--font-ui);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(37, 99, 235, 0.22), transparent),
    var(--bg-deep);
  color: var(--text-primary);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-elevated);
  padding: 2rem 1.75rem;
}

.login-card__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  color: var(--primary-hover);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  text-align: center;
}

.login-card .text-muted {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-card .form-stack {
  gap: 1.1rem;
}

.login-card .field-icon-wrap {
  position: relative;
}

.login-card .field-icon-wrap svg {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.login-card .field-icon-wrap input {
  padding-left: 2.25rem;
}

/* ---- Centered error card (extends base) ---- */
.error-shell {
  max-width: 480px;
  margin: 2rem auto;
  text-align: center;
}

.error-shell .card {
  text-align: left;
}

.error-shell__icon {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  color: var(--warning);
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }

  .dash-tile:hover {
    transform: none;
  }

  .btn:active {
    transform: none;
  }
}
