:root {
  --blue-dark: #1e3a5f;
  --blue-mid: #2563eb;
  --blue-light: #dbeafe;
  --accent: #0ea5e9;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --white: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.5;
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed; top: 0; left: 0;
  width: 240px; height: 100vh;
  background: var(--blue-dark);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .3s;
}

#sidebar .logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
#sidebar .logo h1 {
  color: #fff; font-size: 15px; font-weight: 700;
  line-height: 1.3;
}
#sidebar .logo small { color: var(--accent); font-size: 11px; }

#sidebar nav { flex: 1; overflow-y: auto; padding: 8px 0; }
#sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; color: rgba(255,255,255,.75);
  text-decoration: none; font-size: 13px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
#sidebar nav a:hover, #sidebar nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff; border-left-color: var(--accent);
}
#sidebar nav a .icon { width: 18px; text-align: center; font-size: 16px; }

#sidebar .sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px; color: rgba(255,255,255,.5);
}
#sidebar .sidebar-footer a { color: rgba(255,255,255,.6); text-decoration: none; }

/* ── TOPBAR ── */
#topbar {
  position: fixed; top: 0; left: 240px; right: 0;
  height: 56px; background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
  padding: 0 24px; gap: 12px; z-index: 90;
  box-shadow: var(--shadow);
}
#topbar .page-title { font-weight: 600; font-size: 15px; flex: 1; }
#topbar .user-info { font-size: 12px; color: var(--gray-600); }

#hamburger {
  display: none; background: none; border: none;
  font-size: 22px; cursor: pointer; color: var(--gray-800);
}

/* ── MAIN ── */
#main {
  margin-left: 240px;
  padding: 72px 24px 32px;
  min-height: 100vh;
}

/* ── CARDS ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 14px; font-weight: 600;
  color: var(--blue-dark); margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

/* ── DASHBOARD STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--blue-mid);
}
.stat-card.green { border-left-color: var(--green); }
.stat-card.orange { border-left-color: var(--orange); }
.stat-card.red { border-left-color: var(--red); }
.stat-card.cyan { border-left-color: var(--accent); }
.stat-card .num { font-size: 28px; font-weight: 700; color: var(--blue-dark); }
.stat-card .label { font-size: 12px; color: var(--gray-600); margin-top: 2px; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--gray-50); text-align: left;
  padding: 10px 12px; font-size: 12px; font-weight: 600;
  color: var(--gray-600); border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}
tbody tr:hover { background: var(--gray-50); }

/* ── BADGE ── */
.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 500;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: var(--gray-200); color: var(--gray-600); }

/* ── FORMS ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: var(--gray-600); }
input, select, textarea {
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 8px 10px; font-size: 13px; font-family: inherit;
  color: var(--gray-800); background: var(--white);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 80px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--blue-mid); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── ALERTS ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 16px; font-size: 13px;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ── SEARCH BAR ── */
.search-bar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px;
}
.search-bar input, .search-bar select {
  flex: 1; min-width: 140px; max-width: 260px;
}

/* ── MAP ── */
#map, .map-container { height: 300px; border-radius: var(--radius); overflow: hidden; }

/* ── SECTION HEADER ── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.section-header h2 { font-size: 16px; font-weight: 700; color: var(--blue-dark); }

/* ── PORTA GRID ── */
.porta-row {
  display: grid; grid-template-columns: 50px 1fr 1fr 1fr;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.porta-row .porta-num {
  background: var(--blue-dark); color: #fff;
  border-radius: var(--radius); text-align: center;
  padding: 8px 4px; font-size: 12px; font-weight: 700;
}

/* ── MODAL ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius);
  width: min(600px, 95vw); max-height: 90vh;
  overflow-y: auto; padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--blue-dark); }

/* ── HISTORICO ── */
.historico-item {
  padding: 10px 0; border-bottom: 1px solid var(--gray-100);
  font-size: 12px;
}
.historico-item:last-child { border-bottom: none; }
.historico-item .hi-meta { color: var(--gray-400); margin-top: 2px; }

/* ── LOGIN PAGE ── */
.login-page {
  min-height: 100vh; background: var(--blue-dark);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  background: var(--white); border-radius: 12px;
  padding: 40px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-box .brand { text-align: center; margin-bottom: 28px; }
.login-box .brand h2 { font-size: 18px; color: var(--blue-dark); font-weight: 700; }
.login-box .brand p { font-size: 12px; color: var(--gray-600); margin-top: 4px; }
.login-box .brasao { font-size: 48px; margin-bottom: 8px; }

/* ── IP GRID ── */
.ip-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.ip-cell {
  padding: 8px 10px; border-radius: var(--radius);
  font-size: 12px; text-align: center; font-family: monospace;
  border: 1px solid transparent;
}
.ip-used { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.ip-free { background: #dcfce7; color: #15803d; border-color: #bbf7d0; cursor: pointer; }
.ip-free:hover { background: #bbf7d0; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; padding: 68px 16px 24px; }
  #topbar { left: 0; }
  #hamburger { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .porta-row { grid-template-columns: 40px 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
