/* Laguna Onde — mobile-first dark nautico */

:root {
  --bg: #061827;
  --bg-elev: #0a2538;
  --bg-card: #11324a;
  --fg: #e8eef4;
  --fg-dim: #a9bdcf;
  --accent: #4fc3f7;
  --accent-strong: #29b6f6;
  --warn: #ffb300;
  --danger: #ef5350;
  --ok: #81c784;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 6px 18px rgba(0,0,0,0.4);
  --topbar-h: 56px;
  --bottombar-h: 64px;

  /* Scala colori onde */
  --c1: #4caf50;  /* < 0.10 m */
  --c2: #cddc39;  /* 0.10–0.20 */
  --c3: #ffc107;  /* 0.20–0.50 */
  --c4: #ff7043;  /* 0.50–1.00 */
  --c5: #d32f2f;  /* > 1.00 m */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------- TOPBAR ---------------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: var(--topbar-h);
  background: linear-gradient(135deg, #0a3d62 0%, #0e4d7a 100%);
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 var(--topbar-h);
  padding-top: env(safe-area-inset-top, 0);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
}

#topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#topbar .logo {
  font-size: 24px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

#topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

#topbar .subtitle {
  font-size: 11px;
  margin: 0;
  color: rgba(255,255,255,0.7);
}

#topbar .status {
  display: flex;
  align-items: center;
  gap: 8px;
}

#btn-refresh {
  background: rgba(255,255,255,0.12);
  border: none;
  color: var(--fg);
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform .25s, background .15s;
}

#btn-refresh:active { background: rgba(255,255,255,0.22); }
#btn-refresh.spinning { animation: spin 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.badge {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.14);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.badge.stale { background: var(--warn); color: #000; }
.badge.error { background: var(--danger); color: #fff; }

/* ---------------- CONTENT ---------------- */

#content {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page.active { display: block; }

.page-content {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: calc(var(--bottombar-h) + 16px + env(safe-area-inset-bottom, 0));
}

h2 {
  font-size: 18px;
  margin: 4px 0 12px;
  color: var(--accent);
}

h3 {
  font-size: 15px;
  margin: 18px 0 8px;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.hint {
  font-size: 12px;
  color: var(--fg-dim);
  margin: 0 0 12px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover, a:focus {
  text-decoration: underline;
}

/* ---------------- MAPPA ---------------- */

#page-map {
  display: none;
  position: absolute;
  inset: 0;
}

#page-map.active { display: block; }

#map {
  position: absolute;
  inset: 0;
  bottom: var(--bottombar-h);
  background: #062338;
}

.leaflet-container {
  background: #062338;
  font-family: inherit;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--fg);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.leaflet-popup-tip {
  background: var(--bg-card);
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.leaflet-popup-content .pop-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.leaflet-popup-content .pop-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

.leaflet-popup-content .pop-row .lab { color: var(--fg-dim); }
.leaflet-popup-content .pop-row .val { font-weight: 500; }

.leaflet-popup-content .pop-meta {
  font-size: 10px;
  color: var(--fg-dim);
  margin-top: 6px;
  font-style: italic;
}

/* legenda compatta */

.legend {
  position: absolute;
  bottom: calc(var(--bottombar-h) + 8px + env(safe-area-inset-bottom, 0));
  left: 8px;
  background: rgba(6,24,40,0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 10.5px;
  color: var(--fg-dim);
  z-index: 500;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.legend-title {
  font-weight: 600;
  color: var(--fg);
  margin-right: 2px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.4);
}

.dot.c1 { background: var(--c1); }
.dot.c2 { background: var(--c2); }
.dot.c3 { background: var(--c3); }
.dot.c4 { background: var(--c4); }
.dot.c5 { background: var(--c5); }

.marker-sym {
  display: inline-block;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid #fff;
  vertical-align: middle;
}

.marker-sym.tide { background: #2196f3; border-color: #fff; }
.marker-sym.wind { background: #b388ff; border-color: #fff; }

/* hero box (collassabile) */

#hero-box {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  background: rgba(6,24,40,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 10px;
  font-size: 12.5px;
  z-index: 500;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: max-height .25s ease;
}

.hero-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  flex-wrap: wrap;
}

.hero-mini {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--fg);
  white-space: nowrap;
  flex: 0 0 auto;
}

#btn-hero-toggle {
  margin-left: auto;
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--fg);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
  transition: transform .25s;
}

