:root{
  --bg0:#f5f6f8;
  --bg1:#ffffff;
  --glass: rgba(255,255,255,.85);
  --glass2: rgba(255,255,255,.92);
  --line: rgba(15,23,42,.10);
  --text: #0f172a;
  --muted: #6b7280;
  --shadow: 0 18px 50px rgba(15,23,42,.08);
  --accent:#e11d48;
  --accent-soft: rgba(225,29,72,.12);
  --accent-line: rgba(225,29,72,.28);
  --r12: 12px;
  --r16: 16px;
  --r20: 20px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}
[data-theme="dark"]{
  --bg0:#0b1020;
  --bg1:#070a13;
  --glass: rgba(255,255,255,.08);
  --glass2: rgba(255,255,255,.12);
  --line: rgba(255,255,255,.12);
  --text:#eaf0ff;
  --muted: rgba(234,240,255,.68);
  --shadow: 0 18px 50px rgba(0,0,0,.55);
  --accent:#e11d48;
  --accent-soft: rgba(225,29,72,.18);
  --accent-line: rgba(225,29,72,.35);
  --bg-overlay: rgba(255,255,255,.03);
}

/* Base */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:var(--sans);
  color:var(--text);
  background: radial-gradient(700px 480px at 12% 8%, rgba(225,29,72,.12), transparent 55%),
              radial-gradient(900px 600px at 88% 20%, rgba(15,23,42,.06), transparent 60%),
              linear-gradient(180deg, var(--bg0), var(--bg1));
}

/* Background glow decorations */
.bg{
  min-height:100%;
  padding:24px;
}
.bg:before, .bg:after{
  content:"";
  position:fixed;
  inset:auto;
  width:520px; height:520px;
  filter: blur(60px);
  opacity:.18;
  z-index:-1;
  border-radius:999px;
}
.bg:before{
  left:-160px; top:-140px;
  background: radial-gradient(circle at 30% 30%, rgba(225,29,72,.45), transparent 60%);
}
.bg:after{
  right:-180px; bottom:-200px;
  background: radial-gradient(circle at 50% 50%, rgba(15,23,42,.18), transparent 65%);
}

/* Layout */
.app{
  max-width: 1280px;
  margin: 0 auto;
  display:flex;
  gap:18px;
}
.sidebar-toggle:checked ~ .sidebar{
  transform: translateX(0);
}
.sidebar{
  transition: transform 0.25s ease;
}

.sidebar{
  width: 270px;
  padding: 18px;
  border-radius: var(--r20);
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  display:flex;
  flex-direction:column;
}

.main{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:14px;
}

/* Brand */
.brand{
  display:flex;
  align-items:center;
  gap:12px;
  padding: 10px 10px 16px;
}
.logo-img{
  height: 32px;
  width: auto;
  object-fit: contain;
  display: block;
}
.brand-text{
  display:flex;
  flex-direction:column;
  gap:4px;
}
.brand-title{font-weight:700; letter-spacing:.2px}
.brand-subtitle{font-size:12px; color:var(--muted); margin-top:2px}

/* Nav */
.nav{display:flex; flex-direction:column; gap:6px; padding: 6px 8px}
.nav-item{
  display:flex; align-items:center; gap:10px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--muted);
  text-decoration:none;
  border: 1px solid transparent;
}
.nav-item:hover{
  color: var(--text);
  background: rgba(225,29,72,.06);
  border-color: rgba(225,29,72,.12);
}
.nav-item.active{
  color: var(--text);
  background: rgba(225,29,72,.10);
  border-color: var(--accent-line);
}
.dot{
  width:10px;height:10px;border-radius:999px;
  background: rgba(225,29,72,.4);
  box-shadow: 0 0 0 6px rgba(225,29,72,.08);
}
.nav-item.active .dot{
  background: radial-gradient(circle at 30% 30%, rgba(225,29,72,.9), rgba(239,68,68,.9));
  box-shadow: 0 0 0 6px rgba(225,29,72,.14);
}

