/* Abaque des grandeurs — tableau de conversion vierge */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f4f6fb;
  color: #1f2937;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 2rem; }
.brand h1 { margin: 0; font-size: 1.35rem; }
.brand .subtitle { margin: 0; font-size: .85rem; opacity: .9; }
.nav-btn {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.32); }
nav { display: flex; gap: 8px; }

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

/* ---- Sidebar activités ---- */
#sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 14px;
  overflow-y: auto;
}
#sidebar.hidden { display: none; }
.sidebar-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.sidebar-head .hint { margin: 0 0 10px; font-size: .85rem; color: #6b7280; }
.activity { border: 1px solid #e5e7eb; border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.activity .head {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 10px;
  background: #f8fafc; border: none; cursor: pointer;
  font-size: .92rem; text-align: left;
}
.activity .head:hover { background: #eef2ff; }
.activity .tp-num { background: #6366f1; color: #fff; border-radius: 6px; padding: 2px 6px; font-size: .75rem; font-weight: 700; }
.activity .tp-title { flex: 1; font-weight: 600; }
.activity .tp-level { font-size: .75rem; color: #6b7280; white-space: nowrap; }
.activity .body { display: none; padding: 10px 12px; font-size: .88rem; border-top: 1px solid #e5e7eb; }
.activity.open .body { display: block; }
.activity .body h3 { font-size: .8rem; text-transform: uppercase; color: #6366f1; margin: 10px 0 4px; }
.activity .body ol { margin: 4px 0; padding-left: 20px; }
.activity .body li { margin-bottom: 3px; }
.activity .question { background: #f0f9ff; border-left: 3px solid #0ea5e9; padding: 5px 8px; margin: 5px 0; border-radius: 0 6px 6px 0; }
.prof-note { background: #fffbeb; border-left: 3px solid #f59e0b; padding: 6px 8px; margin-top: 8px; border-radius: 0 6px 6px 0; }
.prof-note h3 { color: #b45309; }

/* ---- Zone principale ---- */
#main { flex: 1; padding: 16px; overflow-x: auto; }

#controls {
  display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px;
}
.step {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 10px 14px;
}
.step-title { font-weight: 600; font-size: .85rem; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: #6366f1; color: #fff; font-size: .75rem; font-weight: 700;
}
.hint-line { margin: 0; font-size: .85rem; color: #6b7280; max-width: 520px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid #d1d5db; background: #fff; color: #1f2937;
  border-radius: 20px; padding: 6px 14px; font-size: .9rem; cursor: pointer;
}
.chip:hover { background: #eef2ff; }
.chip.selected { background: #6366f1; border-color: #6366f1; color: #fff; }
.chip.danger:hover { background: #fef2f2; border-color: #ef4444; color: #b91c1c; }

#stage {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 18px; margin-bottom: 14px;
}

/* ---- Le tableau ---- */
#table-wrap { overflow-x: auto; }
table.abaque { border-collapse: collapse; margin: 0 auto; }
table.abaque th, table.abaque td { border: 1px solid #cbd5e1; }
table.abaque thead th {
  background: #eef2ff; color: #3730a3;
  font-size: 1.2rem; font-weight: 700;
  padding: 10px 6px; min-width: 48px;
  border-bottom: 2px solid #6366f1;
}
table.abaque thead th.alt { background: #e0e7ff; }
/* Ligne capacités / unités agraires */
table.abaque thead tr.subhead th {
  font-size: .95rem; padding: 4px 2px; min-width: 0;
  border-bottom: 2px solid #6366f1;
}
table.abaque thead tr.subhead th.named { background: #fef3c7; color: #92400e; }
table.abaque thead tr.subhead th.empty { background: #f8fafc; }
table.abaque thead tr.subhead th.sub-first { border-left: 2px solid #94a3b8; }
table.abaque thead tr.subhead th.sub-last { border-right: 2px solid #94a3b8; }
table.abaque thead tr:first-child th { border-bottom-width: 1px; }
table.abaque thead tr:last-child th { border-bottom: 2px solid #6366f1; }
table.abaque thead tr.subhead th.pad { border-bottom-color: #cbd5e1; }
table.abaque thead th.rowlbl, table.abaque td.rowlbl {
  background: #f8fafc; border: none; font-size: .8rem; color: #94a3b8;
  width: 1px; white-space: nowrap; padding-right: 8px; text-align: right;
}
table.abaque td.cell {
  width: 48px; height: 64px;
  font-size: 2rem; text-align: center;
  position: relative; cursor: pointer;
  background: #fff;
  vertical-align: middle;
}
table.abaque td.cell:hover { background: #f0f9ff; }
table.abaque td.cell.sub-first { border-left: 2px solid #94a3b8; }
table.abaque td.cell.sub-last { border-right: 2px solid #94a3b8; }
/* Colonnes vides de part et d'autre (grands nombres, décimales) */
table.abaque thead th.pad {
  background: #f8fafc; border-bottom-color: #cbd5e1;
}
table.abaque td.cell.pad {
  background: #fcfcfd;
  border-style: dashed; border-color: #d5dce6;
}
table.abaque td.cell.pad.sel {
  background: #e0f2fe; outline: 3px solid #0ea5e9; outline-offset: -3px;
}
table.abaque tr:last-child td.cell { border-bottom: 2px solid #94a3b8; }
table.abaque td.cell.sel {
  outline: 3px solid #0ea5e9; outline-offset: -3px;
  background: #e0f2fe;
}
table.abaque td.cell.unitcol { background: #dcfce7; }
table.abaque td.cell.unitcol.sel { background: #bbf7d0; }
table.abaque td.cell .comma {
  position: absolute; right: 2px; bottom: 0;
  color: #dc2626; font-size: 2rem; font-weight: 700;
  pointer-events: none;
}
table.abaque td.cell .flag {
  position: absolute; left: 2px; top: 2px;
  font-size: .8rem; line-height: 1;
  color: #16a34a; padding: 1px;
  pointer-events: none;
}
table.abaque td.unit-hdr { border-left: 2px solid #94a3b8; border-right: 2px solid #94a3b8; }
table.abaque tr.delrow td.rowlbl { color: #cbd5e1; }
td.rowlbl .rowdel {
  border: none; background: none; color: #cbd5e1; cursor: pointer;
  font-size: .8rem; padding: 0 2px;
}
td.rowlbl .rowdel:hover { color: #ef4444; }

#row-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

/* ---- Pavé numérique ---- */
#keypad {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  max-width: 420px; margin: 0 auto 16px;
}
#keypad button {
  width: 64px; height: 52px;
  font-size: 1.3rem; font-weight: 600;
  border: 1px solid #d1d5db; border-radius: 10px;
  background: #fff; cursor: pointer;
}
#keypad button:hover { background: #eef2ff; }
#keypad button:active { background: #c7d2fe; }

/* ---- Aide ---- */
.aide {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 12px 16px; font-size: .88rem;
  max-width: 720px; margin: 0 auto;
}
.aide h3 { margin: 0 0 6px; font-size: .95rem; color: #6366f1; }
.aide ul { margin: 0; padding-left: 20px; }
.aide li { margin-bottom: 4px; }

@media (max-width: 900px) {
  #sidebar { position: absolute; z-index: 10; height: 100%; }
  table.abaque td.cell { width: 36px; height: 48px; font-size: 1.5rem; }
}
