/* ==========================================================================
   Meu Aquário — Dashboard
   ========================================================================== */

:root {
  --sidebar-bg: linear-gradient(180deg, #134e4a 0%, #042f2e 100%);
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.14);
  --sidebar-text: rgba(255, 255, 255, 0.72);
  --sidebar-text-strong: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.1);

  --brand-green: #0f766e;
  --brand-green-light: #14b8a6;

  --accent-green-900: #042f2e;
  --accent-green-700: #115e59;
  --accent-green-500: #0d9488;
  --accent-green-300: #5eead4;
  --accent-green-200: #99f6e4;
  --accent-green-100: #c7e7e1;

  --bg-page: #f2f0e8;
  --card-bg: #ffffff;

  --text-dark: #16241a;
  --text-muted: #6f7669;
  --text-faint: #98a091;

  --border-subtle: #e7e4d9;

  --warning-bg: #fbe3e2;
  --warning-fg: #d5473c;
  --calendar-bg: #fbead0;
  --calendar-fg: #c9862c;
  --neutral-bg: #ececE6;
  --neutral-fg: #6f7669;
  --message-bg: #bff7db;
  --message-fg: #115e59;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(20, 30, 20, 0.04), 0 1px 12px rgba(20, 30, 20, 0.03);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--text-dark);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html.android-webview body {
  padding-top: max(24px, env(safe-area-inset-top));
}

html.android-webview .sidebar {
  background: #042f2e;
  background: var(--sidebar-bg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

html.android-webview .app-shell {
  min-height: calc(100vh - max(24px, env(safe-area-inset-top)));
}

.page-kicker {
  margin: 0 0 5px;
  color: var(--brand-green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
}

svg {
  width: 100%;
  height: 100%;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------------------------------- Sidebar ---------------------------------- */

.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.2s ease;
}

/* Recolhida: só ícones, texto escondido */
.sidebar.sidebar--collapsed {
  width: 84px;
  padding-left: 14px;
  padding-right: 14px;
}

.sidebar.sidebar--collapsed .brand {
  justify-content: center;
  padding: 4px 0;
}

.sidebar.sidebar--collapsed .brand-name,
.sidebar.sidebar--collapsed .btn-label,
.sidebar.sidebar--collapsed .nav-link span,
.sidebar.sidebar--collapsed .sidebar-collapse span {
  display: none;
}

.sidebar.sidebar--collapsed .brand-icon img {
  visibility: hidden;
}

.sidebar.sidebar--collapsed .btn-new-process {
  padding: 12px;
}

.sidebar.sidebar--collapsed .nav-link {
  justify-content: center;
  padding: 10px;
}

.sidebar.sidebar--collapsed .sidebar-collapse {
  justify-content: center;
}

.sidebar.sidebar--collapsed .sidebar-collapse svg {
  transform: rotate(180deg);
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.brand-icon img {
  /*width: 60px;*/
  height: 150px;
  border-radius: 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0px;
  flex-shrink: 0;
}

.brand-name {
  color: var(--sidebar-text-strong);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.btn-new-process {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(180deg, #14b8a6 0%, #0f766e 100%);
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: none;
  transition: filter 0.15s ease;
}

.btn-new-process svg {
  width: 17px;
  height: 17px;
}

.btn-new-process:hover {
  filter: brightness(1.08);
}

.sidebar-nav ul {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--sidebar-text);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.nav-link svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke-width: 2.2;
}

.nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-strong);
}

.nav-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-strong);
  font-weight: 700;
}

.nav-link:hover svg,
.nav-link.active svg {
  transform: scale(1.04);
}

.sidebar-collapse {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  border-top: 1px solid var(--sidebar-border);
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 16px 12px 4px;
}

.sidebar-collapse svg {
  width: 16px;
  height: 16px;
}

.sidebar-collapse:hover {
  color: var(--sidebar-text-strong);
}

/* ---------------------------------- Main area ---------------------------------- */

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-page);
  position: relative;
  z-index: 1;
}

.topbar:has(.search-form:focus-within) {
  z-index: 30;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 22, 14, 0.4);
  z-index: 15;
}

.sidebar-backdrop.is-visible {
  display: block;
}

@media (max-width: 860px) {
  body.sidebar-open {
    overflow: hidden;
    overscroll-behavior: none;
  }
}

.menu-toggle-btn {
  display: none;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dark);
}

.menu-toggle-btn svg {
  width: 20px;
  height: 20px;
}

