/* Веб-панель OVI Core: светлая и тёмная темы, адаптивная вёрстка, без внешних шрифтов и CDN. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0e7fd6;
  --accent-hover: #0b6bb5;
  --accent-soft: #e6f2fc;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: #0f1b2d;
  --sidebar-text: #c7d2e0;
  --sidebar-active: #1c2d46;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #121b2c;
  --surface-2: #172236;
  --border: #24324a;
  --text: #e5ecf5;
  --muted: #8ea0b8;
  --accent: #3aa0f0;
  --accent-hover: #5ab1f5;
  --accent-soft: #12304b;
  --accent-text: #04121f;
  --ok: #4ade80;
  --ok-soft: #12301f;
  --warn: #fbbf24;
  --warn-soft: #33270d;
  --danger: #f87171;
  --danger-soft: #3a1717;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --sidebar: #080e1a;
  --sidebar-text: #aab8cc;
  --sidebar-active: #16233a;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #121b2c;
    --surface-2: #172236;
    --border: #24324a;
    --text: #e5ecf5;
    --muted: #8ea0b8;
    --accent: #3aa0f0;
    --accent-hover: #5ab1f5;
    --accent-soft: #12304b;
    --accent-text: #04121f;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #33270d;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --sidebar: #080e1a;
    --sidebar-text: #aab8cc;
    --sidebar-active: #16233a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

input[type="text"], input[type="password"], input[type="number"], input[type="email"], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:disabled, select:disabled { opacity: .65; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .lbl { font-weight: 550; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field .err { color: var(--danger); font-size: 12px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 40px; height: 22px; border-radius: 22px; background: var(--border); position: relative; flex: none; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }

/* ---------- значки ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- страница входа ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 28px 24px;
}
.login-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card .btn.primary { width: 100%; min-height: 40px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand .name { font-weight: 700; font-size: 17px; }
.brand .sub { color: var(--muted); font-size: 12.5px; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- каркас приложения ---------- */
.layout { display: flex; min-height: 100vh; background: linear-gradient(to right, var(--sidebar) 236px, transparent 236px); }
.sidebar {
  width: 236px; flex: none; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.sidebar .brand { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; }
.sidebar .brand img { width: 34px; height: 34px; border-radius: 9px; }
.sidebar .brand .name { color: #fff; font-size: 15.5px; }
.sidebar .brand .sub { color: var(--sidebar-text); opacity: .75; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--sidebar-text); text-decoration: none; font-weight: 550;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.sidebar .foot { padding: 12px 18px 16px; font-size: 12px; opacity: .7; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; display: flex; align-items: center; gap: 10px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 650; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#theme-btn svg { width: 18px; height: 18px; }
.topbar .user { color: var(--muted); font-size: 13px; white-space: nowrap; }
.menu-btn { display: none; }
.content { padding: 22px 20px 40px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { flex: 1; min-width: 200px; }
.scrim { display: none; }

/* ---------- карточки и сетки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 16px; }
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.meter { height: 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--accent); width: 0; }
.meter.warn > span { background: var(--warn); }
.meter.danger > span { background: var(--danger); }

dl.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }

/* ---------- настройки ---------- */
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px 18px; }
.set-grid .field.wide { grid-column: 1 / -1; }
.restart-tag { display: inline-block; margin-left: 6px; }
.savebar {
  position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.savebar .msg { flex: 1; min-width: 160px; }

/* ---------- службы ---------- */
.svc { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.svc + .svc { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.svc .info { flex: 1; min-width: 220px; }
.svc .ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- журналы ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="text"] { max-width: 320px; }
.toolbar select { width: auto; min-width: 150px; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.log { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 70vh; overflow: auto; }
.log div { padding: 2px 0; border-bottom: 1px dashed var(--border); }

/* ---------- всплывающие окна и уведомления ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(2, 8, 20, .5); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
}
.modal { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 20px; }
.modal h2 { margin-bottom: 10px; }
.modal .body { display: flex; flex-direction: column; gap: 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); max-width: 420px; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--ok); }

.empty { padding: 18px 0; color: var(--muted); text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- мобильные ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; }
  .layout.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(2, 8, 20, .45); z-index: 25; }
  .layout { background: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  #theme-btn svg { width: 18px; height: 18px; }
.topbar .user { display: none; }
  .content { padding: 16px 16px 32px; }
  .grid.two { grid-template-columns: 1fr; }
  .table-wrap { margin: 0 -18px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dd { margin-bottom: 6px; }
  .toolbar input[type="text"] { max-width: none; }
  td.actions { white-space: normal; }
  td.actions .btn { margin: 2px 0 2px 6px; }
}
@media (max-width: 520px) {
  .top-label { display: none; }
  h1 { font-size: 19px; }
  .set-grid { grid-template-columns: 1fr; }
}
h3.card-head { margin-top: 18px; }
