/*
 * ======================
 * THEME VARIABLES
 * ======================
 * Core theme variables for light and dark mode.
 */
:root {
    /* Blueprint blue — cyanotype, the color of technical survey drawings,
       not a generic Bootstrap blue. See STYLE.md. */
    --primary-color: #1d5c8a;
    --primary-dark: #143f5e;
    --text-color: #262a26;
    /* Cool neutral paper, not warm cream — avoids the generic
       cream+serif+terracotta AI-template look. */
    --background-color: #eef1ef;
    --nav-background: #ffffff;
    --nav-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --hover-color: #e7ebe8;
    --toggle-bg: #ddd;
    --toggle-circle: #fff;
    /* Surface tokens. Every box pairs --surface with
       --text-color; --surface-2 is for inputs/table stripes/nested chrome.
       Never hardcode #fff / light grays in component css — use these. */
    --surface: #ffffff;
    --surface-2: #f1f4f2;
    --border-color: #d7dcd8;
    --muted-text: #5f6a63;
    --card-background: var(--surface);
    --card-text-color: var(--text-color);
    --radius: 8px;
    /* Display face: condensed/geometric, signage-like — used sparingly for
       headings and the nav wordmark. Body face is untouched. System stacks
       only: CSP has no external font-src, so nothing is webfont-hosted. */
    --font-display: "Bahnschrift", "Roboto Condensed", "Arial Narrow", "Segoe UI", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "Consolas", "SFMono-Regular", Menlo, monospace;
    color-scheme: light;
    /* Additional color variables for button variants */
    --success-color: #2ecc71;
    --success-dark: #27ae60;
    --info-color: #3498db;
    --info-dark: #2980b9;
    --warning-color: #f39c12;
    --warning-dark: #e67e22;
    --danger-color: #e74c3c;
    --danger-dark: #c0392b;
    /* Status indicator colors */
    --success-bg: #d4edda;
    --success-text: #155724;
    --danger-bg: #f8d7da;
    --danger-text: #721c24;
    --warning-bg: #fdecd2;
    --warning-text: #7a4a05;
    --info-bg: #d7f0ed;
    --info-text: #0f5f57;
}

[data-theme="dark"] {
    /* Brighter cyanotype blue for legibility on dark ink. */
    --primary-color: #4a9fd8;
    --primary-dark: #2f7bab;
    --text-color: #e9ece8;
    /* Deep cartographic ink, cooler and more distinctive than a generic
       charcoal admin-theme gray (owner still wants no pure black). */
    --background-color: #161b1f;
    --nav-background: #1b2126;
    --nav-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --hover-color: #2a3138; /* Dark mode hover color */
    --toggle-bg: #555;
    --toggle-circle: #aaa; /* Dark mode toggle circle */
    /* Mild dark surfaces (no pure black, no white boxes). */
    --surface: #1b2126;
    --surface-2: #232a30;
    --border-color: #333c42;
    --muted-text: #94a09a;
    color-scheme: dark;
    /* Adjust button variant colors to be more visible in dark mode */
    --success-color: #2ecc71;
    --success-dark: #27ae60;
    --info-color: #4bb3a8;
    --info-dark: #368e85;
    --warning-color: #f39c12;
    --warning-dark: #e67e22;
    --danger-color: #e74c3c;
    --danger-dark: #c0392b;
    /* Status chips readable on dark surfaces */
    --success-bg: #1e4531;
    --success-text: #a7e3bc;
    --danger-bg: #58262b;
    --danger-text: #f3b9be;
    --warning-bg: #4a3413;
    --warning-text: #f3c98b;
    --info-bg: #163a37;
    --info-text: #8fd9d0;
}

/*
 * Export parity: ONLY the html2canvas capture card stays light in
 * both themes, so exported PNGs are identical. Nothing else is exempt from
 * theming — the old rule also forced .stat-box/.area-item/.filter-controls
 * white, which is exactly what made dark mode "white boxes on black".
 */
.theme-independent {
    background-color: #ffffff !important;
    color: #333 !important;
    border-color: #333 !important;
}
.theme-independent * {
    color: #333;
}
/* Leaflet controls float over the map inside the export card but are
   EXCLUDED from the capture (data-html2canvas-ignore), so they must follow
   the app theme, not the card's forced-light palette. Without this, the
   `.theme-independent *` rule above wins on every control label/glyph
   (a direct rule on a descendant beats a color inherited from an
   !important parent), which made zoom/rotate/layer controls unreadable in
   dark mode ONLY on the area detail page — the maps page has no
   .theme-independent wrapper. */
