/**
 * Main style
 *
 * Copyright (c) 2026 IOTMETVIS
 * All rights reserved.
 *
 * This source code is the private property of IOTMETVIS.
 * Unauthorized copying, modification, distribution, or use
 * of this file, in whole or in part, is strictly prohibited
 * without prior written permission from the author.
 */

:root {
  --bg:          #1a1a1a;
  --bg-dark:     #0f0f0f;
  --panel:       #252526;
  --frame:       #2d2d2d;
  --frame2:      #3a3a3a;
  --title-bar:   #1f3d6e;
  --border:      #6e6e80;
  --border-dim:  #3a3a3a;
  --text:        #ffffff;
  --text-dim:    #c8c8c8;
  --text-muted:  #808080;
  --accent:      #4296fa;
  --accent-dim:  rgba(66,150,250,0.25);
  --green:       #6ad99a;
  --red:         #e06c75;
  --orange:      #e5c07b;
  --sidebar-w:   210px;
  --sidebar-col: 42px;
  --header-h:    28px;
  --gap:         10px;
  --hover:       #2a2a2a;
}

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

a { text-decoration: none; }

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: var(--bg-dark);
  border-right: 1px solid var(--border-dim);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}

#sidebar.collapsed  { width: var(--sidebar-col); }
#sidebar.mob-hidden { transform: translateX(-100%); }

.sb-logo {
  height: var(--header-h);
  background: var(--title-bar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px;
  gap: 8px;
  flex-shrink: 0;
}

.sb-logo-icon {
  width: 14px; height: 14px;
  background: var(--accent);
  flex-shrink: 0;
}

.sb-logo-text {
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.15s;
}

#sidebar.collapsed .sb-logo-text { opacity: 0; }

.sb-logo-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Sidebar Close Button ── */
.sb-close-btn {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.sb-close-btn:hover {
  background: var(--frame2);
  color: var(--text);
}

@media (max-width: 680px) {
  .sb-close-btn {
    display: block;
  }
}

.sb-nav { flex: 1; overflow-y: auto; padding: 3px 0; }
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--frame2); }

.sb-section {
  font-size: 9.5px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 9px 3px;
  white-space: nowrap;
  transition: opacity 0.15s;
}

#sidebar.collapsed .sb-section { opacity: 0; }

.sb-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 9px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
  border-left: 2px solid transparent;
  text-decoration: none;
}

.sb-item:hover  { background: var(--frame); color: var(--text); }
.sb-item.active { background: var(--accent-dim); color: var(--text); border-left-color: var(--accent); }

.sb-icon {
  width: 14px; height: 14px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.sb-icon svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

.icon-svg {
  width: 20px;
  height: 20px;
  fill: var(--text-dim);
  transition: fill 0.2s ease;
}

.sb-item:hover .icon-svg {
  fill: var(--text);
}

.sb-item.active .icon-svg {
  fill: var(--accent);
}

.icon-xs { width: 16px; height: 16px; }
.icon-sm { width: 20px; height: 20px; }
.icon-md { width: 24px; height: 24px; }
.icon-lg { width: 32px; height: 32px; }
.icon-xl { width: 48px; height: 48px; }

.icon-primary { fill: var(--accent); }
.icon-success { fill: var(--green); }
.icon-warning { fill: var(--orange); }
.icon-danger { fill: var(--red); }
.icon-muted { fill: var(--text-dim); }

.icon-hover:hover {
  transform: scale(1.1);
  transition: transform 0.2s ease;
}

.icon-spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.sb-label { flex: 1; transition: opacity 0.15s; }
.sb-arrow { font-size: 9px; color: var(--text-muted); transition: transform 0.15s; }

#sidebar.collapsed .sb-label { opacity: 0; pointer-events: none; }
#sidebar.collapsed .sb-arrow { opacity: 0; }

.sb-item.open .sb-arrow { transform: rotate(90deg); }

.sb-drop { overflow: hidden; max-height: 0; transition: max-height 0.2s ease; }
.sb-drop.open { max-height: 160px; }
#sidebar.collapsed .sb-drop { display: none; }

.sb-sub {
  display: flex; align-items: center;
  padding: 4px 9px 4px 30px;
  font-size: 11.5px; color: var(--text-muted);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  text-decoration: none;
}

.sb-sub:hover  { background: var(--frame); color: var(--text-dim); }
.sb-sub.active { color: var(--accent); }

.sb-foot {
  border-top: 1px solid var(--border-dim);
  padding: 6px 9px;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

#sidebar.collapsed .sb-foot { opacity: 0; }

.sb-foot-row {
  display: flex; justify-content: space-between;
  padding: 2px 0; color: var(--text-muted); font-size: 11px;
}

.sb-val { font-family: 'Consolas', monospace; color: var(--accent); font-size: 11px; }
.sb-ok  { color: var(--green); }

#layout {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}

#layout.sb-col { margin-left: var(--sidebar-col); }
#layout.sb-mob { margin-left: 0; }

#header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
}

.hdr-left { display: flex; align-items: center; gap: 10px; }

#toggle-btn {
  background: none; border: none; cursor: pointer;
  padding: 3px; display: flex; flex-direction: column; gap: 3px;
}

