:root {
  color-scheme: light;
  --ink: #10202b;
  --muted: #667781;
  --line: #dbe7ed;
  --panel: #ffffff;
  --page: #eef7f8;
  --blue: #1787c7;
  --blue-dark: #0d557b;
  --cyan: #41d4f1;
  --green: #27b56b;
  --yellow: #f2b84b;
  --red: #e45f56;
  --shadow: 0 18px 45px rgba(28, 72, 88, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(23, 135, 199, 0.16), rgba(65, 212, 241, 0.06) 36%, rgba(39, 181, 107, 0.1)),
    var(--page);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 8px;
  background: linear-gradient(160deg, var(--blue), var(--green));
}

.brand-mark span {
  width: 26px;
  height: 34px;
  border-radius: 18px 18px 22px 22px;
  background: linear-gradient(#dffaff 46%, var(--cyan) 47%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.75);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 44px;
  line-height: 1;
}

.login-copy {
  color: var(--muted);
  line-height: 1.55;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.login-form label,
.search-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form input,
.search-box input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.login-form input:focus,
.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 135, 199, 0.14);
}

.primary-button,
.demo-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  color: white;
  background: var(--blue-dark);
}

.demo-button {
  width: 100%;
  margin-top: 12px;
  color: var(--blue-dark);
  background: #dff5fb;
}

.login-message {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.dashboard {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 32px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search-box {
  min-width: min(340px, 46vw);
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue-dark);
  background: rgba(255, 255, 255, 0.86);
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.status-strip,
.cards-grid,
.mode-banner {
  max-width: 1440px;
  margin-left: auto;
  margin-right: auto;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.status-strip article {
  min-height: 88px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.status-strip span {
  display: block;
  color: var(--blue-dark);
  font-size: 28px;
  font-weight: 900;
}

.status-strip p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mode-banner {
  min-height: 38px;
  margin-bottom: 14px;
  padding: 9px 12px;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  color: var(--blue-dark);
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 800;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
}

.site-card {
  position: relative;
  overflow: hidden;
  min-height: 380px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(18, 67, 82, 0.12);
}

.site-card.alert {
  border-color: rgba(228, 95, 86, 0.42);
}

.site-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.site-card h3 {
  margin-bottom: 5px;
  font-size: 21px;
}

.site-card .cnpj {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.logs-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue-dark);
  background: #f5fbfd;
  cursor: pointer;
}

.logs-button:hover {
  border-color: rgba(23, 135, 199, 0.42);
  background: #e8f7fb;
}

.logs-button.danger {
  color: #8b1d16;
  background: #fff8f7;
}

.logs-button.danger:hover {
  border-color: rgba(228, 95, 86, 0.42);
  background: #ffe1de;
}

.logs-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.state-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  color: white;
  background: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.site-card.alert .state-pill {
  background: var(--red);
}

.reservoir-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.reservoir {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: 0;
}

.tank {
  position: relative;
  width: min(138px, 100%);
  aspect-ratio: 0.75;
  overflow: hidden;
  border: 5px solid var(--blue-dark);
  border-radius: 8px 8px 18px 18px;
  background: #f6fbfd;
}

.reservoir.is-filling .tank {
  box-shadow: 0 0 0 0 rgba(65, 212, 241, 0.4), 0 12px 28px rgba(23, 135, 199, 0.18);
  animation: fillRing 1.8s ease-out infinite;
}

.water {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 5%;
  background: linear-gradient(180deg, var(--cyan), #1989d2);
  transition: height 420ms ease;
}

.water::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -8%;
  width: 116%;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  animation: wave 2.4s linear infinite;
}

.reservoir.is-filling .water {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 22%, rgba(255, 255, 255, 0.24) 48%, transparent 72%),
    linear-gradient(180deg, var(--cyan), #1989d2);
  background-size: 62px 100%, 100% 100%;
  animation: waterCurrent 1.6s linear infinite;
}

.reservoir.is-filling .water::before {
  height: 24px;
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.78) 0 38%, transparent 40%),
    rgba(255, 255, 255, 0.42);
  animation: wave 1.1s linear infinite, bob 1.8s ease-in-out infinite;
}

.reservoir.is-filling .water::after {
  content: "";
  position: absolute;
  top: -18px;
  left: 22%;
  width: 56%;
  height: 34px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 22% 55%, rgba(255, 255, 255, 0.82) 0 7%, transparent 8%),
    radial-gradient(circle at 48% 42%, rgba(255, 255, 255, 0.68) 0 6%, transparent 7%),
    radial-gradient(circle at 72% 58%, rgba(255, 255, 255, 0.72) 0 5%, transparent 6%);
  opacity: 0.9;
  animation: surfaceBubbles 1.4s ease-in-out infinite;
}

.level-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--blue-dark);
  font-size: 28px;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.reservoir h4 {
  margin: 0;
  font-size: 15px;
}

.device-icons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
}

.device-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 999px;
  color: var(--blue-dark);
  background: #e8f7fb;
  font-size: 11px;
  font-weight: 900;
}

