/**
 * AgriNewBras Irrigação & Manejo • Design System Fluido Mobile & Desktop
 * Desenvolvido para smartphone em campo e workstation no escritório.
 */

:root {
  --primary: #007a3d;
  --primary-dark: #00562b;
  --primary-light: #e6f4ea;
  --accent-water: #0077b6;
  --accent-water-dark: #023e8a;
  --accent-water-light: #e0f2fe;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --surface: #ffffff;
  --background: #f8fafc;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  font-family: var(--font-sans);
  background-color: var(--background);
  color: var(--text-main);
  overflow: hidden;
}

/* APP SHELL */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* TOP NAVBAR */
.top-navbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  flex-shrink: 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--accent-water));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 16px;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-nav {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-nav.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

/* MAIN WORKSPACE */
.workspace {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* MAP WRAPPER & CONTAINER */
.map-wrapper {
  flex: 1;
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
  display: flex;
}

#map {
  flex: 1;
  width: 100%;
  height: 100%;
  z-index: 10;
  background: #e5e7eb;
}

/* SIDE PANEL (DESKTOP) & BOTTOM SHEET (MOBILE) */
.side-panel {
  width: 440px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
}

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #f1f5f9;
}

.tab-btn {
  flex: 1;
  padding: 12px 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  background: var(--surface);
  border-bottom-color: var(--primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* FORM STYLES */
.form-group {
  margin-bottom: 14px;
}

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

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

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

/* BADGES & CARDS */
.metric-card {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
}

.metric-header {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.metric-unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-success { background: var(--primary-light); color: var(--primary-dark); }
.badge-water { background: var(--accent-water-light); color: var(--accent-water-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning); }

/* FLOATING MAP TOOLS & NOTIFICATIONS */
.map-tools-overlay {
  position: absolute;
  top: 12px;
  left: 60px; /* Posicionado após a barra de desenho que termina em 44px */
  z-index: 500;
  display: flex;
  align-items: center;
  pointer-events: auto;
  animation: fadeInDown 0.3s ease;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-card {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.10);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.tool-text {
  font-weight: 500;
  color: var(--text-main);
}

.btn-close-overlay {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-left: 4px;
}

.btn-close-overlay:hover, .btn-close-overlay:active {
  background: rgba(0,0,0,0.08);
  color: var(--danger);
}

/* BOTÃO FLUTUANTE DE DESENHO RÁPIDO (FAB) */
.fab-draw {
  position: absolute;
  bottom: 24px;
  right: 16px;
  z-index: 450;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 122, 61, 0.45);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.fab-draw:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px rgba(0, 122, 61, 0.55);
}

.fab-draw:active {
  transform: translateY(0) scale(0.98);
}

/* UTILITÁRIOS RESPONSIVOS */
.no-desktop {
  display: none;
}

/* RESPONSIVIDADE MOBILE / SMARTPHONE (< 900px) */
@media (max-width: 900px) {
  .no-desktop {
    display: flex;
  }
  
  .hide-mobile {
    display: none !important;
  }

  .app-container {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
  }
  
  .top-navbar {
    height: 48px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .brand-group {
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
    font-size: 13px;
    flex-shrink: 0;
  }
  
  .brand-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-subtitle {
    display: none !important;
  }

  .nav-actions {
    gap: 4px;
    flex-shrink: 0;
  }

  .nav-actions .btn-text {
    display: none; /* No smartphone exibe ícone limpo */
  }

  .btn-nav {
    padding: 6px 8px;
    font-size: 12px;
  }

  #lblAreaHa {
    font-size: 11px;
    padding: 3px 6px;
  }
  
  .workspace {
    position: relative;
    width: 100%;
    height: calc(100% - 48px);
    overflow: hidden;
  }
  
  .map-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
  }

  #map {
    width: 100% !important;
    height: 100% !important;
  }

  /* Notificação compacta no mobile */
  .map-tools-overlay {
    top: 8px;
    left: 54px;
    max-width: calc(100% - 110px);
  }

  .tool-card {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Botão FAB no mobile acima do bottom sheet minimizado */
  .fab-draw {
    bottom: 70px;
    right: 12px;
    padding: 10px 16px;
    font-size: 13px;
    z-index: 450;
  }

  /* Leaflet & Geoman controles touch confortáveis */
  .leaflet-top.leaflet-left {
    top: 8px;
    left: 8px;
  }

  .leaflet-pm-toolbar .leaflet-buttons-control-button {
    width: 38px !important;
    height: 38px !important;
    line-height: 38px !important;
  }

  .leaflet-bar a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
  }

  /* BOTTOM SHEET FLUÍDO NO SMARTPHONE */
  .side-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    height: 84dvh;
    border-left: none;
    border-top: 2px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 56px)); /* Minimizada mostrando barra resumo */
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -8px 30px rgba(0,0,0,0.22);
    z-index: 600;
  }

  .side-panel.expanded {
    transform: translateY(0);
  }

  .side-panel.half {
    transform: translateY(48%);
  }

  .sheet-drag-area {
    padding: 6px 16px 8px 16px;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border);
  }

  .sheet-drag-handle {
    width: 44px;
    height: 5px;
    background: #cbd5e1;
    border-radius: 999px;
    margin: 2px auto 6px auto;
  }

  .sheet-mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
  }

  .sheet-mobile-title {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--primary);
  }

  .sheet-chevron {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
  }

  .panel-header {
    display: none; /* No mobile usamos o sheet-mobile-bar */
  }

  /* Abas de navegação com rolagem horizontal touch */
  .tab-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .tab-nav::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    white-space: nowrap;
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* ESTILIZAÇÃO PARA IMPRESSÃO DO MEMORIAL TÉCNICO A4 */
@media print {
  body {
    background: white;
    color: black;
    overflow: visible;
  }
  .top-navbar, .map-tools-overlay, .tab-nav, .no-print {
    display: none !important;
  }
  .app-container, .workspace, .side-panel {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    box-shadow: none !important;
    border: none !important;
  }
  .panel-content {
    overflow: visible !important;
    padding: 0 !important;
  }
  .report-page {
    page-break-after: always;
    margin: 20mm;
  }
}
