:root {
  --brand-main: #618381; 
  --brand-dark: #3a4f4e;
  --brand-light: #dce4e4;
  --brand-lighter: #f0f4f4;
  --ink: #1d1d1b; 
  --muted: #6b7280;
  --bg: #f4f6f6; 
  --panel: #fff; 
  --line: #c4d0cf; 
  --line2: #eaf0f0;
  --warn: #b3261e; 
  --ok: #1f7a4d;
  --shadow: 0 2px 4px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --radius: 10px;
  --amber-bg: #fff9e6;
  --amber-border: #d99b00;
  --amber-text: #b37400;
}

* { box-sizing: border-box; }

html, body {
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body { 
  font-family: 'Roboto', sans-serif; 
  background: var(--bg); 
  color: var(--ink); 
  font-size: 13px; 
  line-height: 1.4; 
  transition: background 0.2s ease; 
}

/* ÉCRAN D'AUTHENTIFICATION */
#auth-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(29, 29, 27, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  background: #fff;
  padding: 30px;
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.storage-banner { 
  background: var(--brand-dark); 
  color: #fff; 
  padding: 8px 24px; 
  font-size: 12px; 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
}

.storage-banner span b { color: var(--brand-light); }

header.app { 
  background: var(--panel); 
  border-bottom: 3px solid var(--brand-main); 
  padding: 12px 24px; 
  display: flex; 
  align-items: center; 
  gap: 24px; 
  position: sticky; 
  top: 0; 
  z-index: 50; 
  box-shadow: var(--shadow); 
}

.logo { 
  font-weight: 900; 
  font-size: 22px; 
  color: var(--brand-dark); 
  letter-spacing: 1px; 
  text-transform: uppercase; 
}

nav.tabs { display: flex; gap: 8px; }

nav.tabs button { 
  border: 0; 
  background: transparent; 
  color: var(--muted); 
  padding: 10px 18px; 
  border-radius: 6px; 
  font-size: 13px; 
  font-weight: 700; 
  cursor: pointer; 
  transition: all 0.2s; 
  text-transform: uppercase; 
}

nav.tabs button:hover { background: var(--brand-lighter); color: var(--brand-main); }
nav.tabs button.active { background: var(--brand-main); color: #fff; }

.btn { 
  border: 1px solid var(--line); 
  background: var(--panel); 
  color: var(--ink); 
  padding: 8px 16px; 
  border-radius: 6px; 
  font-size: 12.5px; 
  font-weight: 600; 
  cursor: pointer; 
  white-space: nowrap; 
  transition: 0.2s; 
  font-family: inherit; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover { border-color: var(--brand-main); background: var(--brand-lighter); }
.btn.primary { background: var(--brand-main); border-color: var(--brand-main); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--warn); border-color: #eccac7; background: #fff5f5; padding: 6px 12px; }
.btn.sm { padding: 4px 8px; font-size: 11.5px; border-radius: 4px; }

.btn-create-dashed { 
  background: transparent; 
  border: 2px dashed var(--brand-main); 
  color: var(--brand-dark); 
  padding: 12px; 
  border-radius: 6px; 
  font-weight: 700; 
  width: 100%; 
  cursor: pointer; 
  transition: 0.2s; 
  font-family: inherit; 
  margin-bottom: 10px; 
}

.btn-create-dashed:hover { background: var(--brand-main); color: #fff; border-style: solid; }

main { padding: 24px; max-width: 100%; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease-out; }

@keyframes fadeIn { 
  from { opacity: 0; transform: translateY(4px); } 
  to { opacity: 1; transform: translateY(0); } 
}

.toolbar { 
  display: flex; 
  align-items: center; 
  gap: 12px; 
  flex-wrap: wrap; 
  margin-bottom: 20px; 
  background: #fff; 
  border: 1px solid var(--line); 
  border-radius: var(--radius); 
  padding: 12px 18px; 
  box-shadow: var(--shadow); 
}

.spacer { flex: 1; }

.kpi-row { 
  display: grid; 
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
  gap: 16px; 
  margin-bottom: 24px; 
}

.kpi { 
  background: #fff; 
  border: 1px solid var(--line); 
  border-radius: 12px; 
  padding: 18px; 
  box-shadow: var(--shadow); 
  border-top: 4px solid var(--brand-light); 
}

.kpi.highlight { border-top-color: var(--brand-main); }
.kpi.credit { border-top-color: var(--ok); }
.kpi .v { font-size: 26px; font-weight: 900; color: var(--ink); line-height: 1.1; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; margin-top: 6px; }

.split-view { display: flex; gap: 24px; align-items: flex-start; width: 100%; }
.sidebar { flex: 0 0 480px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.main-panel { flex: 1; min-width: 0; }

.project-list { list-style: none; padding: 0; margin: 0 0 12px 0; }
.project-list li { 
  padding: 12px 14px; 
  margin-bottom: 8px; 
  border-radius: 6px; 
  cursor: pointer; 
  font-weight: 700; 
  border: 1px solid var(--line); 
  background: #fff; 
  color: var(--ink); 
  transition: 0.15s; 
  text-align: left; 
}

.project-list li:hover { background: var(--brand-lighter); border-color: var(--brand-main); color: var(--brand-dark); }
.project-list li.active { background: var(--brand-main); color: #fff; border-color: var(--brand-dark); box-shadow: var(--shadow); }

.tablewrap { 
  overflow-x: auto; 
  border: 1px solid var(--line); 
  border-radius: var(--radius); 
  background: #fff; 
  box-shadow: var(--shadow); 
  margin-bottom: 24px; 
  -webkit-overflow-scrolling: touch; 
}

table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; table-layout: auto; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line2); border-right: 1px solid var(--line2); text-align: right; }
th { background: var(--brand-lighter); position: sticky; top: 0; z-index: 5; font-weight: 700; color: var(--brand-dark); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; }
thead th { border-bottom: 2px solid var(--brand-main); }
td.txt, th.txt { text-align: left; }
tr:hover td { background: #fafafa; }
tr.row-total td { background: var(--brand-dark); color: #fff; font-weight: bold; border-right: 1px solid var(--brand-main); }
tr.row-credit td { background: var(--brand-light); color: var(--brand-dark); font-weight: bold; border-right: 1px solid var(--line); }

input.cell-input, select.cell-input { width: 100%; min-width: 60px; border: 1px solid transparent; background: transparent; font-size: 11.5px; padding: 4px; text-align: right; border-radius: 4px; font-family: inherit; }
input.cell-input[type="date"] { min-width: 100px; padding: 2px; font-size: 11px; text-align: left; }
input.cell-input:hover, select.cell-input:hover { border-color: var(--line); background: var(--brand-lighter); }
input.cell-input:focus, select.cell-input:focus { border-color: var(--brand-main); outline: none; background: #fff; box-shadow: 0 0 0 2px var(--brand-light); }
select.cell-input { text-align: left; cursor: pointer; }

.form-input, .form-select { width: 100%; background: #fff; border: 1px solid var(--line); padding: 10px; border-radius: 6px; font-size: 13px; color: var(--ink); font-family: inherit; transition: border-color 0.2s; text-align: left; }
.form-input:hover, .form-select:hover { border-color: var(--brand-main); }
.form-input:focus, .form-select:focus { border-color: var(--brand-main); outline: none; background: #fff; box-shadow: 0 0 0 2px var(--brand-light); }

.form-input.override-active { background: var(--amber-bg) !important; border-color: var(--amber-border) !important; color: var(--amber-text) !important; font-weight: bold; }
.calculated-badge { font-size: 11px; color: var(--brand-dark); background: var(--brand-light); padding: 2px 6px; border-radius: 4px; cursor: pointer; font-weight: 700; text-decoration: underline; }
.calculated-badge:hover { background: var(--brand-main); color: #fff; }

.print-preview-container { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 50px; margin-top: 24px; box-shadow: var(--shadow); max-width: 100%; margin-left: auto; margin-right: auto; }
.print-sheet-title { text-align: center; font-size: 18px; font-weight: 900; color: var(--brand-dark); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1.5px; }
.print-sheet-subtitle { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 30px; font-weight: bold; text-transform: uppercase; border-bottom: 1px solid var(--line); padding-bottom: 12px; }

.cover-page { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 820px; text-align: center; padding: 40px; background: #fff; border: 1px solid var(--line2); border-radius: 6px; margin-bottom: 30px; }
.cover-title { font-size: 32px; font-weight: 900; color: var(--brand-dark); margin-bottom: 12px; letter-spacing: 1px; text-transform: uppercase; line-height: 1.2; }
.cover-subtitle { font-size: 16px; font-weight: 700; color: var(--brand-main); margin-bottom: 180px; text-transform: uppercase; letter-spacing: 0.5px; }
.cover-meta { font-size: 13px; color: var(--ink); line-height: 2.2; margin-top: 40px; border-top: 3px double var(--brand-light); padding-top: 30px; width: 100%; max-width: 550px; text-align: left; }

.toc-page { padding: 50px 50px; min-height: 820px; background: #fff; border: 1px solid var(--line2); border-radius: 6px; margin-bottom: 30px; }
.toc-item { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; font-size: 13.5px; font-weight: 700; color: var(--brand-dark); }
.toc-dots { flex-grow: 1; border-bottom: 2px dashed var(--line); margin: 0 15px; position: relative; top: -3px; }

.theme-swatch { border: 2px solid transparent; border-radius: 8px; padding: 12px; cursor: pointer; background: #fff; text-align: center; transition: all 0.2s; }
.theme-swatch:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.theme-swatch.active { border-color: var(--ink); box-shadow: var(--shadow); font-weight: bold; }

.table-rq-green th { background-color: #92d050 !important; color: #000 !important; font-weight: bold !important; border: 1px solid #71a932 !important; text-align: center !important; }
.table-rq-green td { border: 1px solid #d4ebd4 !important; }

/* ======================================================= */
/* ERGONOMIE MOBILE & RESPONSIVE DESIGN (<= 768px)         */
/* ======================================================= */
@media (max-width: 768px) {
  body {
    font-size: 12px;
  }

  .storage-banner {
    flex-direction: column;
    gap: 4px;
    text-align: center;
    padding: 6px 12px;
  }

  header.app {
    padding: 10px 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    position: relative; /* Désactive le sticky gênant sur petit écran */
  }

  .logo {
    font-size: 18px;
    text-align: center;
  }

  #header-active-dossier {
    width: 100%;
    text-align: center;
    font-size: 11.5px;
    padding: 6px 10px;
    white-space: normal;
    word-break: break-word;
  }

  nav.tabs {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 4px;
  }

  nav.tabs button {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 11.5px;
  }

  main {
    padding: 10px 8px;
  }

  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }

  .kpi {
    padding: 12px 10px;
  }

  .kpi .v {
    font-size: 17px;
  }

  .kpi .l {
    font-size: 9.5px;
  }

  .split-view {
    flex-direction: column;
    gap: 16px;
  }

  .sidebar {
    flex: none;
    width: 100%;
    padding: 12px;
  }

  .main-panel {
    width: 100%;
  }

  /* Force la remise en une seule colonne des formulaires à 2 colonnes */
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: repeat(auto-fill"] {
    grid-template-columns: 1fr !important;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  .toolbar input {
    width: 100% !important;
  }

  .tablewrap {
    border-radius: 6px;
    margin-bottom: 16px;
  }

  table {
    font-size: 11px;
  }

  th, td {
    padding: 5px 6px;
  }

  input.cell-input, select.cell-input {
    font-size: 11px;
    padding: 4px;
    min-height: 30px;
  }

  .btn {
    width: 100%;
    padding: 10px 14px;
    font-size: 12px;
  }

  .btn.sm {
    width: auto;
    padding: 6px 10px;
    font-size: 11px;
  }

  .auth-card {
    padding: 20px 16px;
    margin: 0 12px;
  }

  .print-preview-container {
    padding: 16px 8px;
  }

  .spacer {
    display: none;
  }
}

@media print {
  body { background: #fff; color: #000; }
  .no-print { display: none !important; }
  body, main, #page-config, .print-container-wrapper, #report-view-hub { display: block !important; background: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
  h1, h2, h3, h4, h5, h6 { page-break-after: avoid !important; break-after: avoid !important; }
  .project-print-block { page-break-inside: avoid !important; break-inside: avoid !important; }
  .print-page-break { page-break-after: always !important; page-break-inside: avoid !important; clear: both !important; padding-top: 12mm; }
  .cover-page, .toc-page { min-height: 100% !important; page-break-after: always !important; border: none !important; padding: 0 !important; }
  table { border: 1px solid #000 !important; width: 100% !important; border-collapse: collapse !important; page-break-inside: avoid !important; margin-top: 15px; font-size: 10px; }
  th { background: #f0f0f0 !important; color: #000 !important; border: 1px solid #000 !important; font-weight: bold !important; text-transform: uppercase; font-size: 9px; }
  td { border: 1px solid #000 !important; padding: 6px 8px !important; }
  td.txt, th.txt { text-align: left !important; }
  td.num, th.num { text-align: right !important; }
}