#toggle-btn span {
  display: block; width: 15px; height: 1.5px;
  background: var(--text-dim);
}

#toggle-btn:hover span { background: var(--text); }

.hdr-path { font-size: 12px; color: var(--text-muted); }
.hdr-path strong { color: var(--text); font-weight: 400; }

.hdr-right { display: flex; align-items: center; gap: 14px; }

.hdr-clock {
  font-family: 'Consolas', monospace;
  font-size: 12px; color: var(--accent);
}

.hdr-station { font-size: 11px; color: var(--text-muted); }

#main { flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 10px; }

.win {
  background: var(--bg-dark);
  border: 1px solid var(--border-dim);
}

.win-title {
  background: var(--title-bar);
  padding: 3px 8px;
  font-size: 12px;
  color: var(--text);
  font-weight: 400;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.win-title small { font-size: 10px; color: rgba(255,255,255,0.5); }
.win-body { padding: 8px; }

.pg-head {
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}

.pg-title { font-size: 14px; font-weight: 600; }
.pg-sub   { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.pg-acts  { display: flex; gap: 5px; }

.btn {
  padding: 3px 12px;
  border: 1px solid var(--border-dim);
  background: var(--frame);
  color: var(--text-dim);
  font-size: 12px; cursor: pointer;
  font-family: inherit;
  transition: background 0.1s, color 0.1s;
}

.btn:hover { background: var(--frame2); color: var(--text); }

.btn-accent {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-accent:hover { background: var(--accent); color: #000; }

.chart-controls {
  margin-bottom: 10px;
}

.time-range-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.btn-time-range {
  padding: 4px 8px;
  font-size: 11px;
  min-width: 35px;
}

.btn-time-range.active {
  background: var(--accent);
  color: #000;
}

.btn-time-range:hover:not(.active) {
  background: var(--frame2);
}

hr {
  border: none;
  height: 1px;
  background: var(--title-bar);
  margin: 1px 0;
}

.grid { display: grid; gap: var(--gap); }
.g2    { grid-template-columns: repeat(2,1fr); }
.g3    { grid-template-columns: repeat(3,1fr); }
.g4    { grid-template-columns: repeat(4,1fr); }
.g2-1  { grid-template-columns: 2fr 1fr; }
.g1-2  { grid-template-columns: 1fr 2fr; }

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-row-2 { min-height: calc(2 * (var(--gap) + 100px)); }

@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2,1fr); }
  .g3 { grid-template-columns: repeat(2,1fr); }
  .span-3 { grid-column: span 2; }
  .span-4 { grid-column: span 2; }
}

@media (max-width: 600px) {
  .g4, .g3, .g2, .g2-1, .g1-2 { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: span 1; }
}

@media (max-width: 680px) {
  #main { padding: 6px; }
  .hdr-station, .hdr-clock, .hdr-path { display: none; }
}

.stat-win {
  background: var(--bg-dark);
  border: 1px solid var(--border-dim);
}

.stat-win .win-title { border-left: 2px solid var(--accent); }
.stat-win.green  .win-title { border-left-color: var(--green); }
.stat-win.orange .win-title { border-left-color: var(--orange); }
.stat-win.red    .win-title { border-left-color: var(--red); }

.stat-body { padding: 8px 10px 10px; }

.stat-val {
  font-family: 'Consolas', monospace;
  font-size: 26px; line-height: 1;
  display: flex;
  gap: 12px;
  justify-content: flex-start;
}

.stat-val span {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.stat-val img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.stat-unit { font-size: 13px; color: var(--text-muted); margin-left: 2px; }
.stat-delta { font-size: 11px; margin-top: 5px; }

.up   { color: var(--green);    }
.down { color: var(--red);      }
.neu  { color: var(--text-muted); }

.bar { height: 3px; background: var(--frame2); margin-top: 7px; }

.bar-fill { height: 100%; background: var(--accent); transition: width 0.5s; }
.bar-fill.green  { background: var(--green); }
.bar-fill.orange { background: var(--orange); }
.bar-fill.red    { background: var(--red); }

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100% !important; }

.tbl { width: 100%; border-collapse: collapse; }

.tbl th {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--text-muted);
  padding: 5px 10px; text-align: left;
  background: var(--frame);
  border-bottom: 1px solid var(--border-dim);
}

.tbl td {
  padding: 5px 10px; font-size: 12px;
  border-bottom: 1px solid var(--border-dim);
  color: var(--text-dim);
}

.tbl td:first-child { color: var(--text); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--frame); }

.badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  border: 1px solid;
}