/* Sidebar footer */
.sidebar-footer{
  margin-top:auto;
  padding: 10px 10px 6px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.pill{
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(225,29,72,.06);
  border: 1px solid rgba(225,29,72,.12);
}
.pill-label{color:var(--muted); font-size:12px}
.pill-value{
  font-weight:700;
  font-size:12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}

/* Topbar */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 14px 0;
}
.crumbs{
  color: var(--muted);
  font-size: 13px;
}
.crumbs span{color:var(--text)}
.title{
  margin: 6px 0 0;
  font-size: 28px;
  letter-spacing: .2px;
}
.top-actions{
  display:flex;
  align-items:center;
  gap:10px;
}
.search{
  width: 320px;
  max-width: 40vw;
  background: rgba(15,23,42,.03);
  border: 1px solid rgba(15,23,42,.08);
  border-radius: 16px;
  padding: 8px 10px;
  backdrop-filter: blur(10px);
}
.search input{
  width:100%;
  background: transparent;
  border:0;
  outline:none;
  color: var(--text);
  font-size: 14px;
}
.search input::placeholder{color: #9ca3af}
.icon-btn{
  width: 42px; height: 42px;
  border-radius: 16px;
  border: 1px solid rgba(15,23,42,.08);
  background: rgba(15,23,42,.04);
  color: var(--text);
  cursor:pointer;
}
.icon-btn:hover{background: rgba(15,23,42,.08)}
.icon-bell{
  display:block;
  width:18px;height:18px;
  margin: 0 auto;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #ef4444);
  filter: saturate(1.05);
  box-shadow: 0 10px 25px rgba(225,29,72,.18);
}
.avatar{
  width: 42px; height: 42px;
  display:grid; place-items:center;
  border-radius: 16px;
  background: rgba(15,23,42,.04);
  border: 1px solid rgba(15,23,42,.10);
  font-weight: 700;
}
.user-avatar{
  width: 44px; height: 44px;
  display:grid; place-items:center;
  border-radius: 999px;
  background: rgba(15,23,42,.06);
  border: 1px solid rgba(15,23,42,.10);
  box-shadow: 0 8px 18px rgba(15,23,42,.08);
}
.user-avatar img{ width:22px; height:22px; }
.burger{
  width: 42px;
  height: 42px;
  display:none;
  flex-direction:column;
  justify-content:center;
  gap:5px;
}
.burger span{
  height:2px;
  width:22px;
  background: var(--text);
  display:block;
}

/* Cards + grid */
.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  padding: 0 14px 14px;
}

.card{
  background: var(--glass2);
  border: 1px solid rgba(15,23,42,.08);
  border-radius: var(--r20);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 14px;
  min-width:0;
}

.kpi{ grid-column: span 3; display:flex; align-items:center; justify-content:space-between; gap:10px; }
.kpi-label{ color: var(--muted); font-size: 13px; }
.kpi-value{ font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: .2px; }
.kpi-meta{ margin-top: 6px; color: var(--muted); font-size: 12px; }
.kpi-icon{
  width: 44px; height: 44px;
  display:grid; place-items:center;
  border-radius: 16px;
  background: rgba(225,29,72,.08);
  border: 1px solid var(--accent-line);
  font-size: 18px;
}

.up{ color: #16a34a; font-weight:700; }
.down{ color: rgba(255, 82, 82, .95); font-weight:700; }
.warn{ color: rgba(255, 193, 7, .95); font-weight:700; }

.card-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  margin-bottom: 12px;
}
.card-title{ font-weight: 800; letter-spacing: .2px; }
.card-subtitle{ color: var(--muted); font-size: 12px; margin-top: 4px; }

.chart{ grid-column: span 8; }
.table{ grid-column: span 8; }
.actions{ grid-column: span 4; }
.model{ grid-column: span 4; display:flex; flex-direction:column; gap:12px; }
.model-body{
  display:grid;
  gap:10px;
  padding: 8px 0;
}
.model-row{
  display:flex;
  justify-content:space-between;
  gap:12px;
  border-bottom:1px dashed rgba(15,23,42,.08);
  padding-bottom:8px;
}
.model-row:last-child{ border-bottom:0; padding-bottom:0; }
.model-row .label{ color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing:.4px;}
.model-pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  border-radius: 12px;
  background: rgba(15,23,42,.04);
  border: 1px solid rgba(15,23,42,.08);
  font-weight: 800;
  color: var(--text);
}
.model-pill.alert{
  background: rgba(225,29,72,.12);
  border-color: rgba(225,29,72,.22);
  color: rgba(190,18,60,1);
}