.reservoir.is-filling .device-icon:first-child {
  color: #07506f;
  background: #c9f5ff;
  box-shadow: 0 0 0 0 rgba(65, 212, 241, 0.32);
  animation: badgePulse 1.45s ease-in-out infinite;
}

.reservoir.is-filling .device-icon:first-child svg {
  animation: dropBounce 1.15s ease-in-out infinite;
}

.device-icon.warn {
  color: #7b4c00;
  background: #fff0ce;
}

.device-icon svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.timeline {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.event-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.event-line strong {
  color: var(--ink);
}

.modal-open {
  overflow: hidden;
}

.logs-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 32, 43, 0.48);
}

.logs-panel {
  width: min(1180px, 100%);
  max-height: min(860px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(7, 35, 49, 0.35);
}

.logs-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.logs-header h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.logs-header p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.logs-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.summary-chip,
.log-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.summary-chip.error,
.log-type.error {
  color: #8b1d16;
  background: #ffe1de;
}

.summary-chip.info,
.log-type.info {
  color: #07506f;
  background: #d9f4ff;
}

.summary-chip.heartbeat,
.log-type.heartbeat {
  color: #2f5b12;
  background: #e5f8d6;
}

.summary-chip.normal,
.log-type.normal {
  color: #53616b;
  background: #eef3f5;
}

.logs-content {
  overflow: auto;
  padding: 0 20px 20px;
}

.logs-loading {
  padding: 28px 0;
  color: var(--muted);
  font-weight: 800;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.logs-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 10px;
  text-align: left;
  color: var(--muted);
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.logs-table td {
  padding: 12px 10px;
  border-bottom: 1px solid #edf3f5;
  vertical-align: top;
}

.log-row.error td {
  background: #fff8f7;
}

.log-row.heartbeat td {
  background: #fbfef8;
}

.users-layout {
  max-width: 1440px;
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
  margin: 0 auto;
}

.user-form,
.users-list-panel {
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 12px 32px rgba(18, 67, 82, 0.1);
}

.user-form {
  display: grid;
  align-content: start;
  gap: 14px;
}

.user-form h3,
.users-list-panel h3 {
  margin: 0;
}

.user-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.user-form input,
.user-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
  resize: vertical;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions .demo-button {
  margin: 0;
}

.users-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.user-row div:first-child {
  min-width: 0;
}

.user-row strong,
.user-row span {
  display: block;
}

.user-row strong {
  margin-bottom: 4px;
}

.user-row span {
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 700;
}

.user-actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
}

@keyframes wave {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(14px);
  }
}

@keyframes bob {
  0%,
  100% {
    top: -10px;
  }
  50% {
    top: -14px;
  }
}

@keyframes waterCurrent {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 62px 0, 0 0;
  }
}

@keyframes fillRing {
  0% {
    box-shadow: 0 0 0 0 rgba(65, 212, 241, 0.36), 0 12px 28px rgba(23, 135, 199, 0.18);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(65, 212, 241, 0), 0 12px 28px rgba(23, 135, 199, 0.18);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(65, 212, 241, 0), 0 12px 28px rgba(23, 135, 199, 0.18);
  }
}

@keyframes badgePulse {
  0%,
  100% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 rgba(65, 212, 241, 0.28);
  }
  50% {
    transform: translateY(-1px);
    box-shadow: 0 0 0 5px rgba(65, 212, 241, 0);
  }
}

@keyframes dropBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(2px);
  }
}

@keyframes surfaceBubbles {
  0% {
    opacity: 0.35;
    transform: translateY(4px) scale(0.9);
  }
  45% {
    opacity: 1;
  }
  100% {
    opacity: 0.25;
    transform: translateY(-8px) scale(1.08);
  }
}

@media (max-width: 760px) {
  .dashboard {
    padding: 14px;
  }

  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    min-width: 0;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 44px 44px;
  }

  .status-strip {
    grid-template-columns: 1fr 1fr;
  }

  .reservoir-row {
    grid-template-columns: 1fr;
  }

  .site-card header {
    align-items: stretch;
    flex-direction: column;
  }

  .card-actions {
    justify-content: space-between;
  }

  .logs-modal {
    padding: 10px;
  }

  .logs-panel {
    max-height: calc(100vh - 20px);
  }

  .logs-header {
    padding: 16px;
  }

  .logs-summary {
    padding: 12px 16px;
  }

  .logs-content {
    padding: 0 16px 16px;
  }

  .logs-table,
  .logs-table thead,
  .logs-table tbody,
  .logs-table tr,
  .logs-table th,
  .logs-table td {
    display: block;
  }

  .logs-table thead {
    display: none;
  }

  .logs-table tr {
    margin: 12px 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .logs-table td {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid #edf3f5;
  }

  .logs-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
  }

  .users-layout {
    grid-template-columns: 1fr;
  }

  .user-row {
    align-items: stretch;
    flex-direction: column;
  }

  .user-actions {
    justify-content: flex-end;
  }
}
