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

:root {
  --bg-app: #1a1a2e;
  --bg-card: #16213e;
  --bg-display: #000000;
  --bg-panel: #0f3460;
  --bg-footer: #0f3460;
  --value-green: #00cc00;
  --brand: #e94560;
  --brand-dark: #c0394b;
  --brand-light: #f0627d;
  --amber: #f5a623;
  --teal: #00d4aa;
  --blue-data: #378add;
  --text-primary: #ffffff;
  --text-secondary: #b0b8d1;
  --text-muted: #6b7a99;
  --text-header: #ffffff;
  --border: #0f3460;
  --border-active: #e94560;
  --success: #00d4aa;
  --danger: #e94560;
  --warning: #f5a623;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 24px rgba(233,69,96,0.2);
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 { font-family: 'Nunito', sans-serif; }
.value-display, .instrument-value { font-family: 'Share Tech Mono', monospace; }

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, var(--bg-app), var(--bg-panel));
  color: var(--text-header);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  border-bottom: 2px solid var(--brand);
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-logo svg, .header-logo img {
  width: 40px;
  height: 40px;
}

.header-center {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.hdr-select {
  background: rgba(255,255,255,0.12);
  color: var(--text-header);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  min-width: 160px;
}

.hdr-select option { background: var(--bg-panel); color: white; }
.hdr-select:focus { outline: none; border-color: rgba(255,255,255,0.6); }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

#comm_status {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
}

#hdr_usuario {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.9;
}

/* ── Main content ───────────────────────────────────────── */
.app-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

#grupo_titulo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--brand-light);
  display: none;
}

#no_grupo {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--text-muted);
  font-size: 1.1rem;
}

#instrumentos_grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

/* ── Instrument card ────────────────────────────────────── */
.instrument-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  animation: fadeUp 0.4s ease both;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.instrument-card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--brand-light);
}

.instrument-card.activo {
  border-top: 3px solid var(--brand);
}

.instrument-card.stale {
  opacity: 0.55;
  filter: grayscale(0.5);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.instrument-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.value-display, .instrument-value {
  background: var(--bg-display);
  color: var(--value-green);
  font-size: 1.4rem;
  text-align: right;
  padding: 8px 12px;
  border: 1px solid #003300;
  border-radius: 4px;
  letter-spacing: 0.05em;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.value-display.sin-datos {
  color: #335533;
}

.instrument-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
}

.instrument-timestamp {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
}

/* ── LED indicator ──────────────────────────────────────── */
.led-indicator {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  margin: 8px auto;
  transition: all 0.3s;
}

.led-indicator.on {
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal);
  animation: led-pulse 2s infinite;
}

.led-indicator.off {
  background: var(--danger);
  box-shadow: none;
}

@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 8px var(--teal); }
  50% { box-shadow: 0 0 20px var(--teal); }
}

/* ── Command buttons ────────────────────────────────────── */
.comando-btns {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.2s;
  color: #fff;
}

.btn:hover { opacity: 0.85; }
.btn:active { opacity: 0.7; }

.btn-primary { background: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--teal); color: #003d30; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
}

.btn-ghost:hover { background: var(--brand); color: white; }

.app-header .btn-ghost {
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.7);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.app-header .btn-ghost:hover { background: rgba(255,255,255,0.35); border-color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ── Footer ─────────────────────────────────────────────── */
.app-footer {
  background: var(--bg-footer);
  color: var(--text-muted);
  text-align: center;
  padding: 0.75rem;
  font-size: 0.85rem;
}

/* ── Login page ─────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-app);
}

.login-container { width: 100%; max-width: 380px; padding: 2rem; }

.login-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
  text-align: center;
  border: 1px solid var(--border);
}

.login-logo {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 0.25rem;
}

.login-icon {
  margin-bottom: 0.75rem;
}

.login-icon svg, .login-icon img {
  width: 64px;
  height: 64px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
}

.form-input, .form-select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(233,69,96,0.15);
}

.form-input::placeholder { color: var(--text-muted); }
.form-select option { background: var(--bg-card); color: var(--text-primary); }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* ── Admin panel ────────────────────────────────────────── */
.admin-layout { display: flex; flex: 1; min-height: calc(100vh - 60px); }

.admin-nav {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-tab {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
}

.nav-tab:hover { background: rgba(233,69,96,0.12); color: var(--brand); }
.nav-tab.active { background: var(--brand); color: white; }

.admin-main { flex: 1; padding: 1.5rem; overflow-y: auto; }

.admin-section { animation: fadeUp 0.3s ease; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  color: var(--brand);
  font-size: 1.3rem;
  font-weight: 700;
}

.admin-list { display: flex; flex-direction: column; gap: 0.5rem; }

.admin-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}

.admin-list-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  min-width: 120px;
}

