@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap");

:root {
  --bg-deep: #080b10;
  --bg: #0c1017;
  --bg-elevated: #12181f;
  --card: #151c26;
  --card-hover: #1a222e;
  --border: rgba(100, 130, 180, 0.18);
  --border-strong: rgba(130, 160, 210, 0.28);
  --text: #eef2f8;
  --text-secondary: #9aacbf;
  --muted: #6b7c90;
  --accent: #4f8fff;
  --accent-dim: rgba(79, 143, 255, 0.14);
  --accent-glow: rgba(79, 143, 255, 0.35);
  --success: #3dd68c;
  --success-bg: rgba(61, 214, 140, 0.12);
  --warning: #e3b341;
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.28);
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-deep);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -40%, rgba(79, 143, 255, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 50% at 100% 0%, rgba(120, 80, 200, 0.06), transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

/* ——— App shell + sidebar ——— */
.app-layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.35rem 1rem 1.25rem;
  background: linear-gradient(180deg, rgba(16, 22, 32, 0.98) 0%, rgba(10, 14, 20, 0.99) 100%);
  border-right: 1px solid var(--border-strong);
  box-shadow: 6px 0 32px rgba(0, 0, 0, 0.35);
}

.sidebar-brand {
  display: block;
  font-weight: 700;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  padding: 0.5rem 0.65rem 1.15rem;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, #fff 0%, #8eb8ff 55%, #6b9fff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  border-bottom: 1px solid rgba(100, 140, 220, 0.2);
}

.sidebar-brand:hover {
  filter: brightness(1.08);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
}

.sidebar-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Кнопки навигации */
.sidebar .nav-btn {
  position: relative;
  display: block;
  padding: 0.7rem 1rem 0.7rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.2s ease,
    transform 0.18s ease;
}

.sidebar .nav-btn:hover {
  color: var(--text);
  background: rgba(79, 143, 255, 0.12);
  border-color: rgba(79, 143, 255, 0.35);
  box-shadow:
    0 0 0 1px rgba(79, 143, 255, 0.15),
    0 4px 14px rgba(0, 0, 0, 0.2);
  transform: translateX(3px);
}

.sidebar .nav-btn.is-active {
  color: var(--text);
  background: linear-gradient(105deg, rgba(79, 143, 255, 0.22) 0%, rgba(79, 143, 255, 0.08) 100%);
  border-color: rgba(79, 143, 255, 0.45);
  box-shadow:
    0 0 0 1px rgba(79, 143, 255, 0.25),
    0 6px 20px rgba(79, 143, 255, 0.12);
}

.sidebar .nav-btn.is-active::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 55%;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent) 0%, #7eb0ff 100%);
  box-shadow: 0 0 10px var(--accent-glow);
}

.sidebar .nav-btn.nav-btn--logout {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
  font-weight: 500;
}

.sidebar .nav-btn.nav-btn--logout:hover {
  color: var(--error);
  background: var(--error-bg);
  border-color: rgba(248, 113, 113, 0.35);
  box-shadow: 0 4px 14px rgba(248, 113, 113, 0.08);
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border-strong);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
  }

  .sidebar-brand {
    flex: 1 1 auto;
    min-width: 140px;
    padding: 0.35rem 0.5rem;
    margin-bottom: 0;
    border-bottom: none;
  }

  .sidebar-nav {
    flex: 2 1 280px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .sidebar .nav-btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
    padding: 0.55rem 0.75rem;
    text-align: center;
    transform: none;
  }

  .sidebar .nav-btn:hover {
    transform: none;
  }

  .sidebar .nav-btn.is-active::before {
    display: none;
  }

  .sidebar-footer {
    flex: 1 1 100%;
    margin-top: 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
  }

  .sidebar .nav-btn.nav-btn--logout {
    width: 100%;
  }
}

/* ——— Layout ——— */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.page-head {
  margin-bottom: 1.75rem;
}