.theme-independent .leaflet-control-container,
.theme-independent .leaflet-control-container * {
    color: var(--text-color);
}

/*
 * ======================
 * BUTTON COMPONENTS
 * ======================
 * A comprehensive button system with variants and sizes.
 * Usage: <button class="btn btn-primary">Primary Button</button>
 */
.btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn:hover {
  background-color: var(--primary-dark);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

/* Primary buttons - default style, used for main actions */
.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

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

/* Success buttons - used for confirmations, save actions */
.btn-success {
  background-color: var(--success-color);
  color: white;
}

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

/* Info buttons - used for information or neutral actions */
.btn-info {
  background-color: var(--info-color);
  color: white;
}

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

/* Warning buttons - used for actions requiring caution */
.btn-warning {
  background-color: var(--warning-color);
  color: white;
}

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

/* Danger buttons - used for destructive actions */
.btn-danger {
  background-color: var(--danger-color);
  color: white;
}

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

/* Secondary buttons - neutral outline, for navigation/tab-like actions that
   aren't the primary CTA on a page. Was previously undefined, so templates
   using btn-secondary silently fell back to .btn's primary-orange fill —
   every "secondary" action rendered as if it were the main action. */
.btn-secondary {
  background-color: transparent;
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--surface-2);
}

.btn-secondary.active {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Outline primary — same accent, lower visual weight than the filled
   .btn-primary. Use for a secondary option next to a primary CTA (e.g. an
   alternate download format), not as a general-purpose secondary button —
   that's .btn-secondary. */
.btn-outline-primary {
  background-color: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

.btn-outline-primary:hover {
  background-color: var(--primary-color);
  color: #fff;
}

/* Small button size variant */
.btn-sm {
  font-size: 0.875rem;
  padding: 0.4rem 0.8rem;
}

/* Anchors styled as buttons need these resets to match <button>. */
a.btn {
  display: inline-block;
  text-decoration: none;
  line-height: 1.2;
}

/* Loan-dashboard quick lend/return forms (was inline styles). */
.quick-forms {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    margin: 1rem 0;
}

.quick-forms > form {
    flex: 1;
    min-width: 280px;
}

/* Row of action buttons (e.g. Areas page header). */
.area-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center; /* a link and a <label> button sit on one line */
  margin: 0.5rem 0 1.25rem;
}

/* Fields outside .form-group (toolbars, inline forms, table cells): the
   look of the form fields, compact. :where() keeps the specificity at zero,
   so every rule written for a particular field still wins. */
:where(input[type="text"], input[type="date"], input[type="number"],
       input[type="search"], input[type="email"], input[type="password"],
       select, textarea) {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95rem;
  box-sizing: border-box;
  background-color: var(--surface-2);
  color: var(--text-color);
}

/* A row of fields and buttons: filters, quick forms, bulk actions. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  align-items: center;
}
/* A card that only holds toolbars. */
.card.compact {
  padding: 0.6em;
  margin-bottom: 1em;
}
.card.compact > * + *,
.card.compact details > * + * {
  margin-top: 0.6em;
}

/* A heading inside a page section (home, profile): smaller than the page h2. */
.section-title {
  font-size: 1.1rem;
  margin: 0.5rem 0;
}

/* Tables sorted by a click on a header (core/static/js/sortable-table.js). */
table.sortable thead th:not([data-nosort]) { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable thead th:not([data-nosort])::after { content: " \2195"; opacity: 0.45; }
table.sortable thead th[aria-sort="ascending"]::after { content: " \25B2"; opacity: 1; }
table.sortable thead th[aria-sort="descending"]::after { content: " \25BC"; opacity: 1; }
@media print { table.sortable thead th::after { content: "" !important; } }

/* The page you are on, in the shared area nav (_area_nav.html). */
.area-actions .btn-primary.active {
  background-color: var(--primary-dark);
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.6);
}

/* The page's own actions, right under the shared area nav: one block. */
.area-actions + .page-actions {
  margin-top: -0.75rem;
}

/* What the page is for, or a remark on it: quiet text under the heading. */
.page-intro {
  color: var(--muted-text);
  max-width: 65ch;
  margin: 0 0 1rem;
  line-height: 1.5;
}

/*
 * ======================
 * LAYOUT CONTAINERS
 * ======================
 * Reusable layout containers for consistent page structure.
 * Usage: <div class="flex-container">...</div>
 */
.flex-container {
  display: flex;
  gap: 20px;
}

.flex-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/*
 * ======================
 * CARD COMPONENTS
 * ======================
 * Standard card component for containing related content.
 * Usage: <div class="card">Card content</div>
 */
.card {
  background-color: var(--card-background);
  color: var(--card-text-color);
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

/*
 * ======================
 * STATUS INDICATORS
 * ======================
 * Visual indicators for showing status (success/error).
 * Usage: <div class="status-indicator checked">Status text</div>
 */
.status-indicator {
  padding: 8px 15px;
  border-radius: 4px;
  margin-right: 15px;
  font-weight: bold;
}

.status-indicator.checked {
  background-color: var(--success-bg, #d4edda);
  color: var(--success-text, #155724);
}

.status-indicator.unchecked {
  background-color: var(--danger-bg, #f8d7da);
  color: var(--danger-text, #721c24);
}

/*
 * ======================
 * CONTROL CONTAINERS
 * ======================
 * Containers for buttons and form controls with proper spacing.
 * Usage: <div class="controls-container">...buttons...</div>
 */
.controls-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 15px 0;
}

/*
 * ======================
 * BASIC ELEMENT STYLING
 * ======================
 * Core styling for body and typography elements.
 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--background-color);
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Base link color. Without this, any anchor that doesn't opt into a
   component class (nav, buttons, stat-box…) falls back to the browser's
   default blue/purple visited color, which fights the orange accent. */
a {
  color: var(--primary-color);
}

a:hover {
  color: var(--primary-dark);
}

h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--text-color);
  letter-spacing: 0.01em;
}

/* Page titles say where you are; kept small so the content starts high. */
h1 {
  margin-bottom: 0.75rem;
  font-size: 1.6rem;
  font-weight: 700;
}

/* Area/user codes, counters, coordinates: monospaced like a registry
   ledger, ties the numeric data to the S-13-B / cadastral subject matter. */
.stat-value,
.stats-number,
.area-code-cell a {
  font-family: var(--font-mono);
}

/*
 * ======================
 * NAVIGATION COMPONENTS
 * ======================
 * Navigation bar and responsive menu.
 * Usage: <nav>...</nav>
 */
nav {
  background-color: var(--nav-background);
  box-shadow: var(--nav-shadow);
  padding: 0.8rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1001;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.nav-container {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* Wordmark + the app's own favicon (deliberately full-color, not tinted to
   --primary-color) — the one place the palette allows a brighter accent
   than the rest of the muted UI, same way a logo usually reads louder than
   its surrounding chrome. */
.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--text-color);
  text-decoration: none;
  flex-shrink: 0;
}

.nav-brand img {
  display: block;
  border-radius: 5px;
}

nav ul {
  display: flex;
  list-style: none;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  flex: 1;
  margin: 0;
}

nav ul li {
  position: relative;
}

nav ul li a {
  color: var(--text-color);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: inline-block;
}

nav ul li a:hover {
  background-color: var(--hover-color);
}

nav ul li a.active {
  color: var(--primary-color);
  font-weight: 600;
}

/* Nav link icons — quiet, so the label stays the anchor. */
.nav-icon {
  margin-right: 0.45em;
  font-size: 0.85em;
  opacity: 0.75;
}

/*
 * ======================
 * THEME TOGGLE SWITCH
 * ======================
 * Dark/light theme toggle component.
 * Usage: <div class="theme-switch-wrapper">...</div>
 */
/* Lang toggle owns margin-left:auto so it + the theme switch (next in
   the DOM) both ride the right edge, lang first. */
.nav-lang {
  margin-left: auto;
}

/* Overlapping flag stack: both flags shown, current in front + full
   opacity, other greyed and tucked behind. Clicking swaps which is active. */
.flag-stack {
  position: relative;
  display: inline-block;
  width: 34px;   /* 24px flag + 10px reveal of the back flag */
  height: 16px;
  cursor: pointer;
}

.nav-lang .flag-icon {
  position: absolute;
  top: 0;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--border-color);
  transition: opacity 0.15s ease, filter 0.15s ease, left 0.15s ease;
}

/* Back flag: peeks out on the right, greyed. Front flag: left, full colour. */
.nav-lang .flag-icon {
  left: 10px;
  z-index: 1;
  opacity: 0.45;
  filter: grayscale(0.85);
}

.nav-lang .flag-icon.is-active {
  left: 0;
  z-index: 2;
  opacity: 1;
  filter: none;
}

/* Hover/focus: the flag a click switches to slides out in full colour. */
.flag-stack:hover .flag-icon:not(.is-active),
.flag-stack:focus-visible .flag-icon:not(.is-active) {
  left: 28px;
  opacity: 1;
  filter: none;
}

nav ul li a.flag-stack:hover {
  background-color: transparent;
}

.theme-switch-wrapper {
  display: flex;
  align-items: center;
}

.theme-switch {
  display: inline-block;
  height: 24px;
  position: relative;
  width: 48px;
}

.theme-switch input {
  display: none;
}

.slider {
  background-color: var(--toggle-bg);
  bottom: 0;
  cursor: pointer;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transition: .4s;
  border-radius: 34px;
}

.slider-icon {
  background-color: var(--toggle-circle);
  bottom: 2px;
  top: 1px;
  left: 3px;
  position: absolute;
  transition: .4s;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-color);
  line-height: 1;
}

