/* ==========================================================================
   Chiffrage Rapide & Métrés — Design System (charte RE2020 Expert)
   ========================================================================== */

:root {
  --primary-color: #00235c;
  --primary-color-light: #0a3a86;
  --accent-color: #00bddd;
  --accent-color-soft: #70daec;
  --bg-dark: #0a1128;
  --bg-light: #f4f6fa;
  --card-bg: #ffffff;
  --text-main: #2d3748;
  --text-muted: #6b7690;
  --border-color: #e2e7f0;
  --danger-color: #e5484d;
  --success-color: #1fa971;
  --warning-color: #e8a33d;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 3px rgba(10, 17, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(10, 17, 40, 0.12);
  --shadow-lg: 0 16px 40px rgba(10, 17, 40, 0.22);

  --sidebar-width: 340px;
  --header-height: 82px;

  --font-heading: 'Montserrat', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  color: var(--text-main);
  background: var(--bg-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-heading); margin: 0; }

button, input { font-family: inherit; }

/* ============ HEADER ============ */
.app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: linear-gradient(120deg, var(--primary-color), #001635 85%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 5px;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.2), var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}
.header-logo-link:hover {
  transform: scale(1.06);
  box-shadow: 0 0 0 2px var(--accent-color), var(--shadow-md);
}

.header-logo {
  height: 58px;
  width: 58px;
  object-fit: contain;
  border-radius: 10px;
  display: block;
}

.header-titles { display: flex; flex-direction: column; line-height: 1.25; }
.header-titles h1 { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: 0.2px; }
.header-titles span { color: var(--accent-color-soft); font-size: 0.72rem; font-weight: 500; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.file-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #dff7fb;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  max-width: 240px;
}
.file-badge i { width: 15px; height: 15px; color: var(--accent-color); flex-shrink: 0; }
.file-badge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-action-btn {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #dff7fb;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.header-action-btn i { width: 15px; height: 15px; color: var(--accent-color); flex-shrink: 0; }
.header-action-btn:hover:not(:disabled) { background: rgba(0,189,221,0.18); border-color: var(--accent-color); }
.header-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ LAYOUT ============ */
.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 17, 40, 0.5);
  z-index: 90;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--card-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 95;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.panel-grow { flex: 1; display: flex; flex-direction: column; min-height: 160px; }

.panel h2 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-color);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.panel h2 i { width: 16px; height: 16px; color: var(--accent-color); }

/* --- Import --- */
.import-actions { display: flex; flex-direction: column; gap: 8px; }
.import-actions .btn { width: 100%; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s;
  user-select: none;
}
.btn i { width: 15px; height: 15px; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-color-light); box-shadow: var(--shadow-sm); }

