/* ==========================================================================
   Zones des Annexes Administratives
   Palette : encre ardoise + papier parchemin + rouge de cachet + vert de validation
   ========================================================================== */

:root {
  --ink: #1E2A2E;
  --ink-soft: #47585D;
  --paper: #EFECE2;
  --panel: #F8F6EF;
  --line: #D9D2BF;
  --line-soft: #E6E1D2;
  --stamp: #8B2E2E;
  --stamp-dark: #6E2222;
  --seal: #3E6259;
  --seal-dark: #2E4A43;
  --white: #FFFFFF;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

/* ---------- Masthead ---------- */

.masthead {
  background: var(--ink);
  color: var(--paper);
  border-bottom: 4px double var(--stamp);
}

.masthead-inner {
  max-width: none;
  margin: 0;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.mark-svg {
  width: 34px;
  height: 34px;
  color: var(--stamp);
}

.masthead-text { flex: 1; }

.masthead-eyebrow {
  margin: 0 0 2px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #B9AE93;
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: 0.01em;
}

.masthead-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #C9C0A6;
}

.masthead-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--seal);
  display: inline-block;
}

/* ---------- Layout ---------- */

.layout {
  display: flex;
  height: calc(100vh - 55px);
}

.sidebar {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--ink);
  color: var(--paper);
  padding: 1px 7px;
  border-radius: 10px;
}

/* ---------- Form ---------- */

.form-annexe {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-annexe label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 500;
}

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

.form-annexe input, .form-annexe select {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--white);
  color: var(--ink);
  width: 100%;
}

.form-annexe input:focus, .form-annexe select:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px rgba(62, 98, 89, 0.12);
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  padding: 9px 14px;
  border-radius: 3px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 38px;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--seal);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--seal-dark); }

.btn-outline {
  background: transparent;
  border-color: var(--ink);
  color: var(--ink);
}
.btn-outline:hover:not(:disabled) { background: var(--ink); color: var(--paper); }

.btn-danger {
  background: transparent;
  border-color: var(--stamp);
  color: var(--stamp);
}
.btn-danger:hover:not(:disabled) { background: var(--stamp); color: var(--white); }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); }

/* ---------- Annexe list (dossier cards) ---------- */

.panel-list { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.annexe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.annexe-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 3px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.annexe-card:hover { border-left-color: var(--seal); background: #FCFBF7; }

.annexe-card.is-active {
  border-left-color: var(--stamp);
  background: #FBF3F1;
}

.annexe-seal {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--line);
}

.annexe-seal.drawn {
  border: 1.5px solid var(--seal);
  background: var(--seal);
}
.annexe-seal.drawn::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--white);
}

.annexe-seal.undrawn {
  border-style: dashed;
  border-color: var(--ink-soft);
}

.annexe-card-body { flex: 1; min-width: 0; }

.annexe-card-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.annexe-card-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.annexe-card-delete {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 3px;
}
.annexe-card-delete:hover { color: var(--stamp); background: #F1E4E1; }

.empty-state {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-style: italic;
  padding: 12px 4px;
}

/* ---------- Map ---------- */

.map-wrap {
  position: relative;
  flex: 1;
}

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

.map-hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 42, 46, 0.92);
  color: var(--paper);
  font-size: 12.5px;
  padding: 8px 16px;
  border-radius: 4px;
  z-index: 500;
  pointer-events: none;
}

.map-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--stamp);
  border-radius: 4px;
  padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(30, 42, 46, 0.14);
  max-width: 420px;
}

.toolbar-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.toolbar-label strong { color: var(--ink); font-family: var(--font-display); }

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- Leaflet overrides ---------- */

.leaflet-popup-content-wrapper {
  border-radius: 4px;
  font-family: var(--font-body);
}
.leaflet-popup-content { font-size: 13px; margin: 10px 12px; }
.leaflet-popup-content strong { font-family: var(--font-display); }

/* ---------- Scrollbars (subtle) ---------- */

.sidebar::-webkit-scrollbar, .annexe-list::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .annexe-list::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .map-wrap { height: 55vh; }
}

