:root {
  --bg: #f4f6f8; --panel: #fff; --ink: #1f2733; --muted: #6b7785;
  --line: #e3e8ee; --brand: #2f6df6; --brand-ink: #fff;
  --ok: #1f9d57; --warn: #b8860b; --err: #d23f3f; --pending: #8a94a6;
  --radius: 8px; --shadow: 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; }
/* Атрибут hidden должен перебивать display:grid у .app/.auth (иначе скрытые экраны видны). */
[hidden] { display: none !important; }

/* --- Shell --- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; }
.brand { font-weight: 700; font-size: 16px; padding: 8px 12px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { padding: 9px 12px; border-radius: var(--radius); color: var(--ink); }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand); color: var(--brand-ink); }
.logout { margin-top: 12px; padding: 9px 12px; border: 1px solid var(--line);
  background: var(--panel); border-radius: var(--radius); color: var(--muted); }
.logout:hover { color: var(--err); border-color: var(--err); }
.content { padding: 24px 28px; min-width: 0; }

/* --- Headings / page --- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-actions { display: flex; gap: 8px; }

/* --- Buttons --- */
.btn { padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .7; cursor: default; }
/* Состояние загрузки: текст скрыт, по центру крутится спиннер. */
.btn.loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.loading::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 15px; height: 15px; margin: -8px 0 0 -8px;
  border: 2px solid rgba(127,127,127,.4); border-top-color: var(--brand);
  border-radius: 50%; animation: pdm-spin .6s linear infinite;
}
.btn.primary.loading::after { border-color: rgba(255,255,255,.45); border-top-color: #fff; }
@keyframes pdm-spin { to { transform: rotate(360deg); } }

/* --- Tables --- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
code.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  background: var(--bg); padding: 2px 6px; border-radius: 4px; }

/* --- Badges --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.online { background: #e6f6ec; color: var(--ok); }
.badge.offline { background: #fbe9e9; color: var(--err); }
.badge.pending { background: #eef1f5; color: var(--pending); }
.badge.ok { background: #e6f6ec; color: var(--ok); }
.badge.error { background: #fbe9e9; color: var(--err); }

/* --- Forms --- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); font: inherit; color: var(--ink); background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.form-row { display: flex; gap: 12px; } .form-row > * { flex: 1; }
.form-err { color: var(--err); font-size: 13px; margin: 8px 0; min-height: 18px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink); }
.checks input { width: auto; }

/* --- Auth screens --- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.auth-card { width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.auth-card h1 { font-size: 18px; margin: 0 0 18px; }

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45);
  display: grid; place-items: center; z-index: 50; }
.modal { width: 440px; max-width: calc(100vw - 32px); background: var(--panel);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(16,24,40,.25); padding: 22px; }
.modal h2 { font-size: 17px; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* --- Toasts --- */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { padding: 11px 16px; border-radius: var(--radius); color: #fff; box-shadow: var(--shadow); max-width: 360px; }
.toast.info { background: #334155; } .toast.success { background: var(--ok); } .toast.error { background: var(--err); }