.menu-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.search-form {
  --search-entry-x: 0px;
  --search-entry-y: -80px;
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eae7db;
  border-radius: 999px;
  padding: 10px 16px;
  transition: background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, width 160ms ease;
  position: relative;
  z-index: 2;
}

.search-form:focus-within {
  position: fixed;
  top: 25%;
  left: 50%;
  width: min(720px, calc(100vw - 32px));
  max-width: none;
  transform: translate(-50%, -50%) scale(1.03);
  animation: search-focus-in 180ms ease-out both;
  background: var(--card-bg);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

html:not(.android-webview):has(.search-form:focus-within),
html:not(.android-webview) body:has(.search-form:focus-within) {
  overflow: hidden;
  overscroll-behavior: none;
}

html.android-webview:has(.search-form:focus-within),
html.android-webview body:has(.search-form:focus-within) {
  overscroll-behavior: none;
  touch-action: none;
}

@keyframes search-focus-in {
  from {
    opacity: 0.7;
    transform: translate(
      calc(-50% + var(--search-entry-x)),
      calc(-50% + var(--search-entry-y))
    ) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.03);
  }
}

.search-form .search-icon {
  width: 17px;
  height: 17px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color 160ms ease;
}

.search-form:focus-within .search-icon {
  color: var(--brand-green);
}

.app-shell:has(.search-form:focus-within) .sidebar,
.app-shell:has(.search-form:focus-within) .content,
.app-shell:has(.search-form:focus-within) .topbar > :not(.search-form) {
  filter: blur(5px);
  opacity: 0.52;
  pointer-events: none;
  transition: filter 160ms ease, opacity 160ms ease;
}

.search-form input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 14px;
  color: var(--text-dark);
  font-family: inherit;
}

.search-form input::placeholder {
  color: var(--text-faint);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.notif-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e0483d;
  border: 2px solid var(--bg-page);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  padding: 4px 6px 4px 4px;
  border-radius: 999px;
}

.user-menu:hover {
  background: rgba(0, 0, 0, 0.05);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-weight: 600;
  font-size: 14.5px;
}

.chevron {
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  flex-shrink: 0;
}

/* ---------------------------------- Dropdowns ---------------------------------- */

.dropdown {
  position: relative;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 10px);
  min-width: 240px;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 30px rgba(20, 30, 20, 0.14);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
  z-index: 30;
}

.dropdown-panel--right {
  right: 0;
}

.dropdown-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dark);
  padding: 8px 10px 6px;
}

.dropdown-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}

.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-dark);
}

li.dropdown-item {
  cursor: default;
}

.dropdown-item--link {
  cursor: pointer;
}

.dropdown-item--link:hover,
li.dropdown-item:hover {
  background: var(--bg-page);
}

.dropdown-item--danger {
  color: var(--warning-fg);
}

.dropdown-item-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dark);
}

.dropdown-item-time {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.dropdown-empty {
  padding: 16px 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.dropdown-logout-form {
  margin: 0;
}

.dropdown-logout-form .dropdown-item {
  width: 100%;
}

.content {
  padding: 28px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------------------------------- Info banner ---------------------------------- */

.info-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-green-100);
  color: var(--accent-green-700);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 500;
}

.info-banner svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ---------------------------------- Page header ---------------------------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.page-header .action-link { flex-shrink: 0; }

@media (max-width: 720px) {
  .page-header {
    flex-direction: column;
    gap: 14px;
  }

  .page-header .action-link {
    width: 100%;
    justify-content: center;
  }
}

.page-header h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.page-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14.5px;
}