/* ---------- Masthead user / auth ---------- */

.masthead-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #C9C0A6;
}

.masthead-user .btn-ghost, .masthead-user .btn-outline {
  border-color: #6B6350;
  color: var(--paper);
}
.masthead-user .btn-ghost:hover, .masthead-user .btn-outline:hover {
  border-color: var(--stamp);
  background: rgba(139, 46, 46, 0.18);
  color: var(--paper);
}

.btn-sm { padding: 6px 10px; font-size: 11.5px; min-height: 32px; }

/* ---------- Login page ---------- */

.login-body {
  height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  background-image: radial-gradient(circle at 20% 20%, rgba(139,46,46,0.10), transparent 45%),
                     radial-gradient(circle at 80% 80%, rgba(62,98,89,0.12), transparent 45%);
  font-family: var(--font-body);
}

.login-card {
  width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px double var(--stamp);
  border-radius: 4px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  text-align: center;
}

.mark-svg-wrap { color: var(--stamp); margin-bottom: 10px; }
.mark-svg-wrap .mark-svg { width: 40px; height: 40px; }

.login-eyebrow {
  color: var(--ink-soft) !important;
  text-align: center;
}

.login-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  margin: 4px 0 22px 0;
  color: var(--ink);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 500;
}

.login-form input {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 11px 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--white);
  color: var(--ink);
}

.btn-block { width: 100%; margin-top: 6px; padding: 11px; }

.login-error {
  background: #FBF3F1;
  border: 1px solid var(--stamp);
  color: var(--stamp-dark);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: 3px;
  margin-bottom: 16px;
}

/* ---------- Admin: list toolbar + card actions ---------- */

.list-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.annexe-card-admin { flex-direction: row; align-items: flex-start; cursor: default; }
.annexe-card-admin:hover { border-left-color: var(--line); background: var(--white); }

.annexe-card-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--seal);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:disabled { color: var(--line); cursor: not-allowed; text-decoration: none; }
.link-btn-danger { color: var(--stamp); }

/* ---------- Agent layout (no sidebar) ---------- */

.layout-agent { display: block; height: calc(100vh - 55px); }
.layout-agent .map-wrap { height: 100%; }

/* ---------- Sidebar drawer toggle (mobile, admin) ---------- */

.btn-menu-toggle { display: none; }

/* ---------- Phone breakpoint ---------- */

@media (max-width: 640px) {

  /* Masthead: compact, wraps cleanly */
  .masthead-inner { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .mark-svg { width: 26px; height: 26px; }
  .masthead-eyebrow { display: none; }
  .masthead h1 { font-size: 15px; line-height: 1.25; }
  .masthead-user { font-size: 11px; gap: 8px; }
  .masthead-status { font-size: 11px; }

  .btn { min-height: 44px; font-size: 13px; }
  .btn-sm { min-height: 34px; padding: 7px 10px; }

  .form-row { grid-template-columns: 1fr; }

  /* Sidebar becomes a full-height slide-in drawer, map stays primary */
  .btn-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  body.has-drawer .layout { position: relative; }
  body.has-drawer .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 88vw;
    max-width: 360px;
    z-index: 1200;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    max-height: none;
    border-right: 1px solid var(--line);
  }
  body.has-drawer.sidebar-open .sidebar { transform: translateX(0); }
  body.has-drawer .map-wrap { height: calc(100vh - 55px); }

  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(20, 28, 30, 0.45);
    z-index: 1100;
  }
  body.has-drawer.sidebar-open .sidebar-backdrop { display: block; }

  /* Agent map toolbar becomes a bottom sheet — easier thumb reach */
  .map-toolbar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: none;
    border-radius: 10px 10px 0 0;
    border-left: none;
    border-top: 3px solid var(--stamp);
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar-actions .btn { width: 100%; }

  .map-hint {
    left: 12px; right: 12px; bottom: 12px;
    transform: none;
    max-width: none;
    text-align: center;
    font-size: 12px;
  }

  /* Larger touch targets for Leaflet's own drawing toolbar */
  .leaflet-draw-toolbar a {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
  }
  .leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 36px !important; }
}
