/* ============================================================
   Sewage Treatment Plant Maintenance Log — Apple-style theme
   Light + dark mode via [data-theme] on <html>.
   ============================================================ */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
    Helvetica, Arial, sans-serif;

  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #fbfbfd;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --border: #e2e2e6;
  --border-strong: #d0d0d5;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);

  --danger: #ff3b30;
  --danger-soft: rgba(255, 59, 48, 0.12);
  --warning: #ff9500;
  --warning-soft: rgba(255, 149, 0, 0.14);
  --success: #34c759;
  --success-soft: rgba(52, 199, 89, 0.14);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --ring: 0 0 0 4px var(--accent-soft);

  --nav-h: 56px;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-elev-2: #2c2c2e;
  --text: #f5f5f7;
  --text-muted: #98989d;
  --border: #38383a;
  --border-strong: #48484a;

  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.18);

  --danger: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.2);
  --warning: #ff9f0a;
  --warning-soft: rgba(255, 159, 10, 0.2);
  --success: #30d158;
  --success-soft: rgba(48, 209, 88, 0.2);

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
/* width:100% is required: in a flex column, the container's `margin:0 auto`
   uses auto cross-axis margins which otherwise prevent it from stretching,
   collapsing content-light pages (e.g. the map) to their intrinsic width. */
body > main { flex: 1 0 auto; width: 100%; }

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

h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; margin: 0 0 0.5em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

/* ---------- Navbar ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.nav-brand {
  font-weight: 600;
  color: var(--text);
  margin-right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.nav-brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 2px; align-items: center; flex: 1; overflow-x: auto; }
.nav-link {
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.nav-link:hover { background: var(--bg-elev-2); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--text); font-weight: 500; }
.nav-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }

.lang-switch { display: flex; gap: 2px; font-size: 0.8rem; }
.lang-switch a {
  padding: 4px 7px; border-radius: 7px; color: var(--text-muted);
}
.lang-switch a.active { background: var(--accent-soft); color: var(--accent); }
.lang-switch a:hover { text-decoration: none; }

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 26px 18px 80px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 22px; flex-wrap: wrap;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat .num { font-size: 2rem; font-weight: 600; letter-spacing: -0.03em; }
.stat .label { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 980px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn-secondary {
  background: var(--bg-elev-2); color: var(--text); border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.85rem; font-weight: 500;
  margin-bottom: 6px; color: var(--text);
}
.field .hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 5px; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 90px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 150px; }

/* Measurement trend charts */
.chart-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.chart-card { padding: 14px 16px 10px; }
.chart-title { margin: 0 0 6px; font-size: 0.95rem; }

/* Click-to-enlarge charts */
.chart-card.zoomable { cursor: zoom-in; }
.chart-card.zoomable:hover { border-color: var(--accent); }
.chart-modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.chart-modal {
  position: relative;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px 22px 14px;
  width: min(1000px, 96vw); max-height: 92vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.chart-modal .chart-title { font-size: 1.15rem; margin: 0 32px 12px 0; }
.chart-modal-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; cursor: pointer;
  font-size: 1.2rem; line-height: 1; color: var(--text-muted);
  padding: 4px 8px; border-radius: 8px;
}
.chart-modal-close:hover { background: var(--bg-elev-2); color: var(--text); }
.chart-modal-hint { margin: 8px 2px 0; font-size: 0.8rem; color: var(--text-muted); }
.xhair-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.xhair-dot { fill: var(--accent); stroke: var(--bg-elev); stroke-width: 2; }
.xhair-box { fill: var(--bg-elev); stroke: var(--border); stroke-width: 1; opacity: 0.98; }
.xhair-text { fill: var(--text); font-size: 10px; }
.xhair-value { font-weight: 600; }

/* Out-of-range measurement value */
.measure-warn { color: var(--danger); font-weight: 600; }
.field-error { color: var(--danger); font-size: 0.78rem; margin-top: 4px; }

/* Nav search box */
.nav-search { display: flex; }
.nav-search input {
  width: 160px; max-width: 40vw; padding: 5px 10px; font-size: 0.85rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elev);
  color: var(--text);
}
.nav-search input:focus { outline: none; border-color: var(--accent); }
/* On phones the input would squeeze .nav-links to zero width, so swap it for
   an icon linking to the search page, which carries a full-width form. */
.nav-search-link { display: none; }
@media (max-width: 720px) {
  .nav-search { display: none; }
  .nav-search-link { display: inline-flex; }
}

/* Pagination */
.pagination {
  display: flex; align-items: center; gap: 14px;
  justify-content: center; margin-top: 18px;
}
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn > input, .input-with-btn > select { flex: 1; }