#hero-box.expanded #btn-hero-toggle {
  transform: rotate(180deg);
}

.hero-detail {
  padding: 0 12px 10px;
  border-top: 1px solid var(--border);
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  gap: 8px;
}

.hero-label {
  color: var(--fg-dim);
  font-size: 11px;
}

.hero-val {
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.hero-val.warn { color: var(--warn); }
.hero-val.danger { color: var(--danger); }

/* map controls (right side) */

#map-controls {
  position: absolute;
  right: 8px;
  top: 60px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 500;
}

.layer-switch {
  background: rgba(6,24,40,0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.layer-btn {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  width: 38px;
  height: 38px;
  font-size: 18px;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-bottom: 1px solid var(--border);
}

.layer-btn:last-child { border-bottom: none; }

.layer-btn.active {
  background: var(--accent-strong);
  color: #fff;
}

.layer-btn:not(.active):active { background: rgba(255,255,255,0.1); }

.map-action {
  background: rgba(6,24,40,0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.map-action:active { background: rgba(255,255,255,0.1); }

#map-tip {
  position: absolute;
  bottom: calc(var(--bottombar-h) + 56px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(6,24,40,0.85);
  color: var(--fg-dim);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  z-index: 500;
  pointer-events: none;
  border: 1px solid var(--border);
  white-space: nowrap;
  animation: fadeOut 6s ease 4s forwards;
}

@keyframes fadeOut {
  to { opacity: 0; }
}

/* bottom sheet — previsione punto */

#forecast-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elev);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  z-index: 1500;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
  animation: sheetSlide .25s ease-out;
}

#forecast-sheet[hidden] { display: none !important; }
[hidden] { display: none !important; }

@keyframes sheetSlide {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  height: 4px;
  width: 36px;
  background: var(--fg-dim);
  border-radius: 2px;
  margin: 6px auto;
  opacity: 0.5;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 16px 8px;
  gap: 12px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.sheet-subtitle {
  font-size: 11.5px;
  color: var(--fg-dim);
  margin-top: 2px;
}

#sheet-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--fg);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 16px 28px;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0));
}

.sheet-body h4 {
  font-size: 13px;
  margin: 14px 0 6px;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
}

.sheet-now {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.sheet-now .now-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1 1 calc(50% - 4px);
  min-width: 100px;
}

.sheet-now .now-card .lab {
  font-size: 11px;
  color: var(--fg-dim);
}

.sheet-now .now-card .val {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  margin-top: 2px;
}

.sheet-chart {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 4px 4px;
  height: 160px;
  border: 1px solid var(--border);
}

.sheet-chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.sheet-chart .axis text { fill: var(--fg-dim); font-size: 9px; }
.sheet-chart .grid line { stroke: var(--border); stroke-dasharray: 2,3; }
.sheet-chart .area-wave { fill: rgba(79,195,247,0.3); }
.sheet-chart .area-wind-wave { fill: rgba(255,179,0,0.25); }
.sheet-chart .area-swell { fill: rgba(129,199,132,0.25); }
.sheet-chart .line-main { fill: none; stroke: var(--accent); stroke-width: 2; }
.sheet-chart .line-sec { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4,3; }
.sheet-chart .day-line { stroke: rgba(255,255,255,0.15); stroke-width: 1; }
.sheet-chart .day-text { fill: var(--accent); font-size: 10px; font-weight: 600; }
.sheet-chart .now-marker { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 3,2; }
.sheet-chart .legend-item { font-size: 9px; }

.sheet-note {
  font-size: 11px;
  color: var(--fg-dim);
  font-style: italic;
  margin: 12px 0 4px;
  line-height: 1.4;
}

/* leaflet style overrides */

.leaflet-control-zoom {
  margin-top: 110px !important;  /* sotto hero box */
}

.leaflet-control-zoom a {
  background: rgba(6,24,40,0.86) !important;
  color: var(--fg) !important;
  border: 1px solid var(--border) !important;
}

.leaflet-control-attribution {
  background: rgba(6,24,40,0.7) !important;
  color: var(--fg-dim) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

/* wave marker custom (svg) */

.wave-marker svg { display: block; }

/* ---------------- TABLES ---------------- */

.data-table {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 0 0 12px;
  font-size: 12.5px;
}

.data-table .row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.data-table .row.head {
  font-weight: 600;
  color: var(--fg-dim);
  background: var(--bg);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table .row:last-child { border-bottom: none; }

.data-table .row .name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.data-table .row .station {
  font-weight: 500;
  color: var(--fg);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.data-table .row .ts {
  font-size: 10px;
  color: var(--fg-dim);
}

.data-table .row .val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.data-table .row.empty {
  text-align: center;
  color: var(--fg-dim);
  font-style: italic;
  padding: 16px;
}

.val.c1 { color: var(--c1); }
.val.c2 { color: var(--c2); }
.val.c3 { color: var(--c3); }
.val.c4 { color: var(--c4); }
.val.c5 { color: var(--c5); }

/* ---------------- FORECAST CHART ---------------- */

#forecast-chart {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 8px 8px;
  margin-bottom: 12px;
  height: 260px;
  position: relative;
}

#forecast-chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

#forecast-chart .axis text {
  fill: var(--fg-dim);
  font-size: 9px;
}

#forecast-chart .axis line, #forecast-chart .axis path {
  stroke: var(--border);
  fill: none;
}

#forecast-chart .grid line {
  stroke: var(--border);
  stroke-dasharray: 2,3;
}

#forecast-chart .ref-line {
  stroke: var(--warn);
  stroke-width: 1.2;
  stroke-dasharray: 4,3;
}

#forecast-chart .ref-text {
  fill: var(--warn);
  font-size: 10px;
  font-weight: 600;
}

