/* ============================
   Territory Manager SH6
   (Scoped) Responsive + Dark/Light
   ============================ */

html, body {
  height: 100%;
  margin: 0;
}

/* IMPORTANT :
   On NE TOUCHE PAS au <main> global du site.
   Tout est scopé dans .tm-root / .tm-main.
*/

.tm-root{
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;

  --canvas-bg: #ffffff;
  --grid-line: #e5e7eb;
  --shadow: 0 10px 30px rgba(2,6,23,.10);

  --cell: 28px;

  --radius: 14px;
  --radius-sm: 10px;
  --pad: 12px;

  display: flex;
  width: 100%;
  height: calc(100vh - var(--header-height, 72px));
  max-height: calc(100vh - var(--header-height, 72px));
  background: var(--bg);
  color: var(--text);

  overflow: hidden; /* CRITIQUE : pas de scroll page */
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0; /* CRITIQUE : évite les débordements */
}

html[data-theme="dark"] .tm-root{
  --bg: #0b0c0d;
  --surface: #0f141b;
  --surface-2: #111a23;
  --text: #e7eef6;
  --muted: #9aa6b2;
  --line: #1e2a36;

  --canvas-bg: #f8fafc;
  --grid-line: #d6dde6;
  --shadow: 0 14px 40px rgba(0,0,0,.45);
}

@media (prefers-color-scheme: dark){
  html:not([data-theme]) .tm-root{
    --bg: #0b0c0d;
    --surface: #0f141b;
    --surface-2: #111a23;
    --text: #e7eef6;
    --muted: #9aa6b2;
    --line: #1e2a36;

    --canvas-bg: #f8fafc;
    --grid-line: #d6dde6;
    --shadow: 0 14px 40px rgba(0,0,0,.45);
  }
}

/* Sidebar */
.tm-sidebar {
  width: 320px;
  min-width: 320px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-right: 1px solid var(--line);
}

.tm-side-head{
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap:10px;
  margin-bottom: 12px;
}

.tm-side-title{ font-weight: 700; font-size: 15px; }
.tm-side-sub{ color: var(--muted); font-size: 12px; margin-top: 2px; }

