/* assets/style.css — общий стиль для index.php и admin.php */

:root {
    --bg: #eef2f7;
    --card: #ffffff;
    --ink: #22303f;
    --muted: #7b8a99;
    --line: #e3e9f0;
    --blue: #2f80ed;
    --green: #27ae60;
    --red: #eb5757;
    --violet: #7b4fd8;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 24px 16px 60px;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Tahoma, sans-serif;
}

.wrap { max-width: 1180px; margin: 0 auto; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.3px; }

.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }

.topbar nav a {
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    box-shadow: 0 1px 3px rgba(16, 32, 48, .08);
}

.topbar nav a:hover { background: #dfe8f4; }
.topbar nav a.active { background: var(--blue); color: #fff; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(16, 32, 48, .08);
}

.card > h2 {
    margin: 0 0 16px;
    font-size: 17px;
    font-weight: 600;
}

/* ---- карточки станций ---- */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 16px;
}

.station {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 1px 3px rgba(16, 32, 48, .08);
    border-left: 4px solid var(--muted);
}

.station.online  { border-left-color: var(--green); }
.station.offline { border-left-color: var(--red); }

.station header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.station header h3 { margin: 0; font-size: 16px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    color: #fff;
    white-space: nowrap;
}

.badge.online  { background: var(--green); }
.badge.offline { background: var(--red); }
.badge.warn    { background: #e2a03f; }

.badge i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
    background: #fff;
    opacity: .9;
}

.values {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
    gap: 8px;
}

.values .v { font-size: 26px; font-weight: 700; line-height: 1.15; }
.values .v.t-in  { color: var(--red); }
.values .v.hum   { color: var(--blue); }
.values .v.t-out { color: var(--violet); }
.values .l { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

.meta {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---- элементы управления ---- */

.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

select, input[type=date], input[type=number], input[type=text], input[type=password] {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--ink);
}

select:focus, input:focus { outline: 2px solid #b6d0f5; border-color: var(--blue); }

button {
    padding: 9px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: #fff;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button.ghost { background: #e8eef6; color: var(--ink); }
button.green { background: var(--green); }
button.red   { background: var(--red); }
button.violet{ background: var(--violet); }
button:disabled { opacity: .5; cursor: default; }

.chart-box { position: relative; height: 460px; }

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

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: center; border-bottom: 1px solid var(--line); }
th { background: #f6f9fc; font-weight: 600; color: #44566c; position: sticky; top: 0; }
tbody tr:hover { background: #f7fbff; }
td.left { text-align: left; }

.scroll { max-height: 520px; overflow: auto; border-radius: 8px; }

.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

/* ---- админка ---- */

.field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 14px;
}

.field label { color: var(--muted); min-width: 120px; }

.section {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.section h4 {
    margin: 0 0 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
}

.row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px;
    margin-bottom: 8px;
    background: #f6f9fc;
    border-radius: 8px;
    font-size: 13px;
}

.row input[type=text] { flex: 1 1 120px; min-width: 100px; }
.row input[type=number] { width: 74px; }
.row input[type=color] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(20px);
    background: #22303f;
    color: #fff;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: .25s;
    z-index: 50;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

@media (max-width: 620px) {
    .values .v { font-size: 21px; }
    .chart-box { height: 340px; }
    .field { flex-wrap: wrap; }
    .field label { min-width: 100%; }
}


/* ---- аккордеон контроллеров в админке ---- */
details.node {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    margin-bottom: 12px;
    overflow: hidden;
}
details.node > summary {
    cursor: pointer;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 16px;
    list-style: none;
}
details.node > summary::-webkit-details-marker { display: none; }
details.node > summary::before {
    content: '▸';
    color: var(--muted);
    font-size: 13px;
    transition: transform .15s;
}
details.node[open] > summary::before { transform: rotate(90deg); }
details.node[open] > summary { border-bottom: 1px solid var(--line); }
.node-name { font-weight: 600; }
.node-id, .node-mac { color: var(--muted); font-size: 12px; }
.node-hidden {
    font-size: 11px;
    color: #b06d00;
    background: #fff4e0;
    border-radius: 8px;
    padding: 2px 7px;
}
.node-body { padding: 4px 16px 16px; }

/* ---- таблица показателей: главная и админка ---- */
table.metrics, table.metrics-edit, table.period { width: 100%; }
table.metrics th, table.metrics td,
table.metrics-edit th, table.metrics-edit td { padding: 5px 7px; font-size: 13px; }
table.metrics thead th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.metrics .cur b { font-size: 17px; }
table.metrics .dim { color: var(--muted); }
table.metrics td.left, table.metrics-edit td.left { text-align: left; }
.unit { color: var(--muted); font-size: 11px; margin-left: 3px; }

/* ---- панель скрытия столбцов ---- */
details.cols {
    margin: 10px 0;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 8px 12px;
}
details.cols > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.cols-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin: 10px 0 6px;
}
.cols-list label { display: flex; align-items: center; gap: 5px; font-size: 13px; }

/* ---- формы показателей ---- */
table.metrics-edit form { display: contents; }
table.metrics-edit input[type=text] { padding: 4px 6px; }

/* ---- порядок и цвета показателей в панели ---- */
table.metrics-edit td.ord {
    white-space: nowrap;
}
table.metrics-edit .ord-form {
    display: inline-block;
    margin: 0 2px 0 0;
}
table.metrics-edit .ord-form button {
    padding: 2px 7px;
    font-size: 13px;
    line-height: 1.2;
}
table.metrics-edit .ord-form button:disabled {
    opacity: .35;
    cursor: default;
}
table.metrics-edit td.col-color {
    white-space: nowrap;
}
table.metrics-edit td.col-color input[type=color] {
    width: 34px;
    height: 26px;
    padding: 1px;
    border: 1px solid var(--line);
    border-radius: 4px;
    vertical-align: middle;
    background: none;
    cursor: pointer;
}
table.metrics-edit td.col-color label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 3px;
    vertical-align: middle;
}
table.metrics-edit td.col-color .hint {
    font-size: 10px;
}

/* ---- легенда графика: строки по станциям, цвет из админки ---- */
.legend { margin-top: 10px; font-size: 13px; line-height: 1.7; }
.lg-row { margin: 2px 0; }
.lg-title { font-weight: 600; margin-right: 4px; }
.lg-item {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    margin: 2px 0;
}
.lg-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin: 0 4px 0 2px;
    vertical-align: middle;
}
.lg-sep {
    color: var(--muted);
    margin: 0 10px;
    opacity: .55;
}

