/* IoT SaaS ??? painel admin (azul, verde, branco) */
:root {
  --blue-900: #0c4a6e;
  --blue-700: #0369a1;
  --blue-600: #0284c7;
  --blue-500: #0ea5e9;
  --blue-100: #e0f2fe;
  --green-600: #16a34a;
  --green-500: #22c55e;
  --green-100: #dcfce7;
  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(12, 74, 110, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-700); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; flex-direction: column; }

.sidebar {
  background: linear-gradient(180deg, var(--blue-900) 0%, var(--blue-700) 100%);
  color: var(--white);
  padding: 1rem;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.sidebar.open { transform: translateX(0); }

.sidebar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--white);
  display: block;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0;
}

.sidebar-brand span { color: var(--green-500); }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: rgba(255,255,255,0.85);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,0.12);
  color: var(--white);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 0.85rem;
  opacity: 0.8;
}

.main-wrap {
  flex: 1;
  margin-left: 0;
  width: 100%;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.menu-btn {
  background: var(--blue-100);
  border: none;
  color: var(--blue-700);
  width: 40px; height: 40px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}

.topbar h1 { font-size: 1.1rem; font-weight: 600; flex: 1; }

.badge-mqtt {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
}

.badge-mqtt.on { background: var(--green-100); color: var(--green-600); }
.badge-mqtt.off { background: #fef3c7; color: var(--orange); }

.content { padding: 1rem; max-width: 1280px; margin: 0 auto; width: 100%; }

/* Cards */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card-title { font-size: 1rem; font-weight: 600; color: var(--blue-900); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--blue-700);
  line-height: 1.2;
}

.stat-card.green .value { color: var(--green-600); }
.stat-card.green { border-left: 4px solid var(--green-500); }
.stat-card.blue { border-left: 4px solid var(--blue-500); }
.stat-card.gray { border-left: 4px solid var(--gray-400); }

.grid-2 {
  display: grid;
  gap: 1rem;
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 0.35rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--white);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--blue-100);
}

.form-row {
  display: grid;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s;
}

.btn:hover { filter: brightness(0.95); }
.btn-primary { background: var(--blue-600); color: var(--white); }
.btn-success { background: var(--green-600); color: var(--white); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-warning { background: var(--orange); color: var(--white); }
.btn-outline {
  background: var(--white);
  color: var(--blue-600);
  border: 1px solid var(--blue-500);
}
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-group { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.btn-group-actions { min-width: 18rem; }
th.col-acoes, td.col-acoes { min-width: 20rem; white-space: normal; }

/* Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--gray-100);
}

th {
  color: var(--gray-600);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tr:hover td { background: var(--gray-50); }

/* Status */
.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pill-online { background: var(--green-100); color: var(--green-600); }
.pill-offline { background: var(--gray-100); color: var(--gray-600); }
.pill-bloqueado { background: #fee2e2; color: var(--red); }
.pill-aguardando { background: var(--blue-100); color: var(--blue-700); }
.pill-usado { background: var(--green-100); color: var(--green-600); }
.pill-expirado { background: #fef3c7; color: #b45309; }
.pill-bomba-on { background: var(--green-100); color: var(--green-600); }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  background: var(--gray-400);
}

.dot.on { background: var(--green-500); }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success { background: var(--green-100); color: #166534; border: 1px solid #86efac; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: var(--blue-100); color: var(--blue-900); }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-600) 50%, var(--green-600) 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

.login-card h1 { color: var(--blue-900); font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-card .sub { color: var(--gray-600); margin-bottom: 1.5rem; font-size: 0.95rem; }

.logo-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--blue-500), var(--green-500));
  border-radius: 12px;
  margin-bottom: 1rem;
}

/* Log list */
.log-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.875rem;
}

.log-item:last-child { border-bottom: none; }
.log-meta { color: var(--gray-600); font-size: 0.8rem; }
.log-payload {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  background: var(--gray-50);
  padding: 0.5rem;
  border-radius: 6px;
  margin-top: 0.35rem;
  word-break: break-all;
}

code {
  background: var(--blue-100);
  color: var(--blue-900);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.muted { color: var(--gray-600); }
.empty { text-align: center; padding: 2rem; color: var(--gray-600); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

.overlay.show { display: block; }

/* Desktop */
.text-green { color: var(--green-600); font-weight: 600; }
.small { font-size: 0.8rem; }

.device-cards { display: grid; gap: 1rem; }
.device-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.5rem; }
.device-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.85rem; color: var(--gray-600); margin-bottom: 0.5rem; }
.device-actions { margin-top: 0.75rem; }
.device-actions form { display: inline; }

.table-desktop { display: none; }

@media (min-width: 768px) {
  .device-cards { display: none; }
  .table-desktop { display: block; }
}

@media (min-width: 992px) {
  .sidebar { transform: translateX(0); }
  .main-wrap { margin-left: 260px; width: calc(100% - 260px); }
  .menu-btn { display: none; }
  .overlay { display: none !important; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: repeat(3, 1fr); }
  .content { padding: 1.5rem 2rem; }
}

@media (min-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
}