.tm-field{ margin: 12px 0; }
.tm-label{ display:block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.tm-input{
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.tm-input:focus{
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96,165,250,.25);
}

.tm-statline{ color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.tm-dot{ margin: 0 6px; }

.tm-memberlist{
  display:flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.tm-member{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.tm-member-name{ font-weight: 650; font-size: 13px; }
.tm-member-sub{ color: var(--muted); font-size: 12px; margin-top: 2px; }

.tm-pill{
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.tm-member.assigned{
  background-color: #00ff3b30 !important;
  border-left: 4px solid #10b981;
}

.tm-muted{ color: var(--muted); font-size: 13px; }

/* Main */
.tm-main{
  flex:1;
  display:flex;
  flex-direction: column;
  min-width: 0;
  min-height hooked to flex sizing */
  min-height: 0;
  height: 100%;
}

/* Topbar */
.tm-topbar{
  flex: 0 0 auto;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap:10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.tm-top-left{ display:flex; align-items:center; gap:10px; }
.tm-title{ font-weight: 800; font-size: 16px; }
.tm-subtitle{ color: var(--muted); font-size: 12px; margin-top: 2px; }

.tm-top-actions{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tm-btn{
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  font-size: 13px;
}

.tm-btn:hover{ filter: brightness(0.98); }

.tm-btn-primary{ background:#2563eb; border-color:#2563eb; color:#fff; }
.tm-btn-danger{ background:#b91c1c; border-color:#b91c1c; color:#fff; }
.tm-btn-ghost{ background: var(--surface-2); }

.tm-btn.is-active{
  outline: 3px solid rgba(245,158,11,.25);
  border-color: #f59e0b;
}

/* Toolbar */
.tm-toolbar{
  flex: 0 0 auto;
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap:10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tm-tools{
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tm-tool{
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}

.tm-tool[aria-pressed="true"]{
  outline: 3px solid rgba(37,99,235,.25);
  border-color: #2563eb;
}

.tm-toolbar-right{
  display:flex;
  align-items:center;
  gap: 10px;
  white-space: nowrap;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tm-label-inline{ color: var(--muted); font-size: 12px; }

.tm-select{
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.tm-zoom{
  display:flex;
  align-items:center;
  gap: 8px;
}

.tm-range{
  width: 160px;
}

/* =========================
   CANVAS & VIEWPORT
========================= */

/* Le bloc carte doit prendre TOUT l'espace restant, sans pousser la page */
.tm-canvas-wrap{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;        /* CRITIQUE en flex */
  overflow: hidden;     /* pas de scroll ici */
  background: var(--bg);
}

/* Seul conteneur scrollable */
.tm-canvas-viewport{
  position: absolute;
  inset: 0;
  overflow: auto;       /* ✅ scroll AU NIVEAU de la carte */
  -webkit-overflow-scrolling: touch;
  padding: 14px;        /* joli contour autour de la carte */
}

/* Stage = contenu, pas scrollable */
.tm-stage{
  position: relative;
  transform-origin: 0 0;
  background: var(--canvas-bg);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
  width: max-content;
  height: max-content;
}

/* Grid layer */
.tm-grid{
  position:absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  border-radius: 16px;
}

/* Objects layer */
.tm-objects{
  position:absolute;
  inset: 0;
}

.tm-stage.dragging .tm-obj{
  cursor: grabbing;
}

/* Objects */
.tm-obj{
  position:absolute;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,.12);
  box-shadow: 0 8px 18px rgba(2,6,23,.12);
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding: 2px;
  font-size: 12px;
  font-weight: 800;
  user-select: none;
  cursor: grab;
}

.tm-obj small{
  display:block;
  font-weight: 650;
  opacity: .9;
  margin-top: 2px;
}

/* ===== ICONE / TEXTE SÉPARÉS ===== */
.tm-obj-title{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
}

.tm-obj-icon{
  line-height: 1;
}

/* Colors */
.tm-obj-flag{ background:#f59e0b; color:#111827; font-size: 15px;}
.tm-obj-flag_n{ background:#fcd34d; color:#111827; font-size: 15px;}
.tm-obj-mine{ background:#C5C4C4; color:#fff; font-size: 26px;}

/* CITY — emoji plus gros uniquement */
.tm-obj-city{ background:#22c55e; color:#052e16; }
.tm-obj-city .tm-obj-icon{ font-size: 28px; }
.tm-obj-city small{ font-size: 10px; }

/* CITY_N — emoji plus gros uniquement */
.tm-obj-city_n{ background:#86efac; color:#052e16; }
.tm-obj-city_n .tm-obj-icon{ font-size: 26px; }
.tm-obj-city_n small{ font-size: 10px; }

.tm-obj-hq{ background:#2563eb; color:#fff; font-size: 50px;}
.tm-obj-farm{ background:#a855f7; color:#fff; font-size: 50px;}
.tm-obj-water{ background:#38bdf8; color:#06283a; font-size: 15px;}
.tm-obj-mountain{ background:#8D5816; color:#fff; font-size: 15px;}
.tm-obj-bear{ background:#C89E93; color:#fff; font-size: 50px;}
.tm-obj-status{ background:#fb7185; color:#fff; font-size: 28px;}


/* Leave block */
.tm-obj-leave{
  background: #fde68a;
  color:#111827;
  border: 2px dashed rgba(0,0,0,.35);
}

/* NAV overlay (flèches) : FIXE sur la zone carte */
.tm-nav{
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.tm-nav-btn{
  pointer-events: auto;
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(15,23,42,.82);
  color: #fff;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0,0,0,.25);
  font-weight: 900;
}

html[data-theme="dark"] .tm-nav-btn{ background: rgba(15,23,42,.86); }
html:not([data-theme="dark"]) .tm-nav-btn{ background: rgba(30,41,59,.75); }

.tm-nav-up{ left: 50%; top: 18px; transform: translateX(-50%); }
.tm-nav-down{ left: 50%; bottom: 18px; transform: translateX(-50%); }
.tm-nav-left{ left: 18px; top: 50%; transform: translateY(-50%); }
.tm-nav-right{ right: 18px; top: 50%; transform: translateY(-50%); }

.tm-nav-upleft{ left: 18px; top: 18px; }
.tm-nav-upright{ right: 18px; top: 18px; }
.tm-nav-downleft{ left: 18px; bottom: 18px; }
.tm-nav-downright{ right: 18px; bottom: 18px; }

/* Modal */
.tm-modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.55);
  z-index: 3000;
}

.tm-modal{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 22px));
  max-height: calc(100vh - 22px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 3001;
}

.tm-modal-head{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.tm-modal-title{ font-weight: 800; }
.tm-modal-sub{ color: var(--muted); font-size: 12px; margin-top: 2px; }

.tm-modal-list{
  display:flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.tm-modal-item{
  padding: 10px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.tm-modal-item:hover{ filter: brightness(0.98); }

.tm-modal-actions{
  display:flex;
  justify-content:flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Tooltip */
.tm-tooltip{
  position: fixed;
  z-index: 4000;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 10px;
  min-width: 220px;
  pointer-events: none;
}

.tm-tooltip .t-title{ font-weight: 800; }
.tm-tooltip .t-sub{ color: var(--muted); font-size: 12px; margin-top: 2px; }
.tm-tooltip .t-grid{
  margin-top: 8px;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.tm-tooltip .t-k{ color: var(--muted); font-size: 12px; }
.tm-tooltip .t-v{ font-weight: 750; font-size: 12px; }

/* Icon buttons */
.tm-iconbtn{
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
}

.tm-only-mobile{ display:none; }

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 980px){
  .tm-root{
    flex-direction: column;
    border-radius: 0;
    height: calc(100vh - var(--header-height, 72px));
    max-height: calc(100vh - var(--header-height, 72px));
  }

  .tm-sidebar{
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    display:none;
  }

  .tm-only-mobile{ display:inline-flex; }

  /* Toolbar plus clean */
  .tm-toolbar{
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .tm-toolbar-right{
    justify-content: space-between;
  }

  .tm-range{ width: 140px; }
}

/* Mobile sidebar open */
.tm-root.tm-sidebar-open .tm-sidebar{
  display:block;
}

.tm-version{
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  margin-left: 10px;
}

.tm-version.ok{
  background: #e6f7ec;
  color: #137333;
}

.tm-version.local{
  background: #fff4e5;
  color: #9a5a00;
}

.tm-version.server{
  background: #fdecea;
  color: #b31412;
}

.tm-btn-lock.locked{
  background:#1f2937;
  color:#e5e7eb;
}

.tm-btn-lock{
  cursor:pointer;
}
/* Modal assign — membres déjà placés */
.tm-modal-item.assigned{
  background: #dcfce7;
  border-left: 4px solid #16a34a;
}
/* Highlight city on member hover */
.tm-obj.highlight{
  outline: 4px solid #facc15;
  z-index: 50;
  animation: pulse-highlight 1s infinite;
}

@keyframes pulse-highlight{
  0%   { box-shadow: 0 0 0 0 rgba(250,204,21,.8); }
  70%  { box-shadow: 0 0 0 12px rgba(250,204,21,0); }
  100% { box-shadow: 0 0 0 0 rgba(250,204,21,0); }
}

/* Export header */
.export-header{
  display:flex;
  align-items:center;
  gap:16px;
  padding:12px 20px;
  background:#ffffff;
  border-bottom:2px solid #e5e7eb;
}

.export-header img{
  height:48px;
}

.export-title{
  font-size:20px;
  font-weight:900;
  color:#111827;
}

/* =========================
   FLAG ZONES LAYER (UNDER OBJECTS)
========================= */

.tm-zones{
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* ne bloque jamais les clics */
  z-index: 2;           /* au-dessus de la grille */
}

.tm-zone{
  position: absolute;
  border-radius: 8px;
  /* ✅ beaucoup moins dominant */
  opacity: 0.16;
  filter: saturate(0.9);
}

/* Alliance = prioritaire visuellement */
.tm-zone--alliance{
  background: rgba(0, 140, 255, 1);
}

/* Neutral = plus léger */
.tm-zone--neutral{
  background: #f59e0b;
  opacity: 0.10;
}

/* Si besoin, assure-toi que les objets restent au-dessus */
.tm-objects{
  position: absolute;
  z-index: 3;
}