.view-toggle {
  display: flex;
  background: #e9e6da;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}

.toggle-btn {
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.toggle-btn.active {
  background: #fff;
  color: var(--accent-green-700);
  box-shadow: var(--shadow-card);
}

.section-subtitle {
  margin: 4px 0 20px;
  font-size: 13.5px;
  color: var(--text-muted);
}

/* ---------------------------------- Water page ---------------------------------- */

.page-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
}

.action-group-label {
  padding: 0 5px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.action-group-links {
  display: flex;
  gap: 5px;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  transition: filter 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.action-link svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.action-link--primary {
  background: var(--brand-green);
  color: #fff;
}

.action-link--secondary {
  background: var(--card-bg);
  color: var(--accent-green-700);
  border: 1px solid var(--border-subtle);
}

.action-link:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.water-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.water-metric {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-page);
  border-left: 4px solid var(--accent-green-500);
}

.water-metric--temperature { border-color: #d97706; }
.water-metric--ph { border-color: #0d9488; }
.water-metric--gh { border-color: #2563eb; }
.water-metric--kh { border-color: #7c3aed; }

.water-metric-label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 7px;
}

.water-metric strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.water-metric small {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 3px;
  font-weight: 600;
}

.water-note {
  margin: 18px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state {
  padding: 24px 0 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state p {
  margin: 0;
}

/* ---------------------------------- Pipeline ---------------------------------- */

.pipeline {
  display: flex;
  align-items: stretch;
  gap: 10px;
  overflow-x: auto;
}

.pipeline-stage {
  flex: 1;
  min-width: 130px;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pipeline-count {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.pipeline-label {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.9;
}

.pipeline-arrow {
  flex-shrink: 0;
  width: 18px;
  align-self: center;
  color: var(--text-faint);
}

.stage-1 {
  background: var(--accent-green-100);
  color: #134e4a;
}

.stage-2 {
  background: var(--accent-green-200);
  color: #134e4a;
}

.stage-3 {
  background: #5eead4;
  color: #134e4a;
}

.stage-4 {
  background: #2dd4bf;
  color: #134e4a;
}

.stage-5 {
  background: #0d9488;
  color: #ffffff;
}

.stage-6 {
  background: #134e4a;
  color: #ffffff;
}

/* ---------------------------------- Bottom grid ---------------------------------- */

.bottom-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 20px;
  align-items: stretch;
}

/* Distribution donut */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 26px;
  flex-wrap: wrap;
}

.donut {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}

.donut-hole {
  position: absolute;
  inset: 22px;
  background: var(--card-bg);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-hole strong {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.donut-hole span {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 160px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
}

.legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-label {
  flex: 1;
  color: var(--text-dark);
}

.legend-value {
  font-weight: 700;
}

.ring-wrap {
  margin: 10px 0 4px;
}

.ring {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  position: relative;
}

.ring-hole {
  position: absolute;
  inset: 20px;
  background: var(--card-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-hole strong {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-green-700);
}

.ring-caption {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Responsibility gaps */
.gap-boxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.gap-box {
  background: var(--bg-page);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gap-box svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.gap-box strong {
  font-size: 24px;
  font-weight: 800;
}

.gap-box span {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ---------------------------------- Responsive ---------------------------------- */

@media (max-width: 1180px) {
  .bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .user-name,
  .chevron {
    display: none;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  html.android-webview .sidebar {
    top: 0;
    bottom: 0;
    height: auto;
    background: #042f2e;
  }

  .sidebar.is-open {
    transform: translateX(0);
    -webkit-transform: translateX(0);
  }

  .sidebar.sidebar--collapsed {
    width: 270px;
    padding-left: 18px;
    padding-right: 18px;
  }

  .sidebar.sidebar--collapsed .brand-name,
  .sidebar.sidebar--collapsed .btn-label,
  .sidebar.sidebar--collapsed .nav-link span,
  .sidebar.sidebar--collapsed .sidebar-collapse span {
    display: block;
  }

  .sidebar.sidebar--collapsed .nav-link,
  .sidebar.sidebar--collapsed .brand {
    justify-content: flex-start;
  }

  .sidebar-collapse {
    display: none;
  }

  .menu-toggle-btn {
    display: flex;
  }

  .page-actions {
    width: 100%;
  }

  .action-group {
    flex: 1 1 240px;
  }

  .water-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    padding: 16px;
    gap: 12px;
  }

  .content {
    padding: 20px 16px 40px;
  }

  .search-form {
    max-width: none;
  }

  .dropdown-panel {
    min-width: 210px;
  }
}

.default-back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--accent-green-700);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-card);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.default-back-link svg {
  width: 17px;
  height: 17px;
}

.default-back-link:hover,
.default-back-link:focus-visible {
  border-color: #c7e7e1;
  background: var(--accent-green-100);
}

.default-back-link:focus-visible {
  outline: 3px solid rgba(20, 184, 166, 0.2);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .default-back-link {
    width: 100%;
    justify-content: center;
  }
}

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgb(0 0 0 / 90%);
    pointer-events: none;
}

.lightbox.is-open {
    display: flex;
    pointer-events: auto;
  }

  body.lightbox-open {
    overflow: hidden;
    touch-action: none;
}

.lightbox [data-lightbox-content] {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}

.lightbox [data-lightbox-close] {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: white;
    background: transparent;
    border: 0;
    font-size: 2rem;
    cursor: pointer;
}