﻿
/* Reset e tema */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: "Inter", Arial, sans-serif; }
:root {
  --primary: #0a8d3a;
  --primary-dark: #066829;
  --background: #f5f7fa;
  --gray: #e1e5eb;
  --text-title: #273238;
  --text-body: #4e5b63;
  --track-color: #1e90ff;
  --dose-color: #f01818;
  --track-dash: 6 6;
}

/* Página de login */
.login-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--background); }
.login-container { width: 350px; padding: 40px 30px; background: #fff; border-radius: 14px; text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.logo { max-width: 130px; margin-bottom: 16px; }
.login-container h2 { color: var(--text-title); margin-bottom: 20px; font-weight: 600; }
.login-container input { width: 100%; padding: 12px; margin: 8px 0; border: 1px solid var(--gray); border-radius: 8px; font-size: 15px; }
.login-container button { width: 100%; padding: 14px; margin-top: 10px; background: var(--primary); color: #fff; border-radius: 8px; cursor: pointer; border: none; font-size: 16px; font-weight: 600; transition: 0.2s; }
.login-container button:hover { background: var(--primary-dark); transform: translateY(-2px); }
.login-msg { min-height: 20px; color: #c0392b; font-size: 14px; }
.auth-panel[hidden] { display: none; }
.auth-help { margin: -8px 0 10px; color: var(--text-body); font-size: 14px; line-height: 1.45; }
.login-container .auth-link-btn {
  width: auto;
  padding: 4px;
  margin-top: 14px;
  background: transparent;
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 600;
}
.login-container .auth-link-btn:hover {
  background: transparent;
  color: var(--primary);
  text-decoration: underline;
  transform: none;
}
.login-msg.is-success { color: var(--primary-dark); }
.login-msg.is-error { color: #c0392b; }
.login-container button:disabled { opacity: .65; cursor: wait; transform: none; }

/* Header */

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* garante que fique à esquerda */
}
.app-header {
  background: var(--primary);
  padding: 10px 16px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.logo-header {
  height: 42px;
  width: auto;
  object-fit: contain;
  display: block;
  filter: brightness(0) invert(1);
}
.header-right { display: flex; align-items: center; gap: 8px; }
.btn-header {
  background: rgba(255,255,255,0.15);
  color: #fff; border: none; border-radius: 8px;
  padding: 8px 12px; cursor: pointer;
}
.btn-header:hover { background: rgba(255,255,255,0.25); }

.upload-dropdown { position: relative; }
.upload-menu {
  position: absolute; right: 0; top: (100%+ 8px);
  background: #fff; border: 1px solid var(--gray);
  border-radius: 10px; min-width: 220px;
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
  display: none; overflow: visible; z-index: 100;
}
.upload-dropdown.open .upload-menu { display: block; }

.menu-item {
  width: 100%; text-align: left; padding: 10px 12px;
  background: #fff; border: none; color: var(--text-title);
  cursor: pointer;
}
.menu-item:hover { background: #f2f4f8; }


/* Grid principal: 2 colunas e altura de viewport (evitar scroll geral) */
.grid-container { display: grid; grid-template-columns: 320px 1fr; gap: 12px; padding: 12px; background: var(--background); height: calc(100vh - 60px); }

/* Filtros (coluna 1) */
.filters { background: #fff; padding: 16px; border: 1px solid var(--gray); border-radius: 12px; overflow-y: auto; }
.filters h2 { margin-bottom: 10px; color: var(--text-title); font-size: 20px; }
.filters label { font-weight: 600; color: var(--text-body); display: block; margin-top: 8px; }
.filters select, .filters input { width: 100%; border: 1px solid var(--gray); border-radius: 8px; padding: 8px; margin-top: 4px; background: #fff; }
.clear-filters-btn { width: 100%; margin-top: 8px; }
.multi-select { position: relative; margin-top: 4px; }
.multi-select-toggle { width: 100%; min-height: 38px; padding: 8px; text-align: left; border: 1px solid var(--gray); border-radius: 8px; background: #fff; }
.multi-select-menu { position: absolute; z-index: 1001; width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--gray); border-radius: 8px; background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.16); }
.multi-select-menu input[type="search"] { margin: 0 0 6px; }
.multi-select-all, .multi-select-option { display: flex !important; gap: 6px; align-items: center; margin: 0 !important; padding: 6px 4px; font-weight: 500 !important; cursor: pointer; }
.multi-select-all input, .multi-select-option input { width: auto !important; margin: 0 !important; }
.multi-select-options { max-height: 210px; overflow-y: auto; border-top: 1px solid var(--gray); }
.device-color-toggle { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; white-space: nowrap; }
.device-map-legend { padding: 9px 11px; border-radius: 8px; background: rgba(255,255,255,.94); box-shadow: 0 1px 5px rgba(0,0,0,.28); line-height: 1.5; }
.device-map-legend strong { display: block; margin-bottom: 4px; }
.device-map-legend i { display: inline-block; width: 12px; height: 12px; margin-right: 7px; border-radius: 50%; vertical-align: -1px; }
.btn-primary { width: 100%; padding: 10px; margin-top: 10px; background: var(--primary); color: #fff; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--primary-dark); }

/* Coluna 2: Resultados (compacto) + Mapa que ocupa o restante */
.right-col { display: grid; grid-template-rows: auto 1fr; gap: 12px; overflow: hidden; }

/* Resultados */
.results { background: #fff; border: 1px solid var(--gray); border-radius: 12px; padding: 8px 12px; }
.results-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.results-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.results h2 { color: var(--text-title); font-size: 20px; }
.btn-secondary { padding: 6px 10px; border: 1px solid var(--gray); border-radius: 8px; background: #fff; color: var(--text-title); cursor: pointer; }
.btn-secondary:hover { background: #f2f4f8; }

/* Administração de usuários */
.admin-search { width: min(340px,100%); margin-left: auto; padding: 8px 10px; border: 1px solid var(--gray); border-radius: 8px; }
.admin-screen {
  min-height: calc(100vh - 62px);
  padding: 18px;
  background: var(--background);
}
.admin-screen[hidden], .admin-editor[hidden] { display: none; }
.admin-card {
  width: min(100%, 1480px);
  max-width: 1480px;
  box-sizing: border-box;
  margin: 0 auto 14px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--gray);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
.admin-toolbar, .admin-company-row, .admin-editor-heading, .admin-list-heading, .admin-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.admin-eyebrow { color: var(--primary); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.admin-toolbar h1 {
  margin: 0;
  color: var(--text-title);
  font-size: 28px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.admin-tabs { display: flex; gap: 8px; padding-top: 10px; padding-bottom: 10px; }
.admin-tab { border: 1px solid var(--gray); border-radius: 8px; background: #fff; color: var(--text-body); padding: 9px 16px; cursor: pointer; font-weight: 700; }
.admin-tab.is-active { border-color: var(--primary); background: var(--primary); color: #fff; }
.admin-devices-section[hidden], #admin-users-section[hidden], #admin-devices-section[hidden], #admin-companies-section[hidden] { display: none; }
#admin-devices-section:not([hidden]) { display: flex; flex-direction: column; }
#device-activation-card { order: 1; }
#admin-devices-section > .admin-company-row { order: 2; }
#device-create-editor { order: 3; }
#device-metadata-editor { order: 4; }
#device-credentials-panel { order: 5; }
#admin-devices-section > .admin-card:last-child { order: 6; }
.admin-company-row { justify-content: flex-start; }
.admin-company-row label { color: var(--text-body); font-weight: 700; }
.admin-company-row select { min-width: 280px; padding: 10px; border: 1px solid var(--gray); border-radius: 8px; background: #fff; }
.admin-quota-panel { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-left: auto; }
.admin-quota-panel[hidden] { display: none; }
.admin-quota-panel strong { color: var(--text-title); font-size: 14px; }
.admin-inline-btn { width: auto; margin: 0; padding: 10px 16px; }
.admin-editor h2, .admin-list-heading h2 { color: var(--text-title); }
#device-activation-card h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.admin-close-btn { border: 0; background: transparent; color: var(--text-body); font-size: 28px; cursor: pointer; }
.admin-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 14px; }
.admin-form-grid label { color: var(--text-body); font-weight: 700; font-size: 14px; }
.admin-form-grid input[type="text"], .admin-form-grid input[type="email"], .admin-form-grid select {
  width: 100%; margin-top: 5px; padding: 10px; border: 1px solid var(--gray); border-radius: 8px; background: #fff;
}
.admin-form-grid input:disabled { background: #f2f4f8; color: var(--text-body); }
.admin-active-field span { display: flex; align-items: center; gap: 8px; min-height: 40px; margin-top: 5px; font-weight: 500; }
.admin-permissions { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 16px 0; padding: 14px; border: 1px solid var(--gray); border-radius: 10px; }
.admin-permissions legend { padding: 0 6px; color: var(--text-title); font-weight: 700; }
.admin-permissions label { display: flex; align-items: center; gap: 6px; color: var(--text-body); }
.admin-form-actions { justify-content: flex-end; }
.admin-muted { color: var(--text-body); font-size: 14px; }
.admin-table-wrap { overflow-x: auto; margin-top: 12px; }
.admin-table { width: 100%; min-width: 880px; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 11px 10px; border-bottom: 1px solid var(--gray); text-align: left; vertical-align: top; }
.admin-table th { color: var(--text-title); font-size: 13px; }
.admin-table td { color: var(--text-body); font-size: 14px; }
.admin-status { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.admin-status.is-active { background: #e8f5ea; color: var(--primary-dark); }
.admin-status.is-inactive { background: #fbe9e7; color: #a93226; }
.admin-permission-summary { max-width: 300px; line-height: 1.4; }
.admin-edit-btn { padding: 6px 10px; border: 1px solid var(--gray); border-radius: 7px; background: #fff; cursor: pointer; }
.admin-edit-btn:hover { background: #f2f4f8; }
.admin-edit-btn:disabled { opacity: .6; cursor: wait; }
.device-action-low { border-color: #8fc89a; color: #246b32; background: #f3fbf5; }
.device-action-low:hover { background: #e4f5e8; }
.device-action-warning { border-color: #d9a441; color: #765200; background: #fffaf0; }
.device-action-warning:hover { background: #fff1cf; }
.device-action-danger { border-color: #d9a7a2; color: #9f2d24; background: #fff8f7; }
.device-action-danger:hover { background: #ffe9e6; }
.admin-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.device-table { min-width: 1360px; }
.device-table th { white-space: nowrap; }
.device-table th:last-child,
.device-table td:last-child { min-width: 430px; }
.device-table .admin-row-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}
.device-credentials { border: 2px solid #d9a441; }
.device-warning { margin: 12px 0; padding: 10px 12px; border-radius: 8px; background: #fff6df; color: #684b08; }
.device-credential-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.device-credential-grid > div { min-width: 0; padding: 10px; border: 1px solid var(--gray); border-radius: 8px; background: #f8fafb; }
.device-credential-grid dt { color: var(--text-body); font-size: 12px; font-weight: 700; }
.device-credential-grid dd { margin: 5px 0 0; color: var(--text-title); font-family: monospace; overflow-wrap: anywhere; }
#device-activation-serial, #device-activation-code { text-transform: uppercase; font-family: monospace; }
.company-table { min-width: 1180px; }
.company-table th:last-child, .company-table td:last-child { width: 90px; }
#company-editor .admin-form-grid input:not([type="checkbox"]) { width: 100%; box-sizing: border-box; margin-top: 5px; padding: 10px; border: 1px solid var(--gray); border-radius: 8px; background: #fff; }
#company-editor .admin-active-field span { justify-content: flex-start; }
#company-editor .admin-active-field input[type="checkbox"] { width: auto; margin: 0; }
.company-observations-label { display: block; margin: 16px 0; color: var(--text-body); font-size: 14px; font-weight: 700; }
.company-observations-label textarea { width: 100%; box-sizing: border-box; margin-top: 5px; padding: 10px; border: 1px solid var(--gray); border-radius: 8px; resize: vertical; font: inherit; }

.results-line { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; }
.results-line span small { color: var(--text-body); }
.results-line span strong { color: var(--text-title); }
.results-line .sep { width: 1px; background: var(--gray); margin: 0 2px; }

/* Mapa ocupa o restante da coluna 2 */
.map { background: #fff; border: 1px solid var(--gray); border-radius: 12px; display: flex; flex-direction: column; }
.map-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; }
.map-buttons .btn-secondary { margin-left: 8px; }
#map { margin: 8px 12px 12px 12px; width: calc(100% - 24px); height: 100%; border-radius: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.12); background: #e9eef3; }

#text_mapa {
  font-size: 20px;
}

/* --- =====Resultados: tabela com cabe�alhos agrupados====== --- */
.results-table-wrap { overflow-x: auto; }
.results-table { width: 100%; min-width: 980px; border-collapse: collapse; }

/* Cabe�alho de grupos: usa o verde j� definido no tema */
.results-table thead .group th {
  background: var(--primary);
  color: #fff;
  text-align: center;
  padding: 8px;
  border-right: 1px solid #ffffff33; /* separa��o sutil */
  font-size: 16px;
}

/* Subcabe�alhos (linha 2 do <thead>) com tom suave */
:root { --header-green-soft: #e8f5ea; } /* ajuste se quiser outro tom */
.results-table thead .sub th {
  background: var(--header-green-soft);
  color: var(--text-title);
  text-align: center;
  padding: 6px;
  border-bottom: 1px solid var(--gray);
  font-size: 14px;
}

/* C�lulas */
.results-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--gray);
}
.results-table td span {
  font-weight: 600;
  color: var(--text-title);
}

/* ################# Upload ##########################
/* Dropdown */
.upload-dropdown { position: relative; }

.upload-menu {
  position: absolute; right: 0; top: 110%;
  background: #fff; border: 1px solid var(--gray);
  border-radius: 10px; min-width: 220px;
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
  display: none; overflow: visible; z-index: 100;
}
.upload-dropdown.open .upload-menu { display: block; }

/* Hint à esquerda */

.menu-item-with-hint { position: relative; }

.hint {
  position: absolute; top: 0; transform: none;
  right: calc(100% + 12px);
  width: 420px; height: 250px;
  max-width: calc(100vw - 280px); max-height: 250px;
  background: #fff; color: var(--text-title);
  border: 1px solid var(--gray); border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
  padding: 10px 12px; font-size: 13px; line-height: 1.35; opacity: 0;
  pointer-events: none; transition: .18s ease; z-index: 200;
}

.menu-item-with-hint:hover .hint,
.menu-item-with-hint .menu-item:focus + .hint { opacity: 1;}
.menu-item:hover { background: #f2f4f8; }

.menu-item {
  width: 100%; text-align: left; padding: 10px 12px;
  background: #fff; border: none; color: var(--text-title); cursor: pointer;
}

.hint.left::after {
  content: "";
  position: absolute;
  top: 4%; 
  left: 100%;
  border: 8px solid transparent;
  border-left-color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.08));
}

/* Logo do header */
.logo-header { height: 42px; width: auto; object-fit: contain; }


/* Área de preview do dry-run/commit (se quiser destacar) */
.import-preview {
  display: none;
  position: fixed;
  right: 18px;
  bottom: 78px;
  z-index: 1900;
  width: min(560px, calc(100vw - 36px));
  max-height: min(420px, calc(100vh - 140px));
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--gray);
  border-radius: 8px;
  background: #fff;
  color: var(--text-body);
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
}

.import-preview.is-visible {
  display: block;
}

.import-preview-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-body);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.import-preview-close:hover {
  background: rgba(0,0,0,.08);
}

.import-preview pre {
  margin: 0;
  padding-right: 28px;
  white-space: pre-wrap;
  font: inherit;
}

/* Desabilitar botoes de upload para usuario nao autoriado */
.btn-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-disabled:hover {
  background: rgba(255,255,255,0.15); /* evita hover diferente */
}
.menu-item[disabled] {
  pointer-events: none; /* não recebe clique */
}

/* --- Responsivo: colapsa em cards abaixo de 800px --- */
@media (max-width: 800px) {
  .app-header { padding: 8px 10px; }
  .logo-header { height: 40px; }
  .grid-container {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100dvh - 56px);
    padding: 8px;
    gap: 8px;
  }
  .filters { overflow: visible; }
  .admin-screen { padding: 8px; }
  .admin-toolbar, .admin-company-row { align-items: stretch; flex-direction: column; }
  .admin-company-row select { width: 100%; min-width: 0; }
  .admin-quota-panel { width: 100%; margin-left: 0; align-items: flex-start; flex-direction: column; }
  .admin-form-grid { grid-template-columns: 1fr; }
  .device-credential-grid { grid-template-columns: 1fr; }
  .right-col {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  .results { padding: 8px; }
  .results-header,
  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .results-actions,
  .map-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    margin-left: 0;
    gap: 6px;
  }
  .results-actions .btn-secondary,
  .map-buttons .btn-secondary {
    min-height: 42px;
    margin-left: 0;
    white-space: normal;
  }
  .map { min-height: 68dvh; }
  #map {
    min-height: 55dvh;
    height: 55dvh;
    margin: 4px 8px 8px;
    width: calc(100% - 16px);
  }
  .results-table { min-width: 0; }
  .results-table thead { display: none; }
  .results-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr; /* duas colunas de cards */
    gap: 8px;
  }
  .results-table td {
    text-align: left;
    border: 1px solid var(--gray);
    border-radius: 10px;
    padding: 10px;
    background: #fff;
  }
  .results-table td::before {
    content: attr(data-label); /* rótulo do card */
    display: block;
    font-size: 12px;
    color: var(--text-body);
    margin-bottom: 4px;
  }

/* (Opcional) Ajuste para telas muito estreitas */
@media (max-width: 480px) {
  .header-right { gap: 4px; }
  .btn-header {
    min-height: 40px;
    padding: 8px 10px;
  }
  .upload-menu {
    position: fixed;
    top: 60px;
    right: 8px;
    left: 8px;
    min-width: 0;
  }
  .hint { display: none; }
  .results-actions,
  .map-buttons { grid-template-columns: 1fr; }
  .results-table tbody tr {
    grid-template-columns: 1fr; /* uma coluna */
  }
}