.chart-box{
  height: 220px;
  border-radius: var(--r16);
  background: var(--glass2);
  border: 1px solid var(--line);
  position: relative;
  overflow:hidden;
  box-shadow: 0 16px 36px rgba(15,23,42,.06);
}
.chart-box.chartjs{ height: 300px; padding: 12px; }
.chart-grid{
  position:absolute; inset:0;
  background:
    linear-gradient(to right, rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / 52px 52px,
    linear-gradient(to bottom, rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 52px 52px;
  opacity:.55;
}
.spark{
  position:absolute;
  inset: 18px 16px 18px 16px;
  display:flex;
  align-items:flex-end;
  gap:10px;
}
.spark span{
  flex:1;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent), #ef4444);
  border: 1px solid var(--accent-line);
  box-shadow: 0 18px 35px rgba(225,29,72,.16);
}
.chart-box.small{ height: 160px; }
.chip-row{display:flex;gap:8px;flex-wrap:wrap}
.chip{
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(15,23,42,.10);
  background: rgba(15,23,42,.04);
  color: var(--text);
  font-weight:800;
  font-size:12px;
  cursor:pointer;
}
.chip.active-chip{
  background: var(--accent);
  color:#fff;
  border-color: var(--accent-line);
  box-shadow: 0 8px 18px rgba(225,29,72,.18);
}

/* Filters & sensor picker */
.filters{ margin: 0 14px 14px; padding:14px; }
.filter-row{
  display:flex;
  flex-wrap:wrap;
  gap:12px;
}
.filter{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size: 13px;
  color: var(--muted);
  min-width: 180px;
}
.filter select{
  padding:10px 12px;
  border-radius: 12px;
  border:1px solid var(--line);
  background: var(--bg1);
  color: var(--text);
  font-weight:600;
  box-shadow: 0 6px 14px rgba(15,23,42,.04);
}
.filter select:focus{
  outline:2px solid var(--accent-soft);
  border-color: var(--accent-line);
}
.filter-actions{
  margin-top:14px;
  display:flex;
  gap:10px;
  align-items:center;
}
/* Table */
.table-wrap{ overflow:auto; border-radius: var(--r16); }
.table-wrap::-webkit-scrollbar{
  height: 8px;
  width: 10px;
  background: var(--bg0);
}
.table-wrap::-webkit-scrollbar-thumb{
  background: var(--line);
  border-radius: 999px;
}
.table-wrap::-webkit-scrollbar-thumb:hover{
  background: var(--accent-line);
}
table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 640px;
}
thead th{
  text-align:left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 12px;
  border-bottom: 1px solid rgba(15,23,42,.08);
}
tbody td{
  padding: 12px 12px;
  border-bottom: 1px solid rgba(15,23,42,.06);
  color: var(--text);
  font-size: 14px;
}
tbody tr:hover td{ background: rgba(225,29,72,.04); }
.row-title{ display:flex; align-items:center; gap:10px; }
.svc-dot{
  width:10px;height:10px;border-radius:999px;
  box-shadow: 0 0 0 6px rgba(225,29,72,.08);
}
.svc-dot.ok{ background: #16a34a; }
.svc-dot.warn{ background: rgba(255,193,7,.95); }
.svc-dot.down{ background: rgba(255,82,82,.95); }

.badge{
  display:inline-flex;
  align-items:center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge.ok{ background: rgba(22,163,74,.12); border-color: rgba(22,163,74,.24); color: #166534; }
.badge.warn{ background: rgba(255,193,7,.10); border-color: rgba(255,193,7,.22); color: rgba(255,193,7,.95); }
.badge.down{ background: rgba(255,82,82,.10); border-color: rgba(255,82,82,.22); color: rgba(255,82,82,.95); }

.mono{ font-family: var(--mono); font-size: 13px; color:#111827; }

/* Buttons */
.btn{
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(15,23,42,.03);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  cursor:pointer;
  font-weight: 700;
}
.btn:hover{ background: rgba(15,23,42,.06); }
.btn-primary{
  background: linear-gradient(135deg, var(--accent), #ef4444);
  border-color: var(--accent-line);
  color:#fff;
}
.btn-ghost{
  background: transparent;
  border-color: rgba(15,23,42,.10);
}

/* Actions */
.action-grid{
  display:grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.action{
  width:100%;
  display:flex;
  align-items:center;
  gap:12px;
  padding: 12px;
  border-radius: var(--r16);
  border: 1px solid rgba(15,23,42,.08);
  background: rgba(15,23,42,.03);
  color: var(--text);
  cursor:pointer;
  text-align:left;
}
.action:hover{ background: rgba(225,29,72,.05); }
.action-ico{
  width:40px;height:40px;
  border-radius: 14px;
  display:grid; place-items:center;
  background: rgba(225,29,72,.1);
  border: 1px solid var(--accent-line);
}
.action-title{ font-weight:800; }
.action-sub{ color: var(--muted); font-size: 12px; margin-top: 2px; }
.icon-img{ width:22px; height:22px; display:block; }
.theme-icon{ display:none; }
[data-theme="light"] .theme-toggle .icon-img{ margin:0 auto; }
[data-theme="dark"] .theme-toggle .icon-img{ margin:0 auto; }
[data-theme="light"] .theme-icon.light-icon{ display:block; }
[data-theme="dark"] .theme-icon.dark-icon{ display:block; filter: invert(1) brightness(1.4); }
[data-theme="dark"] .icon-img{ filter: invert(1) brightness(1.3); }

/* Services taskboard cards */
.taskboard-shell{
  margin: 0 14px 14px;
  padding:14px;
  border-radius: var(--r20);
  background: var(--glass2);
  border:1px solid var(--line);
  box-shadow: 0 18px 36px rgba(15,23,42,.05);
}
.taskboard-filters{
  display:flex;
  gap:12px;
  margin-bottom:14px;
}
.taskboard-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap:14px;
}
.division-card{
  border:1px solid var(--line);
  border-radius: var(--r16);
  background: var(--glass);
  padding:14px;
  box-shadow: 0 12px 28px rgba(15,23,42,.08);
}
.division-title{ margin:0 0 6px; font-size:16px; font-weight:900; }
.machine-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap:10px;
  margin-top:10px;
}
.machine-card{
  padding:12px;
  border-radius: var(--r12);
  color:#fff;
  box-shadow: 0 10px 24px rgba(15,23,42,.08);
}
.machine-card.ok{ background: #16a34a; }
.machine-card.warn{ background: #e11d48; }
.machine-name{ font-weight:800; margin-bottom:6px; text-transform: lowercase; }
.machine-meta{ font-size:12px; line-height:1.3; color: rgba(255,255,255,.9); }
.machine-anom{ margin-top:6px; font-weight:800; }
.machine-anom.ok{ color: #e5f8eb; }
.machine-anom.warn{ color: #ffe4e6; }

/* Settings form */
.settings-page{
  margin: 0 14px 14px;
  display:grid;
  gap:12px;
}
.settings-page-header{
  padding: 4px 2px 2px;
}
.settings-sections{
  display:grid;
  gap:14px;
  width:100%;
  max-width: 860px;
}
.settings-accordion{
  border:2px solid rgba(225,29,72,.15);
  border-radius: 18px;
  background: rgba(255,255,255,.56);
  padding: 14px;
  box-shadow: 0 12px 28px rgba(15,23,42,.05);
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
[data-theme="dark"] .settings-accordion{
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.10);
  box-shadow: 0 12px 28px rgba(0,0,0,.22);
}
.settings-summary{
  list-style:none;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  position: relative;
}
.settings-summary::-webkit-details-marker{ display:none; }
.settings-summary:focus-visible{
  outline: 2px solid var(--accent-line);
  outline-offset: 6px;
  border-radius: 12px;
}
.settings-summary-main{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}
.settings-service-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 52px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--text);
  background: rgba(15,23,42,.05);
  flex-shrink: 0;
}
.settings-summary-copy{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:2px;
}
.settings-summary-title{
  font-weight:800;
  color: var(--text);
  letter-spacing:.2px;
}
.settings-summary-subtitle{
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-summary-arrow{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  height: 34px;
  width: 40px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.08);
  background: rgba(15,23,42,.03);
  flex-shrink: 0;
  transition: transform .18s ease, background-color .18s ease, border-color .18s ease;
}
.settings-summary-arrow::before{
  content:"";
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  transform: translateY(-1px) rotate(45deg);
  opacity: .7;
}
.settings-accordion:hover{
  border-color: rgba(225,29,72,.22);
}
.settings-accordion[open]{
  border-color: rgba(225,29,72,.28);
  box-shadow: 0 14px 30px rgba(225,29,72,.08);
  background: rgba(255,255,255,.66);
}
[data-theme="dark"] .settings-accordion[open]{
  background: rgba(255,255,255,.05);
}
.settings-accordion[open] .settings-summary-arrow{
  border-color: rgba(225,29,72,.18);
  background: rgba(225,29,72,.06);
  transform: rotate(180deg);
}
.settings-accordion[data-service="mqtt"] .settings-service-badge{
  background: rgba(14,165,233,.10);
  border-color: rgba(14,165,233,.20);
  color: #0369a1;
}
.settings-accordion[data-service="ros2"] .settings-service-badge{
  background: rgba(249,115,22,.10);
  border-color: rgba(249,115,22,.20);
  color: #c2410c;
}
.settings-accordion[data-service="postgres"] .settings-service-badge{
  background: rgba(59,130,246,.10);
  border-color: rgba(59,130,246,.20);
  color: #1d4ed8;
}
.settings-form{
  display:grid;
  gap:12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  padding-top: 14px;
  margin-top: 10px;
  border-top:1px solid var(--line);
}
.form-field{ display:flex; flex-direction:column; gap:6px; font-size:13px; color: var(--muted); }
.form-field input{
  padding:10px 12px;
  border-radius: 12px;
  border:1px solid var(--line);
  background: var(--bg1);
  color: var(--text);
  font-weight:600;
  box-shadow: 0 6px 14px rgba(15,23,42,.04);
}
.form-field input:focus{
  outline:2px solid var(--accent-soft);
  border-color: var(--accent-line);
}
.form-actions{ display:flex; gap:10px; align-items:center; margin-top:4px; }
.settings-form .form-actions{ grid-column: 1 / -1; }

/* Footer */
.footer{
  display:flex;
  justify-content:space-between;
  padding: 6px 14px 14px;
  color: var(--muted);
  font-size: 12px;
}
.muted{ color: var(--muted); }

/* Responsive */
@media (max-width: 1100px){
  .kpi{ grid-column: span 6; }
  .chart{ grid-column: span 12; }
  .table{ grid-column: span 12; }
  .actions{ grid-column: span 12; }
  .model{ grid-column: span 12; }
  .search{ width: 240px; }
}
@media (max-width: 860px){
  .app{ flex-direction:column; }
  .burger{ display:flex; }
  .sidebar{
    position: fixed;
    top:0; left:0;
    height:100vh;
    z-index:50;
    max-width: 260px;
    transform: translateX(-110%);
    box-shadow: 0 20px 40px rgba(0,0,0,.25);
  }
  .sidebar-toggle:checked ~ .sidebar{
    transform: translateX(0);
  }
  .main{
    margin-left:0;
  }
}
@media (max-width: 520px){
  .topbar{ flex-direction:column; align-items:flex-start; gap:10px; }
  .top-actions{ width:100%; }
  .search{ width:100%; max-width:100%; }
  .settings-page{ margin-left: 14px; margin-right: 14px; }
  .settings-accordion{ padding: 12px; border-radius: 16px; }
  .settings-summary{
    align-items:flex-start;
    padding: 0;
  }
  .settings-summary-main{
    width:100%;
    align-items:flex-start;
  }
  .settings-summary-subtitle{
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .settings-summary-arrow{
    margin-left: 62px;
  }
  .settings-form{
    grid-template-columns: 1fr;
  }
}
