:root {
  color-scheme: light;
  --danger: #c62828;
  --danger-bg: #fdecea;
  --warning: #b26a00;
  --warning-bg: #fff4e0;
  --normal: #2e7d32;
  --normal-bg: #eaf6ea;
  --nodata: #616161;
  --nodata-bg: #f0f0f0;
  --border: #ddd;
  --text: #222;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #fafafa;
}

.topbar {
  background: #0d3b66;
  color: #fff;
  padding: 1.25rem 1.5rem;
  position: sticky;
  top: 0;
  /* Above Leaflet's own panes/controls (max z-index 1000), so the map
     doesn't paint over the sticky header while the page scrolls. */
  z-index: 1100;
}
.topbar h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.subtitle { margin: 0; opacity: 0.85; font-size: 0.9rem; }

.tabs { margin-top: 0.9rem; display: flex; gap: 0.5rem; }
.tabs a {
  color: #fff;
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border-radius: 6px 6px 0 0;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.12);
}
.tabs a.active { background: #fafafa; color: #0d3b66; font-weight: 600; }

main.page-layout {
  display: flex;
  align-items: flex-start;
  width: 100%;
}

.page-content {
  flex: 1;
  min-width: 0;
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}
.page-content.wide { max-width: 1500px; }

@media (max-width: 820px) {
  main.page-layout { flex-direction: column; }
}

section { margin-top: 2rem; }
h2 { font-size: 1.1rem; margin-bottom: 0.25rem; }
.meta { color: #555; font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }

.notice {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.notice-unavailable {
  background: var(--nodata-bg);
  border: 1px solid var(--nodata);
  color: var(--nodata);
}

.banner { padding: 1rem 1.25rem; border-radius: 8px; margin-bottom: 1rem; }
.banner h2 { margin-top: 0; }
.banner ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.banner-alert { background: var(--danger-bg); border: 1px solid var(--danger); }
.banner-alert li { margin-bottom: 0.35rem; }
.banner-ok { background: var(--normal-bg); border: 1px solid var(--normal); color: var(--normal); font-weight: 600; }

.tag-new {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-right: 0.4rem;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
/* Bounds the huge flood table so its own header can stay pinned (position:
   sticky needs a real bounded scroll container - without a max-height the
   header just scrolls away with 300+ rows of content) and so the page's
   own scroll doesn't have to travel through all of them to reach the
   sections below. */
.table-wrap-tall { max-height: 65vh; overflow-y: auto; }

.table-wrap::before, .table-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 3;
}
.table-wrap::before { left: 0; background: linear-gradient(to right, rgba(0, 0, 0, 0.1), transparent); }
.table-wrap::after { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, 0.1), transparent); }
.table-wrap.has-scroll-left::before { opacity: 1; }
.table-wrap.has-scroll-right::after { opacity: 1; }

table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { padding: 0.5rem 0.6rem; text-align: left; white-space: nowrap; }
thead th { background: #f0f0f0; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr.js-hidden { display: none; }

.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.6rem;
}
.table-controls input[type="search"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  min-width: 240px;
}
.table-controls label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.table-controls .meta { margin: 0; }

tr.level-danger { background: var(--danger-bg); }
tr.level-danger td:last-of-type { color: var(--danger); font-weight: 700; }
tr.level-warning { background: var(--warning-bg); }
tr.level-warning td:nth-last-child(2), tr.level-warning td:last-child { color: var(--warning); font-weight: 700; }
tr.level-no_data { color: #888; }
tr.level-normal td:last-of-type { color: var(--normal); }

li.level-danger strong, li.level-warning strong { text-decoration: underline; }

#map, #windy-frame { height: 72vh; min-height: 420px; width: 100%; border-radius: 8px; border: 1px solid var(--border); }
#windy-frame { display: block; }
.view-hidden { display: none !important; }

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  /* Pinned below the sticky topbar (--topbar-height is measured in JS,
     base.html) so the view switch stays reachable without scrolling back
     up, and its own opaque background/z-index keep the map's tiles and
     Leaflet controls (z-index up to 1000) from scrolling over it. */
  position: sticky;
  top: var(--topbar-height, 90px);
  z-index: 1050;
  background: #fafafa;
  padding: 0.6rem 0;
  font-size: 0.85rem;
}

.map-view-switch { display: flex; gap: 0.4rem; }
.view-btn {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #333;
  cursor: pointer;
}
.view-btn.active { background: #0d3b66; color: #fff; border-color: #0d3b66; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-left: auto;
}
.legend span { display: flex; align-items: center; gap: 0.35rem; }

@media (max-width: 820px) {
  /* At this width .legend's own fit-content sizing exceeds the available
     row width without ever triggering its own flex-wrap, clipping the
     last item(s) off-screen. Stacking the toolbar forces each child
     (including .legend) to the container's full width, so .legend's wrap
     applies within a width it can actually work with. */
  .map-toolbar { flex-direction: column; align-items: stretch; }
  .legend { margin-left: 0; }
}
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.swatch.diamond { border-radius: 2px; transform: rotate(45deg); }
.swatch.danger { background: var(--danger); }
.swatch.warning { background: #f5a623; }
.swatch.normal { background: var(--normal); }
.swatch.no_data { background: #9e9e9e; }
.swatch.rainfall { background: #1565c0; opacity: 0.55; }
.swatch.rainfall-heavy { background: #c62828; opacity: 0.55; }

.map-status { font-size: 0.8rem; color: #666; margin-top: 0.5rem; }

.leaflet-popup-content b { display: block; margin-bottom: 0.15rem; }
.leaflet-popup-content .pill {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}
.pill.danger { background: var(--danger); }
.pill.warning { background: #b26a00; }
.pill.normal { background: var(--normal); }
.pill.no_data { background: #757575; }

footer {
  text-align: center;
  color: #777;
  font-size: 0.8rem;
  padding: 1.5rem 1rem 2rem;
}
footer a { color: #0d3b66; }

.assistant-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  position: sticky;
  /* Offset below the sticky topbar (--topbar-height, set in base.html) so
     it doesn't get stuck underneath it once scrolled. */
  top: calc(var(--topbar-height, 90px) + 1.25rem);
  z-index: 1050;
  margin: 1.25rem 0;
  height: calc(100vh - var(--topbar-height, 90px) - 2.5rem);
  max-height: calc(100vh - var(--topbar-height, 90px) - 2.5rem);
  overflow: hidden;
  transition: width 0.15s ease;
}
.assistant-sidebar.collapsed {
  width: auto;
  height: auto;
}
.assistant-sidebar.collapsed .assistant-title,
.assistant-sidebar.collapsed .assistant-body {
  display: none;
}

@media (max-width: 820px) {
  .assistant-sidebar {
    width: 100%;
    position: static;
    height: 55vh;
    max-height: 55vh;
    margin: 0 0 1rem;
    border-left: 1px solid var(--border);
    border-radius: 8px;
  }
  .assistant-sidebar.collapsed { width: 100%; height: auto; }
}

.assistant-header {
  background: #0d3b66;
  color: #fff;
  padding: 0.6rem 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.assistant-header button {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  margin: -0.3rem -0.5rem -0.3rem 0;
}
.assistant-header button:hover,
.assistant-header button:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.assistant-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.assistant-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 200px;
}

.assistant-msg {
  margin: 0;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  max-width: 88%;
  white-space: pre-wrap;
}
.assistant-msg-bot {
  background: #f0f0f0;
  color: var(--text);
  align-self: flex-start;
}
.assistant-msg-user {
  background: #0d3b66;
  color: #fff;
  align-self: flex-end;
}

.assistant-form {
  display: flex;
  border-top: 1px solid var(--border);
}
.assistant-form input {
  flex: 1;
  border: none;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  outline: none;
}
.assistant-form button {
  border: none;
  background: #0d3b66;
  color: #fff;
  padding: 0 1rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.assistant-form button:hover { background: #114a80; }
