:root {
  --bg: #0b0f14;
  --panel: rgba(255, 255, 255, .06);
  --panel2: rgba(255, 255, 255, .09);
  --border: rgba(255, 255, 255, .12);
  --text: rgba(255, 255, 255, .92);
  --muted: rgba(255, 255, 255, .70);
  --accent: #6ee7ff;
  --accent2: #a78bfa;
  --danger: #ff5c7a;
  --shadow: 0 20px 70px rgba(0, 0, 0, .55);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(110, 231, 255, .14), transparent 60%),
    radial-gradient(800px 500px at 80% 20%, rgba(167, 139, 250, .14), transparent 60%),
    radial-gradient(900px 700px at 50% 100%, rgba(255, 92, 122, .08), transparent 65%),
    var(--bg);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .04));
  border-radius: 18px;
  box-shadow: var(--shadow);
}

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

.logo {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 30px rgba(110, 231, 255, .12);
}

.brand h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: .2px;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.card {
  grid-column: span 12;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .035));
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

@media (min-width: 860px) {
  .card.half {
    grid-column: span 6;
  }

  .card.third {
    grid-column: span 4;
  }
}

h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

p {
  margin: 8px 0;
  color: var(--muted);
  line-height: 1.5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background-color: rgba(255, 255, 255, .06);
  color: var(--text);
  cursor: pointer;
  transition: transform .08s ease, background-color .2s ease, border-color .2s ease;
  user-select: none;
}

.btn:hover {
  background-color: rgba(255, 255, 255, .10);
  border-color: rgba(255, 255, 255, .18);
  transform: translateY(-1px);
}

/* --- OTA devices: bordes según selección --- */
.btn.device-normal {
  border-color: rgba(255, 255, 255, .10);
}

.btn.device-selected {
  border-color: rgba(255, 255, 255, .25);
}

.btn.primary {
  border-color: rgba(110, 231, 255, .35);
  background: linear-gradient(135deg, rgba(110, 231, 255, .18), rgba(167, 139, 250, .14));
}

.btn.danger {
  border-color: rgba(255, 92, 122, .35);
}

.btnrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.form {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.input {
  width: 100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  outline: none;
}

.input:focus {
  border-color: rgba(110, 231, 255, .45);
  box-shadow: 0 0 0 4px rgba(110, 231, 255, .08);
}

.badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  font-size: 12px;
}

.badge-online {
  border-color: rgba(60, 220, 140, .35);
  background: rgba(60, 220, 140, .12);
  color: rgba(200, 255, 225, .95);
}

.badge-offline {
  border-color: rgba(255, 92, 122, .35);
  background: rgba(255, 92, 122, .12);
  color: rgba(255, 225, 232, .95);
}

.alert {
  border: 1px solid rgba(255, 92, 122, .35);
  background: rgba(255, 92, 122, .10);
  padding: 10px 12px;
  border-radius: 14px;
  color: rgba(255, 255, 255, .90);
}

.small {
  font-size: 12px;
  color: var(--muted);
}

.hr {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
  border: 0;
}

/* --- Layout con sidebar --- */
.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 14px;
  margin-top: 14px;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
}

.sidebar {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .035));
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  position: sticky;
  top: 14px;
  height: fit-content;
}

.navtitle {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 8px 10px;
  letter-spacing: .25px;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
}

.nav a:hover {
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .10);
}

.nav a.active {
  background: linear-gradient(135deg, rgba(110, 231, 255, .18), rgba(167, 139, 250, .14));
  border-color: rgba(110, 231, 255, .30);
}

.main {
  min-height: 200px;
}

@media (max-width: 520px) {
  .container {
    padding: 18px 12px 46px;
  }

  .topbar {
    padding: 14px;
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
  }

  .btnrow {
    width: 100%;
  }

  .btn {
    width: 100%;
  }

  .brand {
    justify-content: center;
  }

  .sidebar {
    position: static;
  }

  .card {
    padding: 14px;
    border-radius: 16px;
  }

  .input {
    padding: 14px;
    font-size: 16px;
  }

  /* 16 evita zoom automático en iPhone */
}

/* --- Fix selects en tema oscuro --- */
select.input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: rgba(0, 0, 0, .25);
  color: var(--text);
  padding-right: 40px;
  /* espacio para la flecha */
}

/* Flecha custom */
select.input {
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(255, 255, 255, .75) 50%),
    linear-gradient(135deg, rgba(255, 255, 255, .75) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

/* En muchos navegadores desktop sí aplica a las opciones */
select.input option {
  background: #0b0f14;
  color: rgba(255, 255, 255, .92);
}

/* Por si el browser usa 'color-scheme' para controles nativos */
:root {
  color-scheme: dark;
}

/* --- Custom select --- */
.cselect {
  position: relative;
}

.cselect button {
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  cursor: pointer;
}

.cselect button:after {
  content: "▾";
  float: right;
  opacity: .8;
}

.cselect .menu {
  position: absolute;
  left: 0;
  right: 0;
  margin-top: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: #0b0f14;
  box-shadow: var(--shadow);
  max-height: 50vh;
  overflow: auto;
  display: none;
  z-index: 50;
}

.cselect.open .menu {
  display: block;
}

.cselect .item {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  cursor: pointer;
}

.cselect .item:hover {
  background: rgba(255, 255, 255, .06);
}

.cselect .item:last-child {
  border-bottom: none;
}

.cselect .hint {
  color: var(--muted);
}

/* --- Tablas (para nutrientes, historiales, etc.) --- */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.table th {
  text-align: left;
  font-size: 12px;
  letter-spacing: .25px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, .06);
}

.table tr:hover td {
  background: rgba(255, 255, 255, .04);
}

/* --- Tablas (nutrientes, historiales, etc.) --- */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .03);
}

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.table th {
  text-align: left;
  font-size: 12px;
  letter-spacing: .25px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, .06);
}

.table tr:hover td {
  background: rgba(255, 255, 255, .04);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Tablas: permitir scroll horizontal en móvil --- */
.tablewrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  min-width: 620px;
  /* evita que se aplaste */
}

.table td {
  word-break: break-word;
}