/* Основа оформления дашборда (замена Pico.css): цвета, шрифт, базовые элементы.
   Тема — по настройке системы. Отдельные экраны — в app.css. */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --border: #e3e3e7;
  --border-strong: #cfcfd5;
  --text: #18181b;
  --text-2: #52525b;
  --muted: #71717a;
  --accent: #2f6fd6;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fc;
  --focus: rgba(47, 111, 214, 0.35);
  --crit-soft: #fdecec;
  --warn-soft: #fdf4e3;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;

  /* Старые имена переменных Pico — их ещё используют app.css и charts.js */
  --pico-color: var(--text);
  --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--border);
  --pico-primary-background: var(--accent);
  --pico-primary-inverse: var(--accent-text);
  --pico-del-color: var(--critical);
  --pico-border-radius: var(--radius);
  --pico-card-background-color: var(--surface);
  --pico-card-sectioning-background-color: var(--surface-2);
  --pico-block-spacing-vertical: 1rem;
  --pico-font-family-monospace: var(--mono);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e10;
    --surface: #17171a;
    --surface-2: #1f1f23;
    --border: #2a2a2f;
    --border-strong: #3a3a41;
    --text: #ececef;
    --text-2: #b4b4bb;
    --muted: #8b8b93;
    --accent: #4b8bf0;
    --accent-text: #ffffff;
    --accent-soft: #1b2a44;
    --focus: rgba(75, 139, 240, 0.45);
    --crit-soft: #3a1a1a;
    --warn-soft: #3a2c12;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e10;
  --surface: #17171a;
  --surface-2: #1f1f23;
  --border: #2a2a2f;
  --border-strong: #3a3a41;
  --text: #ececef;
  --text-2: #b4b4bb;
  --muted: #8b8b93;
  --accent: #4b8bf0;
  --accent-text: #ffffff;
  --accent-soft: #1b2a44;
  --focus: rgba(75, 139, 240, 0.45);
  --crit-soft: #3a1a1a;
  --warn-soft: #3a2c12;
  --shadow: none;
}

/* ---------- Основа ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

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

h1, h2, h3, h4, h5 { margin: 0 0 0.5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
h4, h5 { font-size: 0.875rem; }

p { margin: 0 0 0.6rem; }
small { font-size: 0.85em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
code, kbd, pre, samp { font-family: var(--mono); font-size: 0.92em; }
pre { background: var(--surface-2); padding: 0.6rem; border-radius: var(--radius-sm); overflow: auto; }
code { background: var(--surface-2); padding: 0 0.25rem; border-radius: 3px; }
pre code { background: none; padding: 0; }
blockquote { margin: 0.5rem 0; padding: 0.4rem 0.75rem; border-left: 3px solid var(--border-strong); color: var(--text-2); }
ul, ol { margin: 0 0 0.6rem; padding-left: 1.2rem; }
dl { margin: 0 0 0.6rem; }
hgroup { margin-bottom: 0.75rem; }
hgroup > * { margin-bottom: 0.2rem; }
mark { background: var(--warn-soft); color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Каркас страницы ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-in {
  max-width: 1440px;
  margin: 0 auto;
  height: 44px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }

.mainnav { display: flex; align-items: center; gap: 0.15rem; flex: 1; min-width: 0; }

.mainnav > a,
.menu > summary {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
}
.mainnav > a:hover, .menu > summary:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.mainnav > a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

.menu { position: relative; margin: 0; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: " ▾"; font-size: 0.8em; color: var(--muted); }
.menu-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
}
.menu-list a { padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); color: var(--text); }
.menu-list a:hover { background: var(--surface-2); text-decoration: none; }
.menu-note { padding: 0.4rem 0.6rem 0.2rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--border); margin-top: 0.2rem; }

.logout { margin: 0 0 0 auto; }

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

/* ---------- Кнопки ---------- */

button, .btn, [role="button"], input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 28px;
  padding: 0 0.7rem;
  font: inherit;
  font-weight: 500;
  line-height: 1;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
button:hover, .btn:hover, [role="button"]:hover { filter: brightness(1.08); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }

.btn-ghost, button.secondary, button.outline, [role="button"].secondary, [role="button"].outline, .btn-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover, button.secondary:hover, button.outline:hover, .btn-secondary:hover { background: var(--surface-2); filter: none; }
button.contrast, [role="button"].contrast { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- Формы ---------- */

form { margin: 0 0 0.75rem; }
label { display: block; margin-bottom: 0.6rem; color: var(--text); }
label > small, fieldset > small { display: block; color: var(--muted); margin-top: 0.15rem; }

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="hidden"]),
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.3rem 0.5rem;
  min-height: 28px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
textarea { line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--critical); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); margin: 0 0.35rem 0 0; vertical-align: -2px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; margin: 0 0 0.75rem; }
legend { padding: 0 0.3rem; font-weight: 600; }
[role="group"] { display: flex; gap: 0.4rem; align-items: center; }
[role="group"] > * { margin: 0 !important; }

/* ---------- Таблицы ---------- */

table { width: 100%; border-collapse: collapse; margin-bottom: 0.75rem; }
th, td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: 0.92em; white-space: nowrap; }
thead th { border-bottom-color: var(--border-strong); }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap, .overflow-auto { overflow-x: auto; }

/* ---------- Блоки ---------- */

article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 0.9rem;
  margin: 0 0 0.75rem;
}
article > header, article > footer {
  margin: -0.75rem -0.9rem 0.6rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
article > footer { margin: 0.6rem -0.9rem -0.75rem; border-bottom: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }

details > summary { cursor: pointer; }
details { margin-bottom: 0.5rem; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1rem;
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 0.5rem 1rem; }

/* ---------- Мелочи ---------- */

.muted { color: var(--muted); }
.error { color: var(--critical); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--neutral);
}
.dot-ok { background: var(--good); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }

.count {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.3em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85em;
  text-align: center;
}

/* ---------- Телефон ---------- */

@media (max-width: 640px) {
  body { font-size: 14px; }
  .topbar-in { gap: 0.5rem; padding: 0 12px; }
  .mainnav { overflow-x: auto; scrollbar-width: none; }
  .mainnav::-webkit-scrollbar { display: none; }
  .menu-list { position: fixed; top: 44px; left: 8px; right: 8px; }
  .page { padding: 10px 12px 32px; }
  button, .btn, [role="button"] { height: 32px; }
}