.admin-list-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
}

.badge {
  background: var(--brand);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-info { background: var(--blue-data); }
.badge-warning { background: var(--warning); color: #411800; }
.badge-danger { background: var(--danger); }

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 150px;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--bg-app);
  border-radius: 6px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.text-muted { color: var(--text-muted); font-size: 0.85rem; font-style: italic; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 700px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-hover);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { color: var(--brand); font-size: 1.2rem; }

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover { color: var(--brand); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

/* ── Radio group ────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 1rem;
  margin-top: 0.3rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
}

/* ── Comandos section ───────────────────────────────────── */
.comando-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-app);
  border-radius: 6px;
}

.comando-row input {
  padding: 0.4rem 0.6rem;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Nunito', sans-serif;
}

/* ── Toast notifications ────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease both;
  max-width: 360px;
}

.toast-success { background: var(--teal); color: #003d30; }
.toast-error { background: var(--danger); }
.toast-info { background: var(--blue-data); }

.toast-fade {
  animation: toastOut 0.4s ease both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Utility ────────────────────────────────────────────── */
.hidden { display: none !important; }
.placeholder-msg {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem;
  font-size: 1rem;
}

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-app); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand); }

/* ─ Responsive ─────────────────────────────────────────── */
@media (max-width: 1023px) {
  #instrumentos_grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 767px) {
  .app-header { flex-direction: column; align-items: stretch; }
  .header-center { justify-content: stretch; }
  .hdr-select { flex: 1; min-width: 0; }
  #instrumentos_grid { grid-template-columns: repeat(2, 1fr); }
  .admin-nav { width: 100%; flex-direction: row; overflow-x: auto; }
  .admin-layout { flex-direction: column; }
}

@media (max-width: 479px) {
  #instrumentos_grid { grid-template-columns: 1fr; }
}

/* ── Legacy preserved styles ────────────────────────────── */
.input-group { margin-bottom: 10px; }
label[type="stick"] { display: inline-block; width: 60px; }
input[type="display"] {
  width: 100px;
  padding: 5px;
  background: var(--bg-display);
  color: var(--value-green);
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  font-family: 'Share Tech Mono', monospace;
}
.gauge {
  width: 200px;
  height: 100px;
  background: conic-gradient(#4caf50 0% 50%, #bbb 50% 100%);
  border-radius: 100px 100px 0 0;
  position: relative;
  margin: 0 auto;
}
.g_cover {
  width: 180px;
  height: 90px;
  background: var(--bg-card);
  border-radius: 90px 90px 0 0;
  position: absolute;
  top: 10px;
  left: 10px;
}
.g_needle {
  width: 4px;
  height: 90px;
  background: red;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform-origin: bottom;
  transform: rotate(0deg);
  transition: transform 0.5s ease;
}

/* ── Header tabs ───────────────────────────────────────── */
.header-tabs {
  display: flex;
  gap: 0;
  width: 100%;
  margin-top: 0.5rem;
}

.tab {
  flex: 1;
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.08);
  border: none;
  color: rgba(255,255,255,0.65);
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tab:first-child { border-radius: 8px 0 0 8px; }
.tab:last-child { border-radius: 0 8px 8px 0; }
.tab.active { background: rgba(255,255,255,0.2); color: #fff; }
.tab:hover { background: rgba(255,255,255,0.15); }

/* ── Históricos ────────────────────────────────────────── */
.historico-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.historico-filters label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.historico-filters input[type="datetime-local"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  background: var(--bg-app);
  color: var(--text-primary);
}

.historico-filters input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

.historico-table-wrap {
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.historico-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.historico-table-wrap th {
  background: var(--bg-panel);
  color: #fff;
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
}

.historico-table-wrap td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.historico-table-wrap tr:nth-child(even) { background: rgba(15,52,96,0.3); }
.historico-table-wrap tr:hover { background: rgba(233,69,96,0.08); }

#historico_count {
  margin-top: 0.5rem;
  text-align: right;
}
