/* ==========================================================================
   SensorDB — стили. Светлая строгая тема.
   Все цвета и размеры — в переменных ниже; цвета графика (--chart-*)
   читает js/app.js, поэтому внешний вид графиков тоже меняется здесь.
   ========================================================================== */

:root {
  /* поверхности */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --hover: #f1f3f6;

  /* текст */
  --text: #17202e;
  --muted: #5c6a7b;
  --faint: #8b97a6;

  /* линии */
  --border: #d6dce4;
  --border-soft: #e7eaf0;

  /* акцент и состояния */
  --accent: #1d4f8a;
  --accent-hover: #163f71;
  --accent-soft: #eaf0f8;
  --danger: #b3261e;
  --danger-soft: #fcefee;
  --ok: #1b7a46;
  --ok-soft: #edf6f0;
  --warn: #9a5b06;

  /* геометрия */
  --radius: 3px;
  --container: 1080px;

  /* шрифты */
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

  /* график (читается из js/app.js) */
  --chart-line: #1d4f8a;
  --chart-line-width: 1;
  --chart-grid: #e8ebf0;
  --chart-axis: #c5ccd6;
  --chart-text: #5c6a7b;
  --chart-bg: #ffffff;
  --chart-height: 420px;
}

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

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.005em; }
h1 { font-size: 18px; line-height: 1.3; }
h2 { font-size: 16px; line-height: 1.3; }

p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.mono { color: var(--muted); word-break: break-all; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.icon { flex: none; vertical-align: -3px; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Каркас ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in {
  max-width: var(--container); margin: 0 auto; padding: 0 20px; height: 48px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar-user { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.topbar-user form { margin: 0; }
.topbar-user .mono { word-break: normal; }

.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text); font-weight: 600; font-size: 15px; letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand .icon { color: var(--accent); vertical-align: 0; }

.container { max-width: var(--container); margin: 0 auto; padding: 24px 20px 48px; }
.container-wide { max-width: 1280px; }
.container-narrow { max-width: 520px; }
.pubbar { margin-bottom: 14px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
}
.panel-head .muted { font-variant-numeric: tabular-nums; }

.empty { padding: 28px 24px; }
.empty h1 { margin-bottom: 6px; }
.empty-note { margin: 0; padding: 20px 16px; color: var(--muted); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px;
  font: inherit; font-weight: 500; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--hover); border-color: #c3cbd6; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); border-color: transparent; color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  color: var(--faint); background: transparent; border: 0; border-radius: var(--radius);
  cursor: pointer; transition: background-color .12s, color .12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

.link-btn {
  padding: 0; font: inherit; font-weight: 600; text-align: left;
  color: var(--accent); background: none; border: 0; cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

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

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-weight: 500; }
.hint { display: block; margin-top: 6px; font-size: 12.5px; color: var(--muted); }

input[type="text"], input[type="password"] {
  width: 100%; height: 36px; padding: 0 10px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
input[type="text"]:hover, input[type="password"]:hover { border-color: #b9c2ce; }
input[type="text"]:focus, input[type="password"]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent);
}
input::placeholder { color: var(--faint); }

.check { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; color: var(--muted); cursor: pointer; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }

/* ---------- Сообщения ---------- */

.alert {
  margin: 0 0 16px; padding: 10px 14px;
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius);
  background: var(--surface);
}
.alert-ok { border-color: #bfdcca; border-left-color: var(--ok); background: var(--ok-soft); }
.alert-error { border-color: #efc7c4; border-left-color: var(--danger); background: var(--danger-soft); color: #7d1b16; }

/* ---------- Таблица датчиков ---------- */

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 10px 16px; text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border-soft);
}
.data-table thead th {
  padding-top: 9px; padding-bottom: 9px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  background: var(--surface-alt); border-bottom-color: var(--border);
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr.is-active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .sub { margin-top: 1px; font-size: 12px; color: var(--faint); }
.data-table .actions-col { width: 1%; }
.data-table .actions { text-align: right; white-space: nowrap; padding-top: 5px; padding-bottom: 5px; }
.data-table time { white-space: nowrap; color: var(--muted); }
.data-table time.is-stale { color: var(--warn); }

/* ---------- Переключатель периода ---------- */

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  min-width: 46px; height: 28px; padding: 0 10px;
  font: inherit; font-size: 13px; color: var(--muted);
  background: var(--surface); border: 0; border-left: 1px solid var(--border); cursor: pointer;
}
.seg-btn:first-child { border-left: 0; }
.seg-btn:hover { background: var(--hover); color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- График ---------- */

.chart-panel .panel-head h2 { min-width: 0; overflow-wrap: anywhere; }
.chart-tools { display: flex; align-items: center; gap: 8px; }

.chart-wrap { position: relative; padding: 8px 8px 0; }
.chart { width: 100%; height: var(--chart-height); }
.chart-state {
  position: absolute; inset: 8px 8px 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: rgba(255, 255, 255, .8);
}
.chart-state.is-error { color: var(--danger); }
.chart-hint { margin: 0; padding: 6px 16px 12px; font-size: 12.5px; color: var(--faint); }

/* Highcharts: мелкие правки поверх настроек из app.js */
.highcharts-container { font-family: var(--font) !important; }
.highcharts-credits { opacity: .55; }
.highcharts-contextmenu hr { border-color: var(--border-soft); }

/* ---------- Подключение датчиков ---------- */

.howto summary {
  padding: 12px 16px; font-weight: 600; cursor: pointer; list-style-position: inside;
}
.howto summary:hover { background: var(--surface-alt); }
.howto[open] summary { border-bottom: 1px solid var(--border-soft); }
.howto-body { padding: 14px 16px 6px; max-width: 760px; }
.howto-body p { color: var(--muted); }
.howto pre {
  margin: 0 0 14px; padding: 10px 12px; overflow-x: auto;
  background: var(--surface-alt); border: 1px solid var(--border-soft); border-radius: var(--radius);
}
.howto code { color: var(--text); }

/* ---------- Окно «Название датчика» ---------- */

dialog {
  width: min(440px, calc(100% - 32px)); padding: 0;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
dialog::backdrop { background: rgba(23, 32, 46, .38); }
.dialog-body { padding: 20px; }
.dialog-body h2 { margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Уведомление ---------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 8px 14px;
  color: #fff; background: var(--text); border-radius: var(--radius);
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.toast.is-visible { opacity: 1; }

/* ---------- Страница входа ---------- */

.page-auth { background: var(--bg); }
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; padding: 28px 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.auth-brand {
  display: flex; align-items: center; gap: 8px; margin-bottom: 22px;
  font-size: 16px; font-weight: 600; letter-spacing: 0.01em;
}
.auth-brand .icon { color: var(--accent); vertical-align: 0; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card > .muted { margin-bottom: 20px; }
.err-code {
  margin-bottom: 6px; font-size: 40px; font-weight: 600; line-height: 1;
  color: var(--border); font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}

/* ---------- Адаптивность ---------- */

@media (max-width: 720px) {
  :root { --chart-height: 320px; }
  .hide-sm { display: none !important; }
  .container { padding: 16px 12px 40px; }
  .topbar-in { padding: 0 12px; }
  .panel-head { padding: 12px; }
  .data-table th, .data-table td { padding-left: 12px; padding-right: 12px; }
  .icon-btn { width: 34px; height: 34px; }
  .chart-tools { width: 100%; justify-content: space-between; }
  .chart-hint { padding-left: 12px; padding-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  body { background: #fff; }
  .topbar, .howto, .chart-tools, .actions, .actions-col, .chart-hint, .toast { display: none !important; }
  .panel { border-color: #999; }
}