.badge-blue   { color: var(--accent);  border-color: var(--accent);  }
.badge-green  { color: var(--green);   border-color: var(--green);   }
.badge-orange { color: var(--orange);  border-color: var(--orange);  }
.badge-red    { color: var(--red);     border-color: var(--red);     }

.sr {
  display: flex; align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-dim);
  font-size: 12px;
}

.sr:last-child { border-bottom: none; }

.dot { width: 7px; height: 7px; flex-shrink: 0; margin-right: 8px; }
.dot-g { background: var(--green);  }
.dot-o { background: var(--orange); }
.dot-r { background: var(--red);    }

.sr-name { flex: 1; color: var(--text-dim); }
.sr-val  { font-family: 'Consolas', monospace; font-size: 11px; color: var(--text-muted); }

.al-list { display: flex; flex-direction: column; gap: 4px; }

.al-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 8px;
  background: var(--frame);
  border-left: 2px solid var(--accent);
}

.al-item.warn   { border-left-color: var(--orange); }
.al-item.danger { border-left-color: var(--red);    }
.al-item.ok     { border-left-color: var(--green);  }

.al-body { flex: 1; }
.al-title { font-size: 12px; font-weight: 600; color: var(--text); }
.al-desc  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.al-time {
  font-family: 'Consolas', monospace;
  font-size: 10px; color: var(--text-muted);
  flex-shrink: 0; padding-top: 1px;
}

.fc-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.fc-strip::-webkit-scrollbar { height: 3px; }
.fc-strip::-webkit-scrollbar-thumb { background: var(--frame2); }

.fc-card {
  flex: 1; min-width: 78px;
  background: var(--frame);
  border: 1px solid var(--border-dim);
  padding: 8px 6px; text-align: center;
}

.fc-card.today { background: var(--accent-dim); border-color: var(--accent); }

.fc-day  { font-size: 9px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 5px; }
.fc-hi   { font-family: 'Consolas', monospace; font-size: 17px; }
.fc-lo   { font-size: 11px; color: var(--text-muted); }
.fc-cond { font-size: 10px; color: var(--text-muted); margin-top: 3px; }
.fc-card.today .fc-day  { color: var(--accent); }
.fc-card.today .fc-cond { color: var(--text-dim); }

.banner {
  background: var(--panel);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
}

.bn-temp  { font-family: 'Consolas', monospace; font-size: 42px; line-height: 1; }
.bn-cond  { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.bn-loc   { font-size: 10px; color: var(--text-muted); margin-top: 3px; letter-spacing: 0.8px; text-transform: uppercase; }
.bn-stats { display: flex; gap: 24px; flex-wrap: wrap; }
.bn-val   { font-family: 'Consolas', monospace; font-size: 18px; }
.bn-lbl   { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.sg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.sg-item {
  background: var(--frame);
  border: 1px solid var(--border-dim);
  padding: 7px 9px;
}

.sg-lbl { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 3px; }
.sg-val { font-family: 'Consolas', monospace; font-size: 17px; }
.sg-val small { font-size: 10px; color: var(--text-muted); }

.s-block { margin-bottom: 14px; }

.s-block-title {
  font-size: 9.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted);
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-dim);
  margin-bottom: 2px;
}

.s-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-dim);
}

.s-row:last-child { border-bottom: none; }

.s-lbl  { font-size: 12.5px; color: var(--text-dim); }
.s-desc { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }

.s-row select,
.s-row input[type="text"] {
  background: var(--frame);
  border: 1px solid var(--border-dim);
  color: var(--text);
  font-size: 12px; padding: 3px 7px;
  font-family: inherit; outline: none;
}

.s-row select:focus,
.s-row input[type="text"]:focus { border-color: var(--accent); }

/* toggle */
.tog {
  width: 34px; height: 16px;
  background: var(--frame2);
  border: 1px solid var(--border-dim);
  cursor: pointer; position: relative;
  flex-shrink: 0; transition: background 0.15s;
}

.tog.on { background: var(--accent-dim); border-color: var(--accent); }

.tog::after {
  content: ''; position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  background: var(--text-muted);
  transition: left 0.15s, background 0.15s;
}

.tog.on::after { left: 20px; background: var(--accent); }

#footer {
  position: sticky;
  bottom: 0;
  z-index: 200;
  border-top: 1px solid var(--border-dim);
  background: var(--bg-dark);
  padding: 6px 12px;
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 6px;
  font-size: 11px; color: var(--text-muted);
  min-height: 45px;
}

.ft-brand { color: var(--accent); }
.ft-links { display: flex; gap: 14px; }
.ft-links a { color: var(--text-muted); text-decoration: none; }
.ft-links a:hover { color: var(--text-dim); }

#overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.55); z-index: 200;
}

#overlay.show { display: block; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--frame2); }

#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 15, 15, 0.05);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 14px;
}

#loading-overlay.show {
  display: flex;
}

#loading-overlay img {
  width: 48px;
  height: 48px;
}

#loading-overlay span {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}