:root {
  --navy: #0b1a2e;
  --navy-2: #12243d;
  --ink: #14253c;
  --muted: #5d6d82;
  --line: #e4ebf3;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --blue: #1a6fbf;
  --blue-hover: #155ea3;
  --green: #1a8a5c;
  --green-bg: #e7f6ee;
  --amber: #9a6b00;
  --amber-bg: #fff4d6;
  --red: #b42318;
  --red-bg: #fdecec;
  --violet: #4b3f8a;
  --violet-bg: #eee9fb;
  --shadow: 0 1px 2px rgba(12, 32, 58, .05), 0 10px 28px rgba(12, 32, 58, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: 248px;
  --focus: 0 0 0 3px rgba(26, 111, 191, .22);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: .01em;
}

.hidden { display: none !important; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--navy) 0%, #081422 100%);
  color: #fff;
  padding: 28px 18px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-kicker, .login-kicker {
  display: block;
  font-size: 11px;
  letter-spacing: .28em;
  color: #9bb6d3;
  font-weight: 700;
}
.brand strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 650;
}
.nav { margin-top: 36px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  color: #c5d5e8;
  text-decoration: none;
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(26, 111, 191, .28); color: #fff; }
.sidebar-logout {
  border: 1px solid rgba(255,255,255,.12);
  background: transparent;
  color: #c5d5e8;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 650;
}
.sidebar-logout:hover { color: #fff; background: rgba(255,255,255,.06); }

.workspace { min-width: 0; }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 36px 18px;
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-meta { color: var(--muted); font-size: 13px; }
.menu-toggle { display: none; }
.main { padding: 0 36px 48px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
  border: 1px solid #edf2f7;
}
.kpi .label {
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
}
.kpi .value {
  margin-top: 10px;
  font-size: 34px;
  font-weight: 650;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi.warn .value { color: var(--amber); }
.kpi.ok .value { color: var(--green); }
.kpi.bad .value { color: var(--red); }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #edf2f7;
  padding: 20px 22px;
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 15px;
  letter-spacing: .04em;
}
.dash-grid {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 16px;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover .name { color: var(--blue); }
.list-row .name { font-weight: 650; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
.search { min-width: 240px; flex: 1; }

.btn, .icon-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  border-radius: var(--radius-sm);
}
.btn { padding: 10px 16px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-secondary { background: #eef3f8; color: var(--ink); }
.btn-secondary:hover { background: #e2eaf2; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #931c13; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef3f8;
  color: var(--ink);
}
.icon-btn svg { width: 18px; height: 18px; }

.chip, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip .dot, .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.chip-ok, .badge-ok { background: var(--green-bg); color: var(--green); }
.chip-warn, .badge-warn { background: var(--amber-bg); color: var(--amber); }
.chip-bad, .badge-bad { background: var(--red-bg); color: var(--red); }
.chip-info, .badge-info { background: #e8f1fb; color: var(--blue); }
.chip-lock, .badge-lock { background: var(--violet-bg); color: var(--violet); }
.dot-on { background: var(--green); }
.dot-off { background: var(--red); }

.device-list { display: flex; flex-direction: column; gap: 10px; }
.device-card {
  display: grid;
  grid-template-columns: 1.3fr 1fr .9fr .8fr .7fr .9fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid #edf2f7;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
}
.device-card:hover { border-color: #c9d8ea; }
.device-card .title { font-weight: 700; }
.device-card .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.hero {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.hero h2 { margin: 0; font-size: 26px; }
.hero .id { margin-top: 4px; color: var(--muted); font-weight: 650; }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 16px; }
.tabs a, .tabs button {
  text-decoration: none;
  color: var(--muted);
  background: transparent;
  padding: 9px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}
.tabs a.active, .tabs button.active { background: var(--navy); color: #fff; }

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.app-card {
  background: var(--panel);
  border: 1px solid #edf2f7;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  position: relative;
}
.app-icon, .tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 750;
  color: #fff;
  background: var(--navy);
  margin-bottom: 12px;
  overflow: hidden;
}
.tile-name .tile-icon { margin-bottom: 0; }
.tile-icon img, .icon-preview {
  width: 44px;
  height: 44px;
  object-fit: contain;
  display: block;
  background: #f4f7fb;
}
.icon-preview-box {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.app-card h3, .tile-card h3 { margin: 0; font-size: 16px; }
.app-card .ver { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.app-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.menu {
  position: absolute;
  right: 12px;
  top: 48px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 180px;
  z-index: 5;
  padding: 6px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
}
.menu button:hover { background: #f3f6fa; }
.menu .danger { color: var(--red); }

.tile-table { width: 100%; border-collapse: collapse; }
.tile-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 10px 12px;
}
.tile-table td {
  padding: 14px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}
.tile-table tbody tr { cursor: grab; }
.tile-table tbody tr.drag-over { outline: 2px dashed var(--blue); }
.tile-name { display: flex; align-items: center; gap: 12px; }
.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }

.progress {
  height: 10px;
  background: #e8eef5;
  border-radius: 999px;
  overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--blue); }
.rollout-card { padding: 20px; }
.rollout-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: 13px; font-weight: 650; }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item {
  display: grid;
  grid-template-columns: 76px 14px 1fr;
  gap: 12px;
  padding: 0 0 18px;
}
.tl-item time { color: var(--muted); font-size: 12px; font-weight: 700; padding-top: 2px; }
.tl-rail { position: relative; }
.tl-rail::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 12px;
  bottom: -18px;
  width: 2px;
  background: var(--line);
}
.tl-item:last-child .tl-rail::before { display: none; }
.tl-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--blue);
  margin-top: 4px;
}
.tl-dot.ok { background: var(--green); }
.tl-dot.bad { background: var(--red); }
.tl-dot.warn { background: #d4a017; }
.details {
  margin-top: 10px;
  background: #f7f9fc;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.control-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.control-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.danger-zone {
  border: 1px solid #f3c4c0;
  background: #fff8f8;
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 18px;
}
.danger-zone h3 { margin: 0 0 6px; color: var(--red); font-size: 14px; letter-spacing: .08em; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.form-grid textarea { min-height: 84px; }

.wizard-types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.type-pick {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 22px 16px;
  cursor: pointer;
  text-align: left;
}
.type-pick strong { display: block; margin-bottom: 6px; }
.type-pick.active, .type-pick:hover { border-color: var(--blue); box-shadow: var(--focus); }
.wizard-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }

.empty {
  text-align: center;
  padding: 42px 16px;
  color: var(--muted);
}
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; }

.skeleton { background: linear-gradient(90deg, #edf2f7, #f8fafc, #edf2f7); background-size: 200% 100%; animation: shine 1.2s infinite; border-radius: 12px; height: 88px; }
@keyframes shine { to { background-position: -200% 0; } }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: var(--navy);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  min-width: 240px;
  box-shadow: var(--shadow);
  font-weight: 650;
  font-size: 13px;
}
.toast.bad { background: var(--red); }
.toast.ok { background: #146c49; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 28, .46);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 24px;
}
.modal {
  background: #fff;
  border-radius: 18px;
  width: min(720px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.steps { display: flex; gap: 8px; margin: 0 0 18px; font-size: 12px; font-weight: 700; color: var(--muted); }
.steps span.active { color: var(--blue); }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #07111f, #0c203a 55%, #123152);
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-brand { margin-bottom: 24px; }
.login-brand h1 { margin: 8px 0 6px; }
.login-brand p { margin: 0; color: var(--muted); }
.login-card label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.login-card input { width: 100%; margin-bottom: 16px; }
.login-error { color: var(--red); font-size: 13px; font-weight: 650; margin: -8px 0 14px; }

.tech-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}
.banner {
  background: var(--amber-bg);
  color: var(--amber);
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .device-card { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 30;
    transform: translateX(-110%);
    transition: transform .2s ease;
    width: var(--sidebar);
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .dash-grid, .form-grid, .wizard-types { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .main, .topbar { padding-left: 20px; padding-right: 20px; }
  .device-card { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .kpi-grid, .device-card { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 22px; }
}
