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

:root {
  --primary: #0b548d;
  --primary-dark: #083e6a;
  --accent: #89bd24;
  --accent-dark: #6d9a1b;
  --green: #27ae60;
  --yellow: #f39c12;
  --red: #e74c3c;
  --bg: #f0f4f8;
  --white: #ffffff;
  --text: #1a2e3d;
  --text-muted: #6b7c93;
  --border: #dde3ea;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: var(--white);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

header .logo img {
  height: 36px;
  width: auto;
  display: block;
  filter: brightness(0) invert(1);
}

header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

header .logo-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(137,189,36,0.15);
  border: 1px solid rgba(137,189,36,0.4);
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

header .user-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}

/* ── Layout ── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #083e6a 0%, #0b548d 60%, #0d6aaf 100%);
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-card .brand img {
  height: 52px;
  width: auto;
  margin: 0 auto;
  display: block;
}

.login-card .brand p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 10px;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); opacity: 1; }
.btn-accent  { background: var(--accent); color: var(--white); }
.btn-accent:hover { background: var(--accent-dark); opacity: 1; }
.btn-danger  { background: var(--red); color: var(--white); }
.btn-ghost   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm      { padding: 6px 12px; font-size: 12px; }
.btn-full    { width: 100%; justify-content: center; }

/* ── Alerts / Messages ── */
.alert {
  padding: 12px 16px;
  border-radius: 7px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}

.alert-danger  { background: #fdf2f2; border: 1px solid #f5c6cb; color: #c62828; }
.alert-success { background: #f0faf4; border: 1px solid #a8d5b5; color: #1e7e34; }
.alert-warning { background: #fff8e1; border: 1px solid #ffe082; color: #7d5c00; }

/* ── Cards ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ── Sensor grid ── */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.sensor-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.sensor-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.sensor-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.sensor-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.sensor-location {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Tank visual ── */
.tank-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0;
}

.tank-outer {
  width: 64px;
  height: 140px;
  background: #e9eef4;
  border-radius: 6px 6px 4px 4px;
  border: 2px solid #c8d3de;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  position: relative;
}

.tank-fill {
  width: 100%;
  border-radius: 0 0 3px 3px;
  transition: height 0.6s ease, background 0.3s ease;
}

.level-green  .tank-fill { background: linear-gradient(to top, #1e8449, var(--green)); }
.level-yellow .tank-fill { background: linear-gradient(to top, #d68910, var(--yellow)); }
.level-red    .tank-fill { background: linear-gradient(to top, #c0392b, var(--red)); }

.tank-pct {
  font-size: 24px;
  font-weight: 700;
  margin-top: 10px;
}

.level-green  .tank-pct { color: var(--green); }
.level-yellow .tank-pct { color: var(--yellow); }
.level-red    .tank-pct { color: var(--red); }

.tank-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

.no-data {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
  font-style: italic;
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-ultrasonico { background: #e8f4fd; color: #1a6fa0; }
.badge-presion     { background: #fef3e2; color: #b07d00; }
.badge-flotador    { background: #eaf7ef; color: #1e7e34; }
.badge-admin       { background: #e8eaf6; color: #3949ab; }
.badge-active      { background: #e8f5e9; color: #2e7d32; }
.badge-inactive    { background: #fce4ec; color: #ad1457; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Tables ── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
}

th {
  background: #f0f4f8;
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f7fafc; }

/* ── Level cell ── */
.level-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-bar-bg {
  flex: 1;
  height: 8px;
  background: #e9eef4;
  border-radius: 4px;
  overflow: hidden;
  max-width: 80px;
}

.level-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.level-green-fill  { background: var(--green); }
.level-yellow-fill { background: var(--yellow); }
.level-red-fill    { background: var(--red); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

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

/* ── Page header ── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Stats bar (admin) ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Toggle switch ── */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .sensor-grid { grid-template-columns: 1fr; }
  .tabs { flex-wrap: wrap; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .login-card { padding: 32px 24px; }
}

/* ── Spinner ── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center { text-align: center; padding: 40px; }