.page-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-head .lead {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ——— Stat pills ——— */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.stat-card .label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat-card .value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}

.stat-card .value.accent {
  color: var(--accent);
}

/* ——— Panels & cards ——— */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

/* ——— Tables ——— */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.container thead {
  background: rgba(0, 0, 0, 0.2);
}

.container th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.container td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.container tbody tr {
  transition: background 0.12s;
}

.container tbody tr:hover {
  background: rgba(79, 143, 255, 0.05);
}

.container tbody tr:last-child td {
  border-bottom: none;
}

.container td:first-child,
.container th:first-child {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
}

.empty-table {
  padding: 2rem 1.25rem !important;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Status badges (plain text states) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-done,
.badge-ok {
  background: var(--success-bg);
  color: var(--success);
}

.badge-pending,
.badge-running {
  background: var(--accent-dim);
  color: var(--accent);
}

.badge-failed,
.badge-error {
  background: var(--error-bg);
  color: var(--error);
}

.badge-cancelled {
  background: rgba(155, 163, 175, 0.15);
  color: #b8c0cc;
}

.btn-danger,
button.btn-danger {
  background: linear-gradient(135deg, #c94b4b 0%, #a83838 100%);
  box-shadow: 0 2px 10px rgba(201, 75, 75, 0.35);
  margin-top: 0;
  font-size: 0.78rem;
  padding: 0.35rem 0.65rem;
}

.btn-danger:hover {
  box-shadow: 0 3px 14px rgba(201, 75, 75, 0.45);
}

.checkbox-fieldset {
  margin: 1rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
}

.checkbox-fieldset legend {
  padding: 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-row input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

select {
  cursor: pointer;
}

select.select-multi {
  min-height: 7.5rem;
  padding: 0.45rem 0.5rem;
}

/* ——— Forms ——— */
label {
  display: block;
  margin: 0.65rem 0 0.25rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: auto;
  margin-top: 0.85rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, #3b7ae8 100%);
  color: #fff;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(79, 143, 255, 0.35);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}

button:hover,
.btn:hover {
  filter: brightness(1.06);
  box-shadow: 0 4px 18px rgba(79, 143, 255, 0.45);
}

button:active,
.btn:active {
  transform: scale(0.98);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.actions form {
  display: inline-block;
  margin: 0;
}

.actions button {
  margin-top: 0;
  font-size: 0.78rem;
  padding: 0.35rem 0.65rem;
  box-shadow: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
  filter: none;
}

.error {
  color: var(--error);
}

.ok {
  color: var(--success);
}

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
  margin-top: 0.75rem;
}

.mt {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.82rem;
  background: var(--bg-elevated);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.logbox {
  background: #06080c;
  color: #b8c5d4;
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* ——— Login ——— */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-card {
  position: relative;
  width: min(420px, 100%);
  padding: 2rem 2rem 1.75rem;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(165deg, rgba(21, 28, 38, 0.95) 0%, rgba(12, 16, 23, 0.98) 100%);
  box-shadow:
    var(--shadow-card),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 80px rgba(79, 143, 255, 0.08);
}

.login-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 17px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(79, 143, 255, 0.45), transparent 40%, transparent 60%, rgba(120, 80, 200, 0.25));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-card .subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.login-card .error {
  margin-top: 1rem;
}

.login-card > form {
  margin-top: 1.25rem;
}

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.7rem;
  font-size: 0.95rem;
}

/* Page titles outside page-head (legacy h1) */
.container > h1:first-child {
  margin: 0 0 0.25rem;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.container > h1:first-child + p {
  margin: 0 0 1.5rem;
  color: var(--text-secondary);
}

.container > h2 {
  margin: 1.75rem 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

@media (max-width: 640px) {
  .top {
    flex-direction: column;
    align-items: stretch;
  }

  nav {
    justify-content: center;
  }

  .stat-card .value {
    font-size: 1.4rem;
  }
}