/* Theme switch: sun while light, moon while dark (the switch is checked). */
.theme-switch .fa-moon,
.theme-switch input:checked + .slider .fa-sun { display: none; }
.theme-switch input:checked + .slider .fa-moon { display: inline; }

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider .slider-icon {
  transform: translateX(24px);
}

/*
 * ======================
 * LOADING SPINNER
 * ======================
 * Animated loading indicator with glassmorphism effect.
 * Usage: <div class="loading-spinner">
 *          <div class="spinner-circle outer-circle"></div>
 *          <div class="spinner-circle inner-circle"></div>
 *          <div class="spinner-text">Loading</div>
 *        </div>
 */
.loading-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner.hidden {
  display: none;
}

.loading-spinner .spinner-circle {
  position: absolute;
  width: 80%;
  height: 80%;
  border: 8px solid transparent;
  border-top-color: var(--primary-color, #3498db);
  border-radius: 50%;
  will-change: transform, opacity, border-top-color;
}

.loading-spinner .spinner-circle.outer-circle {
  animation: spinOuter 2s linear infinite, colorFadeOuter 4s linear infinite,
    opacityFade 4s ease-in-out infinite;
}

.loading-spinner .spinner-circle.inner-circle {
  width: 60%;
  height: 60%;
  animation: spinInner 1.5s linear infinite, colorFadeInner 3s linear infinite,
    opacityFade 3s ease-in-out infinite;
}

.loading-spinner .spinner-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  color: var(--text-color, #555);
  font-weight: bold;
  text-align: center;
}

/* Animation keyframes */
@keyframes spinOuter {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes spinInner {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(-180deg) scale(1.05); }
  100% { transform: rotate(-360deg) scale(1); }
}

@keyframes colorFadeOuter {
  0% { border-top-color: var(--primary-color, #3498db); }
  25% { border-top-color: #9b59b6; }
  50% { border-top-color: var(--danger-color, #e74c3c); }
  75% { border-top-color: var(--warning-color, #f1c40f); }
  100% { border-top-color: var(--primary-color, #3498db); }
}

@keyframes colorFadeInner {
  0% { border-top-color: var(--danger-color, #e74c3c); }
  25% { border-top-color: var(--warning-color, #f1c40f); }
  50% { border-top-color: var(--success-color, #2ecc71); }
  75% { border-top-color: var(--primary-color, #3498db); }
  100% { border-top-color: var(--danger-color, #e74c3c); }
}

@keyframes opacityFade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/*
 * ======================
 * RESPONSIVE NAVIGATION
 * ======================
 * Mobile menu with hamburger icon for small screens.
 */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: content-box;
  width: 30px;
  height: 21px;
  /* Padding grows the tap target to ~46px without changing the icon. */
  padding: 12px 8px;
  border: 0;
  background: none;
  cursor: pointer;
  z-index: 1001;
}

.hamburger span {
  display: block;
  height: 3px;
  width: 100%;
  background-color: var(--text-color);
  border-radius: 3px;
  transition: all 0.3s ease;
}

/* Main content container */
.container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

/* Map benefits from more width than a text page does; opt in per-page via
   {% block container_class %} in base.html (see map.html). */
.container.container-wide {
  max-width: 1600px;
}

/*
 * ======================
 * STAT CHIPS (global: areas list, loan dashboard, home)
 * ======================
 * Usage: <div class="area-stats"><div class="stat-box">
 *          <span class="stat-label">…</span><span class="stat-value">…</span>
 */
.area-stats {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 20px;
  gap: 15px;
}

.stat-box {
  background-color: var(--surface);
  padding: 10px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.stat-label {
  font-weight: bold;
  margin-right: 5px;
}

/* Some stat chips are links (admin dashboard); keep the box look. */
a.stat-box {
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

a.stat-box:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

/*
 * ======================
 * LOGGED-OUT HERO
 * ======================
 * Signed-out visitors got a bare h1 + link on an empty page — no context on
 * what the tool even does. The background is a topographic contour pattern
 * (inline SVG, no network fetch) instead of a stock gradient: same visual
 * language as the app's own map pages, not decoration bolted on.
 */
.hero-landing {
  max-width: 42em;
  padding: 3.5rem 2rem;
  margin: 3rem auto;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  background-color: var(--surface);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.hero-landing h1 {
  margin-bottom: 0.6rem;
  font-size: 2.4rem;
}

.hero-landing .btn {
  margin: 0 0.25rem;
}

/* The Prague obvod outline above the landing headline (real map data,
   same <defs> path the row minimaps use). */
.hero-landing .hero-map {
  width: 140px;
  height: 140px;
  margin-bottom: 0.5rem;
}
.hero-landing .hero-map use {
  fill: var(--primary-color);
  fill-opacity: 0.1;
  stroke: var(--primary-color);
  stroke-width: 1;
  stroke-linejoin: round;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--muted-text);
  margin-bottom: 1.5rem;
}

/*
 * ======================
 * HOME PAGE TILES
 * ======================
 * Landing-page link cards (index.html).
 */
.home-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 15px;
  margin-top: 1rem;
}

.home-tile {
  text-decoration: none;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.home-tile:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.home-tile h3 {
  margin: 0 0 0.4em;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

/* Unified icon treatment: white glyph on a blue badge, matching the
   loan-dashboard button look the owner asked to standardize on. */
.tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2em;
  height: 2em;
  border-radius: 8px;
  background-color: var(--primary-color);
  color: #fff;
  font-size: 1.1em;
  flex-shrink: 0;
}

.home-tile p {
  margin: 0;
  font-size: 0.9em;
  opacity: 0.75;
}

/*
 * ======================
 * MAP THEMING
 * ======================
 * The tile-less map pane follows the page background (no white flash while
 * tiles load). Dark mode dims tiles with a mild gray filter — deliberately
 * NOT an invert/night style, which would falsify the red/green/amber loan
 * colors and mapy.cz cartography. The export capture card is exempt so
 * exported PNGs stay true-color (`.exporting` is set during html2canvas).
 */
#map,
.leaflet-container {
  background-color: var(--background-color) !important;
}

[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(0.7) contrast(1.05) saturate(0.85);
}

[data-theme="dark"] .exporting .leaflet-tile-pane {
  filter: none;
}

/* Satellite imagery is already dark; the OSM-dimming filter above
   turns it near-black and buries the controls. Skip it when satellite is the
   active base layer (map.html toggles .satellite-active on baselayerchange). */
[data-theme="dark"] #map.satellite-active .leaflet-tile-pane {
  filter: none;
}

/* Lift the corner controls off dark imagery so they stay legible. */
[data-theme="dark"] .leaflet-bar,
[data-theme="dark"] ._customControl,
[data-theme="dark"] .leaflet-control-street-search,
[data-theme="dark"] .leaflet-control-layers,
[data-theme="dark"] .area-select-control button {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

/* !important needed here: leaflet.css loads AFTER this stylesheet (map.html
   includes it in extra_css), so its same-specificity `background: white;
   color: #333;` on .leaflet-popup-content-wrapper/.leaflet-popup-tip and
   .leaflet-bar a would otherwise win on source order alone — the popup and
   +/- zoom buttons stayed permanently light regardless of theme. */
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip,
[data-theme="dark"] .leaflet-control-layers,
[data-theme="dark"] .leaflet-bar a {
  background-color: var(--surface) !important;
  color: var(--text-color) !important;
}

/* Vendor leaflet.css only styles the resting state — :hover/:focus and
   .leaflet-disabled fall back to its own #f4f4f4/#ccc, so every themed
   control (zoom, layers, street search) flashed light grey on hover. Same
   for the popup close button and the resting border-bottom. */
[data-theme="dark"] .leaflet-bar a {
  border-bottom-color: var(--border-color);
}
[data-theme="dark"] .leaflet-bar a:hover,
[data-theme="dark"] .leaflet-bar a:focus {
  background-color: var(--hover-color) !important;
}
[data-theme="dark"] .leaflet-bar a.leaflet-disabled {
  background-color: var(--surface-2) !important;
  color: var(--muted-text) !important;
}
[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button {
  color: var(--muted-text);
}
[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:hover,
[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:focus {
  color: var(--text-color);
}

/* The layers toggle is a black glyph baked into a vendor image on a white
   button: inverting the whole button in dark mode gives a dark button with
   a light glyph without touching the vendored assets. (The area-select
   button used to be in this list — it now runs on surface tokens and
   inverts only its glyph layer; see leaflet-area-selection.css.) */
[data-theme="dark"] .leaflet-control-layers-toggle {
  filter: invert(1) hue-rotate(180deg);
}

/* Compass control (map-bearing.js): a .leaflet-bar anchor holding an inline
   SVG needle. The dark-mode .leaflet-bar a rule already themes the button;
   the needle's south half uses currentColor so it follows the text colour. */
.map-compass-dial {
  touch-action: none;
  cursor: ew-resize;
}
.map-compass-dial svg {
  display: block;
  width: 24px;
  height: 24px;
  margin: 3px;
  pointer-events: none;
}
/* Two-finger twist is on: ring the button instead of recolouring it. */
.map-compass-dial.is-on {
  box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* The expanded layer-list panel (base-layer radios, overlay checkboxes) —
   color-scheme tells the browser to render those native form controls with
   dark-appropriate chrome instead of their light-mode default; accent-color
   pins the checked state to the app's own blue instead of default OS blue. */
[data-theme="dark"] .leaflet-control-layers-expanded {
  color-scheme: dark;
}
[data-theme="dark"] .leaflet-control-layers-selector {
  accent-color: var(--primary-color);
}

[data-theme="dark"] .loading-spinner {
  background: rgba(0, 0, 0, 0.35);
}

/*
 * ======================
 * RESPONSIVE ADJUSTMENTS
 * ======================
 * Mobile-specific styling for smaller screens.
 */
@media (max-width: 768px) {
  .hamburger {
    display: flex;
  }

  .nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
  }

  nav ul {
    position: fixed;
    flex-direction: column;
    background-color: var(--nav-background);
    top: 0;
    right: -100%;
    width: 70%;
    height: 100vh;
    height: 100dvh;
    padding: 80px 20px 30px;
    transition: right 0.3s ease;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    align-items: flex-start;
  }

  nav ul.active {
    right: 0;
  }

  nav ul li {
    width: 100%;
    margin-bottom: 15px;
  }

  nav ul li a {
    display: block;
    padding: 0.7rem 0;
    width: 100%;
  }

  .nav-lang {
    margin-left: 0;
  }

  .theme-switch-wrapper {
    margin-left: 0;
    margin-top: 20px;
    width: 100%;
  }

  /* Hamburger animation */
  .hamburger.active span:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
  }

  .hamburger.active span:nth-child(2) {
    opacity: 0;
  }

  .hamburger.active span:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
  }

  /* Overlay when menu is open */
  .menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .menu-overlay.active {
    display: block;
  }
}

/*
 * ======================
 * DATA TABLES
 * ======================
 * Shared styling for tabular data (loan dashboard, loan history, user list).
 */
.loan-dashboard-table,
.loan-history-table,
.users-table,
.area-table-list {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  background-color: var(--surface);
  box-shadow: var(--nav-shadow);
  border-radius: 6px;
  overflow: hidden;
}

.loan-dashboard-table th,
.loan-history-table th,
.users-table th,
.area-table-list th {
  background-color: var(--primary-color);
  color: #fff;
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.loan-dashboard-table td,
.loan-history-table td,
.users-table td,
.area-table-list td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-color);
}

.loan-dashboard-table tbody tr:nth-child(even),
.loan-history-table tbody tr:nth-child(even),
.users-table tbody tr:nth-child(even),
.area-table-list tbody tr:nth-child(even) {
  background-color: var(--surface-2);
}

.loan-dashboard-table tbody tr:hover,
.loan-history-table tbody tr:hover,
.users-table tbody tr:hover,
.area-table-list tbody tr:hover {
  background-color: var(--hover-color);
}

.loan-dashboard-table tr.overdue td {
  background-color: var(--danger-bg);
  color: var(--danger-text);
}

/* Inline field validation: shake + red ring, no blocking alert. */
@keyframes field-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
.input-invalid {
  border: 1px solid var(--danger-text, #d9534f) !important;
  box-shadow: 0 0 0 2px var(--danger-bg, rgba(217, 83, 79, 0.25));
  animation: field-shake 0.35s ease;
}
.field-hint {
  color: var(--danger-text, #d9534f);
  font-size: 0.8rem;
}

/* Status badges: the ONE definition for every page (areas list, area
   detail, loan dashboard). Previously this rule existed three times —
   here, in area.css, and in a page-local <style> block inside areas.html —
   each with different hardcoded hex, and five of the modifier classes used
   in templates (reviewed/needs-review/available/total-loans/held) had no
   definition anywhere at all. Don't add a fourth; add a modifier here. */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge.on-loan,
.status-badge.overdue {
  background-color: var(--danger-bg);
  color: var(--danger-text);
}
.status-badge.fresh,
.status-badge.reviewed,
.status-badge.checked {
  background-color: var(--success-bg);
  color: var(--success-text);
}
.status-badge.needs-review,
.status-badge.available {
  background-color: var(--warning-bg);
  color: var(--warning-text);
}
.status-badge.unread {
  background-color: var(--info-bg);
  color: var(--info-text);
}
.status-badge.unchecked {
  background-color: var(--surface-2);
  color: var(--muted-text);
  border: 1px solid var(--border-color);
}
.status-badge.total-loans {
  background-color: var(--surface-2);
  color: var(--text-color);
}
.status-badge.held {
  background-color: var(--muted-text);
  color: var(--surface);
}
.status-badge.outlier {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px dashed var(--danger-text);
}

/*
 * ======================
 * FORMS (global)
 * ======================
 * Mirrors the user-form styling so any page that uses .form-group looks the
 * same (users.css covers the auth pages; this covers the rest, e.g. /areas).
 */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group textarea,
.form-group select,
.form-control {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
  background-color: var(--surface-2);
  color: var(--text-color);
}
.form-group textarea {
  min-height: 6rem;
  resize: vertical;
}

/* Browser default placeholder color is tuned for light backgrounds
   (near-black at low opacity) — on dark --surface-2 inputs it was nearly
   invisible. Applies to every input/textarea, not just .form-group ones
   (e.g. the notes textarea, borrower/hold-note fields). */
input::placeholder,
textarea::placeholder {
  color: var(--muted-text);
  opacity: 1;
}
.form-actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.5rem;
}

/* ---- Nav dropdowns (moved from base.html inline <style>) ---- */
.dropdown {
    position: relative;
}

.dropdown-toggle::after {
    content: '▼';
    font-size: 10px;
    margin-left: 5px;
}

.dropdown-menu {
    display: none;
    position: absolute;
    background-color: var(--nav-background);
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    border-radius: 4px;
}

.dropdown-menu li {
    width: 100%;
}

.dropdown-menu a {
    color: var(--text-color);
    padding: 8px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-menu a:hover {
    background-color: var(--hover-color);
}

@media (max-width: 768px) {
    .dropdown-menu {
        position: static;
        box-shadow: none;
        width: 100%;
        margin-top: 10px;
        margin-bottom: 10px;
        padding-left: 15px;
    }
}

/* ---- Global error toasts (moved from base.html inline <style>/JS) ---- */
@keyframes toast-slide-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-slide-out {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

.global-error-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--danger-color);
    color: white;
    padding: 12px 20px;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    max-width: 400px;
    font-size: 14px;
    line-height: 1.4;
    animation: toast-slide-in 0.3s ease-out;
    cursor: pointer;
}

/* Warning uses the theme's warning surface pair — white-on-yellow was
   unreadable. */
.global-error-message.warning {
    background-color: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid var(--warning-color);
}

.global-error-message.success {
    background-color: var(--success-color);
}

.global-error-message:hover {
    opacity: 0.9;
}

.global-error-message.closing {
    animation: toast-slide-out 0.3s ease-in;
}

/* ---- Modal dialogs (moved from users.css) — shared by the users delete
   modal and the appConfirm() helper in base.js. ---- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--surface);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 8px;
    max-width: 500px;
    width: 100%;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Row minimaps — obvod outline + area shape, generated by app/areas/minimap.py. */
.area-minimap {
    width: 1.6em;
    height: 1.6em;
    vertical-align: middle;
    margin-right: 0.35em;
}
.area-minimap .mini-dot {
    fill: var(--primary-color);
    opacity: 0.85;
}
.area-minimap use {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 1.5;
    stroke-linejoin: round;
}
.area-minimap .mini-area {
    fill: var(--primary-color);
    stroke: var(--primary-color);
    stroke-width: 1.5;
    stroke-linejoin: round;
}

/*
 * ======================
 * UTILITY CLASSES (database_management.html)
 * ======================
 * That page's markup was written assuming Bootstrap 5 (.row/.col-md-6,
 * .card-header/.card-body, .alert, .form-check, data-bs-toggle accordions…)
 * but this app never loads Bootstrap — every one of those classes was
 * dead weight. This is the minimum real set to back them with the app's own
 * tokens, scoped to what that page actually uses. Don't grow this into a
 * parallel utility framework — new pages should reach for .card/.btn/
 * .form-group like the rest of the app, not these.
 */
.row { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0 -0.5rem; }
.row > [class*="col-"] { flex: 1 1 300px; padding: 0 0.5rem; }
.card-header {
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}
.card-body { padding-top: 0; }
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  margin: 0.75rem 0;
}
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-color); }
.alert-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-color); }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-color); }
.form-check { margin-bottom: 0.5rem; }
.form-check-input { margin-right: 0.5rem; }
.form-label { display: block; margin-bottom: 0.3rem; font-weight: 600; }
.text-muted { color: var(--muted-text); }
.text-success { color: var(--success-text); }
.d-flex { display: flex; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.mt-2 { margin-top: 0.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1.5rem; }
.small { font-size: 0.85em; }
.mx-1 { margin-left: 0.4em; margin-right: 0.4em; }
.field-narrow { max-width: 14em; }
.field-narrow-wide { max-width: 16em; }
.scroll-x { overflow-x: auto; }
.pointer { cursor: pointer; }
.gap-sm { gap: 0.4rem; }

/* Notice over the page when map tiles are rate limited (area_detail.html). */
.tile-limit-notice {
  background: var(--warning-bg);
  border: 1px solid var(--warning-color);
  border-radius: var(--radius);
  padding: 12px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--warning-text);
}
.tile-limit-notice > div { flex: 1; }
.tile-limit-notice .tile-limit-icon { font-size: 18px; }
.tile-limit-notice button {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  color: var(--warning-text);
}
.table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
}
.table th, .table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}
.table-sm th, .table-sm td { padding: 0.3rem 0.5rem; }
.table-striped tbody tr:nth-child(even) { background: var(--surface-2); }
.table-responsive { overflow-x: auto; }
.schema-table-toggle {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem 0;
  color: var(--text-color);
}

/* Admin edit / cancel of a loan record (_loan_history.html): the edit form
   opens as a small panel over the table instead of stretching its column. */
.loan-actions { white-space: nowrap; position: relative; }
.loan-edit { display: inline-block; }
.loan-edit > summary { list-style: none; cursor: pointer; }
.loan-edit > summary::-webkit-details-marker { display: none; }
.loan-edit[open] .loan-edit-form {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 20;
    width: min(20rem, 85vw);
    display: grid;
    gap: .5rem;
    padding: .75rem;
    white-space: normal;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}
.loan-edit-form label { display: flex; flex-direction: column; gap: .15rem; font-size: .85rem; }
.loan-edit-form small { color: var(--muted-text); }

/* htmx's request indicator. htmx would inject these as an inline <style>
   (includeIndicatorStyles is off in base.html): html2canvas copies inline
   styles into its capture frame, and Firefox/WebKit drop the CSP nonce on
   the copy, so the export logged a CSP violation there. */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }

/* The hall on every map (maps/static/js/hall-marker.js). */
/* With .leaflet-marker-icon: leaflet.css loads later and sets display:block,
   which left the glyph in the top left corner. */
.leaflet-marker-icon.map-pin-hall {
    /* border-box: Leaflet sizes and anchors the icon by iconSize, border included. */
    box-sizing: border-box;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    line-height: 1;
    /* The blue of jw.org. */
    background-color: #4a6da7;
    border: 1.5px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Area codes on the series maps (areas/static/js/series-map.js): plain text
   with a light halo, so the outline under it stays visible. */
.series-label div {
    font: bold 13px/16px sans-serif;
    color: #111;
    text-align: center;
    white-space: nowrap;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.series-label-faint div {
    font-weight: normal;
    font-size: 11px;
    color: #333;
}
.series-labels-off .series-label-faint {
    display: none;
}
