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

:root {
  --bg:        #080b14;
  --surface:   #0f1320;
  --surface2:  #161c2e;
  --border:    #1e2640;
  --accent:    #4f6ef7;
  --accent2:   #6c3ef7;
  --text:      #d8e0f0;
  --muted:     #6b7a9e;
  --green:     #22d3a0;
  --yellow:    #f5b942;
  --red:       #f25555;
  --blue:      #38b6ff;
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    10px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── LAYOUT ─────────────────────────────────────── */

.layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: .95rem; }
.brand-sub  { font-size: .7rem; color: var(--muted); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  flex: 1;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: .7;
}
.nav-link:hover  { background: var(--surface2); color: var(--text); }
.nav-link:hover svg { opacity: 1; }
.nav-link.active { background: rgba(79,110,247,.15); color: var(--accent); }
.nav-link.active svg { opacity: 1; }

.sidebar-status {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sys-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sys-label { font-size: .75rem; color: var(--muted); }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-red    { background: var(--red); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

/* ── CONTENT ─────────────────────────────────────── */

.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── TOPBAR ─────────────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle { display: none; background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }

.topbar-title { font-weight: 600; font-size: .95rem; flex: 1; }

.status-pill {
  font-size: .73rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: .2px;
}
.status-pill.connected    { background: rgba(34,211,160,.12); color: var(--green); }
.status-pill.disconnected { background: rgba(242,85,85,.1);   color: var(--red);   }
.status-pill.qr           { background: rgba(245,185,66,.1);  color: var(--yellow);}
.status-pill.pairing      { background: rgba(245,185,66,.1);  color: var(--yellow);}

/* ── SECTIONS ─────────────────────────────────────── */

.section { display: none; padding: 24px; }
.section.active { display: block; }

/* ── KPIs ─────────────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.kpi-value { font-size: 2.2rem; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.kpi-label { font-size: .73rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── CARDS ─────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.card-head h2 { font-size: .9rem; font-weight: 600; }

/* ── TABLE ─────────────────────────────────────── */

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

table { width: 100%; border-collapse: collapse; font-size: .82rem; }

th {
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .4px;
}
td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(30,38,64,.6);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.empty { text-align: center; color: var(--muted); padding: 32px; }

/* ── BADGES ─────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-green  { background: rgba(34,211,160,.12);  color: var(--green);  }
.badge-yellow { background: rgba(245,185,66,.12);  color: var(--yellow); }
.badge-red    { background: rgba(242,85,85,.1);    color: var(--red);    }
.badge-gray   { background: rgba(107,122,158,.1);  color: var(--muted);  }
.badge-blue   { background: rgba(56,182,255,.1);   color: var(--blue);   }

/* ── STATUS BANNER ─────────────────────────────────────── */

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: .88rem;
  margin-bottom: 16px;
}
.status-banner.connected    { background: rgba(34,211,160,.08);  color: var(--green);  }
.status-banner.disconnected { background: rgba(242,85,85,.07);   color: var(--red);    }
.status-banner.qr           { background: rgba(245,185,66,.08);  color: var(--yellow); }
.status-banner.pairing      { background: rgba(245,185,66,.08);  color: var(--yellow); }

.pulse {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── QR + PAIRING ─────────────────────────────────────── */

.qr-wrap, .pairing-wrap { margin-bottom: 16px; }

.qr-instructions {
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.6;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 7px;
  border-left: 3px solid var(--yellow);
  margin-bottom: 16px;
}

.qr-frame {
  display: flex;
  justify-content: center;
}
.qr-frame img {
  width: 240px; height: 240px;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
}

.pairing-code {
  text-align: center;
  font-family: 'Courier New', monospace;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 12px;
  color: var(--accent);
  padding: 24px;
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: 12px;
}

/* ── CONNECT PANEL ─────────────────────────────────────── */

.connect-panel {
  margin-top: 20px;
  padding: 18px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.panel-label { font-size: .78rem; color: var(--muted); margin-bottom: 10px; font-weight: 500; }

.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.input-row input {
  flex: 1;
  min-width: 180px;
  padding: 9px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .88rem;
  outline: none;
  transition: border-color .2s;
}
.input-row input:focus { border-color: var(--accent); }

.panel-divider {
  text-align: center;
  color: var(--muted);
  font-size: .75rem;
  margin: 12px 0;
  position: relative;
}
.panel-divider::before, .panel-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 44%;
  height: 1px;
  background: var(--border);
}
.panel-divider::before { left: 0; }
.panel-divider::after  { right: 0; }

/* ── TELEGRAM SECTION ─────────────────────────────────────── */

.tg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tg-bot-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tg-username { font-weight: 700; font-size: .95rem; color: var(--blue); }

.cmd-list { display: flex; flex-direction: column; gap: 0; margin-top: 14px; }
.cmd-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
}
.cmd-row:last-child { border-bottom: none; }
.cmd-row code {
  font-family: monospace;
  font-size: .82rem;
  color: var(--accent);
  background: rgba(79,110,247,.1);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  min-width: 90px;
}
.cmd-row span { color: var(--muted); }

/* ── HARDWARE ─────────────────────────────────────── */

.hw-list { display: flex; flex-direction: column; gap: 0; }

.hw-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.hw-row:last-child { border-bottom: none; }

.hw-name { font-weight: 500; font-size: .88rem; margin-bottom: 2px; }
.hw-desc { font-size: .75rem; color: var(--muted); }

.hw-badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  background: rgba(107,122,158,.1);
  color: var(--muted);
}
.hw-badge.ok   { background: rgba(34,211,160,.12); color: var(--green); }
.hw-badge.fail { background: rgba(242,85,85,.1);   color: var(--red);   }
.hw-badge.warn { background: rgba(245,185,66,.1);  color: var(--yellow);}