/* Password fields: show/hide toggle (wrapper + button injected by app.js) */
.pw-field { position: relative; display: block; }
.pw-field input { width: 100%; padding-right: 2.7rem; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.pw-toggle:hover { color: var(--text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--bg-elev); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { font-weight: 600; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-elev-2); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 980px;
  font-size: 0.76rem; font-weight: 500;
}
.badge-plant { background: var(--accent-soft); color: var(--accent); }
.badge-shaft { background: var(--warning-soft); color: var(--warning); }
.badge-connection { background: var(--success-soft); color: var(--success); }
.badge-neutral { background: var(--bg-elev-2); color: var(--text-muted); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-due_soon { background: var(--warning-soft); color: var(--warning); }
.badge-ok { background: var(--success-soft); color: var(--success); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-plant { background: var(--accent); }
.dot-shaft { background: var(--warning); }
.dot-connection { background: var(--success); }

/* ---------- Flash / alerts ---------- */
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 18px; font-size: 0.9rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ---------- Login ---------- */
.auth-wrap { display: grid; place-items: center; padding: 40px 20px; }

/* ---------- Site footer (on every page) ---------- */
.site-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 22px 18px 30px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.82rem;
}
.site-footer strong { color: var(--text); font-weight: 600; }
.site-footer .sep { margin: 0 8px; opacity: 0.45; }
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--accent); }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { text-align: center; font-size: 2.4rem; margin-bottom: 8px; }

/* ---------- Entry / list items ---------- */
.entry-item { padding: 16px 0; border-bottom: 1px solid var(--border); }
.entry-item:last-child { border-bottom: none; }
.entry-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--text-muted); font-size: 0.82rem; margin-bottom: 6px; }
.entry-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.entry-thumbs img { width: 74px; height: 74px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.empty {
  text-align: center; padding: 50px 20px; color: var(--text-muted);
}
.empty .emoji { font-size: 2.5rem; display: block; margin-bottom: 10px; }

.muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.inline-form { display: inline; }

/* ---------- Speech button ---------- */
.speech-btn {
  border: 1px solid var(--border-strong); background: var(--bg-elev-2);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer; font-size: 0.9rem;
}
.speech-btn.listening { color: var(--danger); border-color: var(--danger); }
.speech-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Map ---------- */
#map { height: 65vh; min-height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }
.map-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }
.pipe-line { display: inline-block; width: 18px; border-top: 3px solid #64748b; }

.map-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.map-add-btn {
  padding: 7px 14px; border-radius: 980px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--bg-elev);
  color: var(--text); font-family: inherit; font-size: 0.85rem; font-weight: 500;
}
.map-add-btn:hover { background: var(--bg-elev-2); }
.map-add-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.map-place-hint { font-size: 0.82rem; color: var(--accent); }

.map-create-form label { display: block; font-size: 0.78rem; font-weight: 500; margin: 8px 0 3px; }
.map-create-form input {
  width: 100%; padding: 7px 9px; border-radius: 8px; font-size: 0.88rem;
  border: 1px solid var(--border-strong); background: var(--bg-elev-2); color: var(--text);
}
.map-create-form .mc-err { color: var(--danger); font-size: 0.78rem; min-height: 1em; margin-top: 6px; }
.map-create-form .mc-actions { display: flex; gap: 8px; margin-top: 10px; }
/* Leaflet popup should adopt the app's surface colours (esp. in dark mode). */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-elev); color: var(--text);
  box-shadow: var(--shadow);
}
.leaflet-popup-content { font-family: var(--font); }
.leaflet-popup-content a { color: var(--accent); }

@media (max-width: 640px) {
  .nav-brand span { display: none; }
  h1 { font-size: 1.5rem; }
  .container { padding: 18px 14px 80px; }
}

/* ---------- Tooltips ---------- */
/* Texts are rendered server-side into data-tip, so they follow the language
   cookie like every other string. app.js positions a single floating bubble
   because .table-wrap / .nav-links scroll containers would clip a ::after. */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 5px; padding: 0;
  vertical-align: middle; flex: none;
  border: 1px solid var(--border-strong); border-radius: 50%;
  background: none; color: var(--text-muted);
  font-family: var(--font); font-size: 0.62rem; font-style: italic;
  font-weight: 600; line-height: 1; cursor: help;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tip:hover, .tip:focus-visible { color: var(--accent); border-color: var(--accent); }
.tip:focus-visible { outline: none; box-shadow: var(--ring); }

.tooltip {
  position: fixed; top: 0; left: 0; z-index: 1100;
  max-width: 260px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.78rem; line-height: 1.35; text-align: left;
  white-space: normal; pointer-events: none;
  opacity: 0; transform: translateY(3px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.tooltip.visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .tip, .tooltip { transition: none; }
}