#forecast-chart .ref-line.danger { stroke: var(--danger); }
#forecast-chart .ref-text.danger { fill: var(--danger); }

#forecast-chart .point {
  fill: var(--accent);
  stroke: var(--bg-elev);
  stroke-width: 2;
}

#forecast-chart .point.high { fill: var(--warn); }
#forecast-chart .point.danger { fill: var(--danger); }
#forecast-chart .point.low { fill: var(--ok); }

#forecast-chart .label {
  fill: var(--fg);
  font-size: 9px;
  font-weight: 600;
  text-anchor: middle;
}

#forecast-chart .connector {
  stroke: var(--accent);
  stroke-width: 1.5;
  fill: none;
}

/* ---------------- SOURCES ---------------- */

#sources-list .source-cat {
  margin-bottom: 16px;
}

#sources-list h3 {
  font-size: 13px;
  color: var(--accent);
  margin: 0 0 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

#sources-list .src-item {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  text-decoration: none;
}

#sources-list .src-item .src-name {
  font-weight: 500;
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#sources-list .src-item .src-name::after {
  content: "↗";
  color: var(--fg-dim);
  font-size: 14px;
  flex-shrink: 0;
}

#sources-list .src-item .src-desc {
  font-size: 11.5px;
  color: var(--fg-dim);
  margin-top: 2px;
}

#sources-list .src-item:active {
  background: var(--bg-card);
}

/* ---------------- BOTTOMBAR ---------------- */

#bottombar {
  flex: 0 0 var(--bottombar-h);
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0));
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 1000;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  transition: color .15s;
  min-height: var(--bottombar-h);
}

.tab .tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab .tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.tab.active {
  color: var(--accent);
}

.tab:active {
  background: rgba(255,255,255,0.06);
}

/* ---------------- INSTALL BANNER ---------------- */

#install-banner {
  position: fixed;
  bottom: calc(var(--bottombar-h) + 8px + env(safe-area-inset-bottom, 0));
  left: 8px;
  right: 8px;
  background: var(--accent-strong);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  z-index: 1100;  /* sotto al forecast sheet (1500) */
  font-size: 13px;
  animation: slideUp .3s ease-out;
}

body.sheet-open #install-banner { display: none; }

#install-banner button {
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}

#install-banner #btn-install-dismiss {
  background: transparent;
  font-size: 18px;
  padding: 0 6px;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------------- TABLET / DESKTOP ---------------- */

@media (min-width: 720px) {
  #map { right: 0; left: 0; }
  #hero-box {
    max-width: 360px;
    right: auto;
  }
}
