:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #192234;
  --border: #263248;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d9e1ec;
  --text: #111827;
  --muted: #5b677a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace; }
.muted { color: var(--muted); font-size: 0.9rem; }
.full-width { width: 100%; }

/* Авторизация */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.brand-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.login-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; }
.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-sub { color: var(--muted); font-size: 0.82rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); box-shadow: 0 0 10px rgba(34, 197, 94, 0.6); }
.dot-warn { background: var(--warn); }
.dot-danger { background: var(--danger); box-shadow: 0 0 10px rgba(239, 68, 68, 0.6); }

/* Кнопки */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s, background 0.15s;
}
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }

/* Контент */
.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.section-title { margin: 0 0 14px; font-size: 1.1rem; font-weight: 700; }
.section-head .section-title { margin-bottom: 0; }

/* Метрики сервера */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.metric-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.metric-value { font-size: 1.35rem; font-weight: 700; margin-bottom: 6px; }
.metric-sub { font-size: 0.8rem; color: var(--muted); }

.progress {
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--ok);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--danger); }

/* Проекты */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}
.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.project-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.project-name { font-size: 1.05rem; font-weight: 700; margin: 0 0 2px; }
.project-desc { font-size: 0.84rem; color: var(--muted); margin: 0; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-ok { background: rgba(34, 197, 94, 0.14); color: var(--ok); }
.pill-warn { background: rgba(245, 158, 11, 0.14); color: var(--warn); }
.pill-danger { background: rgba(239, 68, 68, 0.14); color: var(--danger); }
.pill-neutral { background: var(--surface-2); color: var(--muted); }

.project-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.83rem;
}
.stat-k { color: var(--muted); font-size: 0.76rem; }
.stat-v { font-weight: 600; margin-top: 2px; }

.project-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

/* Журнал аудита */
.audit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.audit-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.audit-table th, .audit-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.audit-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.audit-table tr:last-child td { border-bottom: none; }

/* Модалки */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.65); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  z-index: 2;
}
.modal-wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-head-actions { display: flex; gap: 8px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.confirm-text { margin: 8px 0 0; color: var(--text); font-size: 0.94rem; }

.logs-pre {
  background: #070a10;
  color: #cbd5e1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  max-height: 60vh;
  overflow: auto;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 0.9rem;
}

/* Навигация и разделы Agency OS */
.main-nav {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active { color: #fff; background: var(--primary); }
.tab-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 999px;
}

.subnav {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.subnav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}
.subnav-btn.active { border-color: var(--primary); color: var(--text); background: rgba(59, 130, 246, 0.14); }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-box h3, .card-box h4 { margin: 0 0 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.84rem; color: var(--muted); }
.form-grid .full-span { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea,
.card-box textarea, .select-sm, .input-sm {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 0.9rem;
  font-family: inherit;
}
.select-sm, .input-sm { padding: 6px 9px; font-size: 0.84rem; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel-list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  flex-wrap: wrap;
}
.list-item-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.list-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.empty-box { padding: 18px; background: var(--surface); border: 1px dashed var(--border); border-radius: 12px; text-align: center; }

.mini-issues {
  background: var(--surface-2);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 8px 0;
}
.expanded-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sub-block h4 { margin: 0 0 8px; font-size: 0.92rem; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; }
.strike { text-decoration: line-through; color: var(--muted); }
.txt-ok { color: var(--ok); }
.txt-warn { color: var(--warn); }
.txt-danger { color: var(--danger); }
.pill-danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.pill-ok { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.btn-ok { background: var(--ok); color: #052e16; border: none; }

@media (max-width: 640px) {
  .main-nav { padding: 8px 12px; }
  .topbar { padding: 12px; }
  .container { padding: 14px 12px; }
}