.btn-secondary { background: var(--accent-color); color: #00233a; }
.btn-secondary:hover:not(:disabled) { background: var(--accent-color-soft); }

.btn-outline { background: #fff; color: var(--primary-color); border-color: var(--border-color); }
.btn-outline:hover:not(:disabled) { border-color: var(--accent-color); color: var(--primary-color); background: #f3fcfd; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-light); }

.btn-block { width: 100%; }
.btn-sm { padding: 8px 10px; font-size: 0.76rem; flex: 1; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: auto;
}
.icon-btn i { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--bg-light); color: var(--primary-color); }
.icon-btn-accent { background: var(--primary-color); color: #fff; }
.icon-btn-accent:hover { background: var(--accent-color); color: #00233a; }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mobile-only { display: none; }

/* --- Scale panel --- */
.scale-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.78rem;
  color: var(--warning-color);
  background: #fef8ec;
  border: 1px solid #f6e3bb;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.scale-status i { width: 15px; height: 15px; flex-shrink: 0; }
.scale-status.calibrated { color: var(--success-color); background: #eafbf3; border-color: #bdeed6; }

/* --- Group list --- */
.group-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }

.empty-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  padding: 18px 8px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
}

.group-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  background: #fff;
}
.group-item:hover { border-color: var(--accent-color-soft); }
.group-item.active { border-color: var(--accent-color); background: #eefcff; box-shadow: 0 0 0 2px rgba(0,189,221,0.15); }

.g-color { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.g-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.g-name { font-size: 0.82rem; font-weight: 700; color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-value { font-size: 0.72rem; color: var(--text-muted); }
.g-type-icon { color: var(--text-muted); flex-shrink: 0; display: flex; }
.g-type-icon i { width: 14px; height: 14px; }
.g-actions { display: flex; gap: 2px; flex-shrink: 0; }
.g-actions button { width: 26px; height: 26px; }
.g-actions button i { width: 13px; height: 13px; }

/* --- Summary table --- */
.table-wrap { max-height: 220px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: var(--radius-sm); margin-bottom: 10px; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; }
.summary-table th {
  position: sticky; top: 0;
  background: var(--bg-light);
  color: var(--primary-color);
  text-align: left;
  padding: 8px 10px;
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
}
.summary-table td { padding: 7px 10px; border-bottom: 1px solid #f0f2f7; color: var(--text-main); }
.summary-table tr:last-child td { border-bottom: none; }
.summary-table .empty-row td { text-align: center; color: var(--text-muted); padding: 14px; }
.summary-table .g-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

.export-actions { display: flex; gap: 8px; }

/* ============ CANVAS AREA ============ */
.canvas-area {
  flex: 1;
  position: relative;
  background: var(--bg-dark);
  background-image:
    radial-gradient(circle at 25% 15%, rgba(0,189,221,0.08), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(0,35,92,0.4), transparent 50%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.canvas-topbar {
  position: absolute;
  top: 14px; left: 14px; right: 14px;
  display: flex;
  justify-content: space-between;
  z-index: 20;
  pointer-events: none;
}

.mode-pill, .scale-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(0, 20, 48, 0.68);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.mode-pill i { width: 14px; height: 14px; }
.mode-pill.mode-nav { color: #dbe4ff; }
.mode-pill.mode-calibrate { background: rgba(120,74,10,0.75); border-color: rgba(232,163,61,0.5); color: #ffe6b8; }
.mode-pill.mode-measure { background: rgba(0,60,74,0.75); border-color: rgba(0,189,221,0.5); color: #d8fbff; }

.canvas-container {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
}

#planCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: rgba(255,255,255,0.6);
  text-align: center;
  pointer-events: none;
}
.canvas-empty-state i { width: 52px; height: 52px; color: rgba(0,189,221,0.5); margin-bottom: 8px; }
.canvas-empty-state p { margin: 0; font-size: 1rem; font-weight: 700; color: rgba(255,255,255,0.85); }
.canvas-empty-state span { font-size: 0.8rem; max-width: 280px; }

/* --- Magnifier --- */
.magnifier {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 3px solid var(--accent-color);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  pointer-events: none;
  z-index: 60;
  background: #fff;
}

/* --- Floating controls --- */
.float-controls {
  position: absolute;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.float-controls-zoom { right: 16px; bottom: 16px; }
.float-controls-draw { left: 50%; bottom: 16px; transform: translateX(-50%); flex-direction: row; }

.fbtn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0, 20, 48, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: background 0.15s, transform 0.12s;
}
.fbtn i { width: 19px; height: 19px; }
.fbtn:hover { background: rgba(0,189,221,0.55); }
.fbtn:active { transform: scale(0.94); }
.fbtn-wide { width: auto; padding: 0 16px; gap: 8px; font-size: 0.8rem; font-weight: 600; }
.fbtn-stop { background: rgba(150,30,34,0.78); border-color: rgba(229,72,77,0.5); }
.fbtn-stop:hover { background: rgba(229,72,77,0.75); }

/* ============ MODALS ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 17, 40, 0.55);
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal h3 { display: flex; align-items: center; gap: 8px; color: var(--primary-color); font-size: 1.05rem; margin-bottom: 6px; }
.modal h3 i { width: 18px; height: 18px; color: var(--accent-color); }
.modal-hint { font-size: 0.8rem; color: var(--text-muted); margin: 0 0 16px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 0.78rem; font-weight: 700; color: var(--text-main); }
.field input[type="text"], .field input[type="number"] {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(0,189,221,0.15); }

.type-options { display: flex; gap: 8px; }
.type-option { flex: 1; cursor: pointer; }
.type-option input { display: none; }
.type-option span {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s;
}
.type-option span i { width: 18px; height: 18px; }
.type-option input:checked + span { border-color: var(--accent-color); background: #eefcff; color: var(--primary-color); }

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] { width: 42px; height: 38px; border: 1px solid var(--border-color); border-radius: 8px; padding: 2px; cursor: pointer; background: none; }
.color-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.color-swatch { width: 22px; height: 22px; border-radius: 6px; cursor: pointer; border: 2px solid transparent; }
.color-swatch.selected { border-color: var(--primary-color); }

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

/* ============ RÉCAPITULATIF VISUEL (plein écran) ============ */
.summary-view {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-light);
  z-index: 300;
  overflow-y: auto;
}
.summary-view.active { display: block; }

.summary-view-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.summary-view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 3px solid var(--primary-color);
  padding-bottom: 16px;
  margin-bottom: 20px;
}
.summary-view-header img { height: 56px; width: 56px; object-fit: cover; border-radius: 12px; flex-shrink: 0; }
.summary-view-header h2 { color: var(--primary-color); font-size: 1.3rem; }
.summary-view-header p { margin: 2px 0 0; color: var(--text-muted); font-size: 0.85rem; }
.summary-view-header .icon-btn { margin-left: auto; width: 40px; height: 40px; }
.summary-view-header .icon-btn i { width: 20px; height: 20px; }

.summary-cards { display: flex; flex-direction: column; gap: 10px; }
.summary-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-left: 6px solid var(--accent-color);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.summary-card-info { flex: 1; min-width: 0; }
.summary-card-name { font-weight: 800; font-size: 1.05rem; color: var(--text-main); }
.summary-card-type { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.summary-card-value { font-family: var(--font-heading); font-size: 1.4rem; font-weight: 800; color: var(--primary-color); white-space: nowrap; }
.summary-empty { text-align: center; color: var(--text-muted); padding: 40px 10px; }

.summary-view-actions { display: flex; justify-content: center; gap: 12px; margin-top: 28px; }

/* ============ PRINT ============ */
.print-summary { display: none; }

@media print {
  body > *:not(#printSummary) { display: none !important; }
  #printSummary { display: block !important; padding: 20px; }
  .print-header { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid var(--primary-color); padding-bottom: 14px; margin-bottom: 18px; }
  .print-header img { height: 54px; width: 54px; object-fit: cover; border-radius: 8px; }
  .print-header h1 { color: var(--primary-color); font-size: 1.3rem; margin: 0 0 4px; }
  .print-header p { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
  #printSummary table { width: 100%; border-collapse: collapse; }
  #printSummary th, #printSummary td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #ddd; font-size: 0.9rem; }
  #printSummary th { background: #f0f2f7; color: var(--primary-color); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 880px) {
  .mobile-only { display: inline-flex; }

  .header-titles span { display: none; }
  .header-logo { height: 48px; width: 48px; }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: min(86vw, 360px);
    min-width: unset;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }

  .float-controls-zoom { bottom: 84px; right: 10px; }
  .float-controls-draw { bottom: 10px; width: calc(100% - 20px); justify-content: center; }
  .fbtn { width: 46px; height: 46px; }

  .file-badge { max-width: 140px; }
  .header-action-label { display: none; }
  .header-action-btn { padding: 8px; }
}

@media (max-width: 480px) {
  .type-options { flex-wrap: wrap; }
  .modal { padding: 18px; }
}
