/* MiniZapier — базовые стили Django-шаблонов */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-muted: #f7f7f8;
  --border: #e6e7ea;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #ff4a00;
  --accent-hover: #e74300;
  --danger: #b91c1c;
  --success: #15803d;
  --radius: 14px;
  --shadow: 0 14px 36px rgba(17, 24, 39, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

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

a:hover {
  text-decoration: underline;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-brand a {
  display: inline-block;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text);
  font-weight: 600;
  border: 1px solid transparent;
}

.nav-ico {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.nav-ico svg {
  width: 18px;
  height: 18px;
  display: block;
}

.nav-item:hover {
  background: var(--surface-muted);
  text-decoration: none;
}

.nav-item--active {
  background: #fff7f3;
  border-color: rgba(255, 74, 0, 0.25);
}

.nav-item--active .nav-ico {
  color: var(--accent);
}

.nav-item:hover .nav-ico {
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-user {
  font-size: 0.875rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  max-width: 1160px;
  padding: 28px 28px 52px;
  margin: 0 auto;
}

/* Wider layouts for heavy pages */
body[data-page="workflow_edit"] .content {
  max-width: 1920px;
}

body[data-page="analytics"] .content {
  max-width: 1400px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
}

/* Кнопки и «пилюли» ссылок */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.25;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

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

.btn--sm {
  padding: 6px 12px;
  font-size: 0.875rem;
}

/* Основной контент */
main {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

@media (max-width: 640px) {
  main {
    padding: 20px 18px;
  }
}

.page-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.lead {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 1rem;
}

.hero {
  margin-bottom: 18px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff7f3;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
}

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

/* Auth containers look like cards */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-card .page-title {
  margin-top: 0;
}

/* Tables on white cards */
table {
  width: 100%;
}

th, td {
  vertical-align: top;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 900px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
}

.card-title {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 700;
}

.card-metric {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin-top: 6px;
}

.table {
  border-collapse: collapse;
  width: 100%;
}

.table thead th {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 800;
}

.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f2;
  font-size: 0.95rem;
}

.table tbody tr:hover td {
  background: #fffaf7;
}

.json-pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  background: #fbfbfc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.json-pre--error {
  margin-top: 10px;
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}

/* Сообщения Django */
.messages {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.messages li {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.9375rem;
}

.messages li.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.messages li.error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.messages li.warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.messages li.info,
.messages li.debug {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* Карточка формы (вход / регистрация) */
.auth-card {
  max-width: 400px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="password"],
.form-field input[type="number"] {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-field input[type="date"] {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.form-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-field .helptext,
.form-field small {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-field ul.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--danger);
}

.form-errorlist {
  margin: 0 0 16px;
  padding: 12px 14px;
  list-style: none;
  font-size: 0.875rem;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
}

.form-actions {
  margin-top: 8px;
}

.form-actions .btn {
  width: 100%;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.checkbox-field label {
  font-weight: 500;
  cursor: pointer;
}

/* Ссылки под формой */
.auth-links {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.auth-links p {
  margin: 8px 0;
}

/* Списки сценариев */
.workflow-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.workflow-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  transition: border-color 0.15s;
}

.workflow-list li:hover {
  border-color: #cbd5e1;
}

.workflow-list a {
  font-weight: 500;
  color: var(--text);
}

.workflow-list a:hover {
  color: var(--accent);
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  font-weight: 800;
  font-size: 0.75rem;
  white-space: nowrap;
}

.status-badge--success {
  background: rgba(34, 197, 94, 0.10);
  border-color: rgba(34, 197, 94, 0.25);
  color: #15803d;
}

.status-badge--failed {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.22);
  color: #b91c1c;
}

.status-badge--running {
  background: rgba(255, 74, 0, 0.10);
  border-color: rgba(255, 74, 0, 0.22);
  color: var(--accent);
}

.status-badge--paused {
  background: rgba(59, 130, 246, 0.10);
  border-color: rgba(59, 130, 246, 0.22);
  color: #2563eb;
}

.badge--on {
  color: var(--success);
}

.badge--off {
  color: var(--text-muted);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.page-back {
  margin: 0 0 20px;
  font-size: 0.9375rem;
}

/* Редактор: блок под Vue */
.editor-mount {
  margin-top: 8px;
}

/* Workflows: cards + toggle */
.wf-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 900px) {
  .wf-grid {
    grid-template-columns: 1fr;
  }
}

.wf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.wf-title {
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
}

.wf-title:hover {
  color: var(--accent);
  text-decoration: none;
}

.wf-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  white-space: nowrap;
}

.wf-badge--on {
  border-color: rgba(255, 74, 0, 0.25);
  background: rgba(255, 74, 0, 0.10);
  color: var(--accent);
}

.wf-badge--off {
  color: var(--text-muted);
}

.wf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toggle {
  position: relative;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #e5e7eb;
  cursor: pointer;
  padding: 0;
}

.toggle .toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.14);
  transition: transform 0.16s ease, background 0.16s ease;
}

.toggle--on {
  background: #22c55e;
  border-color: #22c55e;
}

.toggle--on .toggle-knob {
  transform: translateX(24px);
}

.toggle .toggle-text {
  display: none;
}

form[action*="toggle-active"] .toggle {
  background: #e5e7eb;
}

/* If workflow is active, render "On" text; we can't detect state in CSS reliably,
   so we keep this as a neutral toggle UI. */