/* ---- элементы, локации, табло, правила, графики ---- */
table.edit-table { width: 100%; }
table.edit-table th, table.edit-table td { padding: 4px 6px; font-size: 13px; vertical-align: middle; }
table.edit-table thead th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.edit-table form { display: contents; }
.tiny { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.kind-tag, .loc-tag, .val-tag {
    font-size: 11px; border-radius: 8px; padding: 2px 7px; background: #eef2f7; color: #4a5b6b;
}
.loc-tag { background: #e8f0fe; color: #1a56b8; }
.val-tag { background: #eaf7ee; color: #1c6b34; font-family: ui-monospace, monospace; }
.val-tag.on { background: #fdecec; color: #a11f1f; }
.color-field { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.color-field input[type=color] { width: 30px; height: 24px; padding: 1px; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
.color-field label { display: inline-flex; align-items: center; gap: 2px; font-size: 10px; color: var(--muted); }
.c-inp { width: 34px; height: 24px; padding: 1px; border: 1px solid var(--line); border-radius: 4px; background: none; }
details.node.el > summary { padding: 10px 14px; font-size: 14px; }

/* ---- блоки графиков на главной ---- */
.chart-block { margin: 18px 0; }
.chart-block h4 { margin: 0 0 6px; font-size: 15px; }
.legend { margin-top: 8px; font-size: 13px; line-height: 1.7; }
.lg-row { margin: 2px 0; }
.lg-title { font-weight: 600; margin-right: 4px; }
.lg-item { white-space: nowrap; }
.lg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 4px 0 2px; vertical-align: middle; }
.lg-sep { color: var(--muted); margin: 0 8px; }

/* ---- шкала WiFi: пять делений по возрастающей ---- */
.wifi-scale { display: inline-flex; align-items: flex-end; gap: 2px; vertical-align: middle; margin-right: 4px; }
.wifi-scale i { display: block; width: 4px; border-radius: 1px; background: #d6dee7; }
.wifi-scale i.on { background: #27ae60; }

/* ---- дашборд: плитки локаций ---- */
.loc-tile {
    display: block;
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 1px 3px rgba(16, 32, 48, .08);
    border-left: 4px solid var(--line);
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s, transform .15s;
}
.loc-tile:hover {
    box-shadow: 0 4px 14px rgba(16, 32, 48, .14);
    transform: translateY(-1px);
}
.loc-tile header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.loc-tile header h3 { margin: 0; font-size: 16px; }

.loc-sensors {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 13px;
}
.loc-sensors li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--line);
}
.loc-sensors li:last-child { border-bottom: none; }
.loc-sensors .nm {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.loc-sensors .vl { font-variant-numeric: tabular-nums; }

/* Кружок состояния: зелёный — контроллер датчика на связи. */
.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--muted);
}
.dot.on  { background: var(--green); box-shadow: 0 0 0 2px rgba(39, 174, 96, .18); }
.dot.off { background: var(--red);   box-shadow: 0 0 0 2px rgba(235, 87, 87, .18); }

.loc-rest {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
}
.loc-more {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: #2f80ed;
}
.btn-link {
    display: inline-block;
    text-decoration: none;
    padding: 6px 12px;
}


/* ---- строка состояния платы в заголовке карточки контроллера ---- */
/* Всё в одну линию, по нижней границе текста: шкала WiFi по высоте
   совпадает со значком «в сети» и не разъезжается с ним. */
details.node > summary {
    align-items: center;
    row-gap: 6px;
}

.node-meta {
    display: inline-flex;
    align-items: baseline;       /* нижняя граница текста у всех ячеек одна */
    gap: 14px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--muted);
    line-height: 1;
    margin-left: 4px;
}
.node-meta > span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}
.node-meta b { color: var(--ink); font-weight: 600; }

/* Шкала WiFi: пять делений по возрастающей, по высоте равна значку статуса. */
.wifi-scale {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    /* Высота как у значка «в сети»: шкала и статус читаются как одна строка. */
    height: 22px;
    margin: 0;
}
.wifi-scale i {
    display: block;
    width: 3px;
    border-radius: 1px;
    background: #d6dee7;
}
.wifi-scale i.on { background: var(--green); }

/* Бейдж статуса в заголовке: та же высота, что и шкала. */
details.node > summary .badge {
    height: 22px;
    margin-left: auto;
    align-self: center;
}

@media (max-width: 720px) {
    .node-meta { font-size: 11px; gap: 10px; }
}


/* Легенда графиков: цвет и название, без текущих показаний.
   Пункты в одну строку с переносом, разделитель — точка. */
.legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    font-size: 13px;
    line-height: 1.6;
    margin-top: 8px;
}
.legend .lg-dot {
    width: 9px;
    height: 9px;
    margin-right: 6px;
    flex: 0 0 auto;
}

/* Расшифровка точек реле в легенде графика */
.lg-note {
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}
.lg-sub { opacity: .8; }