/* ── ALERTS ─────────────────────────────────────── */

.alert {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: .82rem;
  line-height: 1.5;
}
.alert-green { background: rgba(34,211,160,.08); color: var(--green); border-left: 3px solid var(--green); }
.alert-blue  { background: rgba(56,182,255,.08); color: var(--blue);  border-left: 3px solid var(--blue);  }
.alert-yellow{ background: rgba(245,185,66,.08); color: var(--yellow);border-left: 3px solid var(--yellow);}

.muted-text { color: var(--muted); font-size: .82rem; line-height: 1.5; margin-bottom: 6px; }

/* ── BUTTONS ─────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: none;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover  { opacity: .83; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: 5px 11px; font-size: .75rem; }

.hidden { display: none !important; }

/* ── LOGS ─────────────────────────────────────── */

.log-filter {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .75rem;
  padding: 4px 8px;
  outline: none;
}

.logs-container {
  font-family: 'Courier New', monospace;
  font-size: .76rem;
  max-height: 520px;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px;
}

.log-entry {
  display: grid;
  grid-template-columns: 180px 60px 1fr;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1.4;
  align-items: start;
}
.log-entry:hover { background: var(--surface2); }
.log-ts    { color: var(--muted); white-space: nowrap; }
.log-level { font-weight: 700; text-align: center; padding: 1px 6px; border-radius: 4px; font-size: .7rem; }
.log-level.INFO    { background: rgba(79,110,247,.12); color: var(--accent); }
.log-level.SUCCESS { background: rgba(34,211,160,.12); color: var(--green);  }
.log-level.WARN    { background: rgba(245,185,66,.12); color: var(--yellow); }
.log-level.ERROR   { background: rgba(242,85,85,.12);  color: var(--red);    }
.log-msg   { color: var(--text); word-break: break-word; }

/* ── SETTINGS ─────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.cfg-list { display: flex; flex-direction: column; gap: 0; }
.cfg-row  {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
  gap: 12px;
}
.cfg-row:last-child { border-bottom: none; }
.cfg-key   { color: var(--muted); }
.cfg-val   { font-weight: 600; color: var(--text); text-align: right; }
.cfg-empty { color: var(--red); font-size: .75rem; }

.env-table { display: flex; flex-direction: column; gap: 0; }
.env-row {
  display: grid;
  grid-template-columns: 1.4fr 2fr .7fr;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .79rem;
  align-items: center;
}
.env-row:last-child { border-bottom: none; }
.env-header { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; }
.env-row code { color: var(--accent); background: rgba(79,110,247,.1); padding: 2px 6px; border-radius: 4px; font-size: .76rem; }
.env-row span:nth-child(2) { color: var(--muted); }
.req { font-size: .72rem; font-weight: 600; text-align: center; }
.req.yes { color: var(--yellow); }
.req.no  { color: var(--muted);  }

.about-list { display: flex; flex-direction: column; gap: 0; }
.about-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
}
.about-row:last-child { border-bottom: none; }
.about-row span:first-child { color: var(--muted); }
.about-row span:last-child  { font-weight: 500; }

/* ── AT TERMINAL ─────────────────────────────────────── */

.at-terminal {
  background: #0a0d18;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: .82rem;
  min-height: 220px;
  max-height: 380px;
  overflow-y: auto;
  margin-bottom: 10px;
  color: #c9d1e9;
  line-height: 1.6;
}

.at-line { margin-bottom: 2px; }
.at-line.cmd  { color: var(--accent); }
.at-line.resp { color: #a8e6b0; }
.at-line.err  { color: var(--red); }
.at-line.info { color: var(--muted); font-style: italic; }

.at-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
.at-prompt { color: var(--accent); font-family: monospace; font-weight: 700; flex-shrink: 0; }
.at-input-row input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: .88rem;
  outline: none;
}

.field-label {
  display: block;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ── USSD ─────────────────────────────────────── */

.ussd-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.ussd-input {
  flex: 1;
  min-width: 180px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  font-family: monospace;
  outline: none;
  transition: border-color .2s;
}
.ussd-input:focus { border-color: var(--accent); }

.ussd-result {
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: monospace;
  font-size: .85rem;
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}
.ussd-result.error { color: var(--red); }

.ussd-quick {
  cursor: pointer;
  transition: border-color .15s;
}
.ussd-quick:hover { border-color: var(--accent); }

/* ── RESPONSIVE ─────────────────────────────────────── */

@media (max-width: 900px) {
  .tg-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .env-row { grid-template-columns: 1.2fr 1.5fr .5fr; }
}

@media (max-width: 680px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .content { margin-left: 0; }
  .menu-toggle { display: block; }
  .section { padding: 16px; }
}

@media (max-width: 480px) {
  .kpi-value { font-size: 1.7rem; }
  .pairing-code { font-size: 2rem; letter-spacing: 6px; }
  .qr-frame img { width: 200px; height: 200px; }
}
