:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #62707d;
  --border: #dde1e6;
  --accent: #2f5bd3;
  --select: #7c3aed;
  --alert: #c62828;
  --warn: #b26a00;
  --ok: #1b7f3b;
  --t0: #d64545;
  --t1: #e58a1f;
  --t2: #3b74d9;
  --t3: #2e9d5a;
  --row-h: 30px;
}

* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
main { max-width: 1500px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
a { color: var(--accent); }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fafbfc; }

.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
          padding: 10px 16px; background: #1f2d3d; color: #fff; }
.topbar a, .topbar .link { color: #fff; text-decoration: none; }
.brand { font-weight: 600; font-size: 1.05rem; }
.topbar nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.topbar nav a:hover, .topbar .link:hover { text-decoration: underline; }
form.inline { display: inline; margin: 0; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 640px; margin: 24px auto; }
.hint { color: var(--muted); font-size: .88rem; margin: 8px 0; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; border: 1px solid; }
.flash-error { background: #fdecec; border-color: #f3b4b4; color: #8a1c1c; }
.flash-success { background: #e8f6ec; border-color: #a9dcb8; color: #145c2c; }
.text-alert { color: var(--alert); font-weight: 600; }
.text-warn { color: var(--warn); }
.nowrap { white-space: nowrap; }

button, .btn { font: inherit; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; color: var(--text); }
button:hover { background: #f0f2f5; }
a.btn { display: inline-block; text-decoration: none; line-height: normal; }
a.btn:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #244aad; }
button.danger { background: #fff; border-color: var(--alert); color: var(--alert); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
.btn-group { display: inline-flex; }
.btn-group button { border-radius: 0; margin-left: -1px; }
.btn-group button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.btn-group button:last-child { border-radius: 0 6px 6px 0; }
.btn-group button.active { background: var(--accent); border-color: var(--accent); color: #fff; position: relative; }

label { display: block; margin-bottom: 12px; font-weight: 500; }
label.radio { font-weight: normal; }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px; font: inherit;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; }
input[type=range] { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 16px; align-items: center; }
.delete-form { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)) minmax(260px, 2.5fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.kpi-value { display: block; font-size: 1.7rem; font-weight: 700; }
.kpi-label { color: var(--muted); font-size: .88rem; }
.kpi-alert { border-color: #f3b4b4; background: #fdf3f3; }
.kpi-alert .kpi-value { color: var(--alert); }
.kpi .meter { margin-top: 8px; }

.meter { position: relative; height: 10px; background: #e7eaee; border-radius: 5px; overflow: visible; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.meter-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #1f2933; }
.meter.small { height: 6px; width: 70px; display: inline-block; vertical-align: middle; margin-right: 6px; }

.tiers { display: grid; gap: 10px; }
.tier-row { display: grid; grid-template-columns: 40px 220px minmax(120px, 1fr) minmax(260px, auto); gap: 12px; align-items: center; }
.tier-label { color: var(--muted); }
.tier-figures { font-size: .9rem; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 4px; color: #fff; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tier-T0, .tier-bg-T0 { background: var(--t0); }
.tier-T1, .tier-bg-T1 { background: var(--t1); }
.tier-T2, .tier-bg-T2 { background: var(--t2); }
.tier-T3, .tier-bg-T3 { background: var(--t3); }

/* Tableau */
.table-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.table-toolbar h2 { margin: 0 8px 0 0; }
.table-toolbar input[type=search] { width: 220px; margin: 0; }
.table-wrap { overflow-x: auto; }
table.tasks { width: 100%; border-collapse: collapse; }
table.tasks th, table.tasks td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tasks th { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
table.tasks tr:hover td { background: #f8f9fb; }
.notes { color: var(--muted); font-size: .85rem; white-space: pre-line; }
.status { font-size: .82rem; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.status-done { background: #e3f4e8; color: var(--ok); }
.status-overdue { background: #fde3e3; color: var(--alert); font-weight: 600; }
.status-in_progress { background: #e5edfb; color: var(--accent); }
.status-late_start { background: #fff1dc; color: var(--warn); }
.status-todo { background: #eef0f3; color: var(--muted); }

/* Gantt */
.gantt-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.selection-info { background: #f1eafe; color: #4c1d95; border-radius: 6px; padding: 4px 10px; }
.selection-info[hidden] { display: none; }
.gantt-status { font-size: .9rem; color: var(--muted); }
.gantt-status.error { color: var(--alert); font-weight: 600; }
.gantt-status.ok { color: var(--ok); }

.gantt { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.gantt.g-busy { opacity: .7; pointer-events: none; }
.g-scroll { overflow: auto; max-height: 72vh; position: relative; }
.g-grid { position: relative; }
.g-header { display: flex; position: sticky; top: 0; z-index: 4; background: #fafbfc; border-bottom: 1px solid var(--border); }
.g-corner { position: sticky; left: 0; z-index: 5; width: var(--label-w); flex: none; background: #fafbfc;
            border-right: 1px solid var(--border); padding: 8px 10px; font-weight: 600; display: flex; align-items: flex-end; }
.g-scale { position: relative; height: 48px; flex: none; }
.g-scale-cell { position: absolute; overflow: hidden; white-space: nowrap; text-overflow: clip; font-size: 12px;
                border-left: 1px solid var(--border); padding: 0 4px; }
.g-upper { top: 0; height: 24px; line-height: 24px; font-weight: 600; text-transform: capitalize; }
.g-upper { overflow: visible; }
.g-upper span { position: sticky; left: calc(var(--label-w) + 4px); }
.g-lower { top: 24px; height: 24px; line-height: 24px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); }
.g-lower.g-weekend { background: #eef0f3; }
.g-lower.g-today-cell { background: var(--alert); color: #fff; font-weight: 700; }

.g-body { position: relative; }
.g-bg { position: absolute; top: 0; bottom: 0; left: var(--label-w); pointer-events: none; }
.g-gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: #eceef1; }
.g-weekend-band { position: absolute; top: 0; bottom: 0; background: rgba(120, 130, 145, .08); }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--alert); opacity: .75; z-index: 1; }

.g-row { display: flex; height: var(--row-h); border-bottom: 1px solid #f0f1f3; }
.g-row.selected .g-label { background: #f1eafe; box-shadow: inset 3px 0 0 var(--select); }
.g-label { position: sticky; left: 0; z-index: 3; width: var(--label-w); flex: none; background: #fff; border-right: 1px solid var(--border);
           padding: 0 10px; line-height: var(--row-h); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
           cursor: pointer; user-select: none; font-size: 13px; }
.g-code { font-weight: 600; color: var(--muted); font-size: 12px; }
.g-tier-row { background: #f7f8fa; }
.g-tier-row .g-label { background: #f7f8fa; font-weight: 600; cursor: default; }
.g-track { position: relative; flex: none; }

.g-bar { position: absolute; top: 5px; height: calc(var(--row-h) - 10px); border-radius: 4px; cursor: grab;
         touch-action: none; user-select: none; z-index: 2; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.g-bar:hover { filter: brightness(1.08); }
.g-bar-progress { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0, 0, 0, .28); border-radius: 4px 0 0 4px; pointer-events: none; }
.g-bar.g-overdue { background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, .35) 0 4px, transparent 4px 8px); }
.g-bar.selected { outline: 3px solid var(--select); outline-offset: 2px; z-index: 3; }
.g-handle { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 1; }
.g-narrow .g-handle, .g-readonly .g-handle { display: none; }
.g-readonly .g-bar { cursor: pointer; }
.g-handle.left { left: -2px; }
.g-handle.right { right: -2px; }
.g-bar-text { position: absolute; top: 0; line-height: var(--row-h); font-size: 12px; color: var(--muted); white-space: nowrap; pointer-events: none; }
body.g-dragging, body.g-dragging * { cursor: grabbing !important; }
.g-tip { position: fixed; z-index: 100; background: #1f2933; color: #fff; font-size: 12px; padding: 6px 9px;
         border-radius: 5px; white-space: pre-line; pointer-events: none; max-width: 420px; }
.g-tip[hidden] { display: none; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi-wide { grid-column: 1 / -1; }
  .tier-row { grid-template-columns: 40px 1fr; }
  .tier-row .meter, .tier-row .tier-figures { grid-column: 1 / -1; }
  .form-row { grid-template-columns: 1fr; }
}

/* Projets, menus, administration */
.topbar-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.menu { position: relative; }
.menu summary { cursor: pointer; list-style: none; padding: 4px 10px; border-radius: 6px; background: rgba(255, 255, 255, .1); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; font-size: .8em; }
.menu-panel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; min-width: 240px; background: #fff;
              border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); padding: 6px 0; }
.menu-panel.right { left: auto; right: 0; }
.topbar .menu-panel a, .topbar .menu-panel .link { display: block; width: 100%; text-align: left; padding: 7px 14px; color: var(--text); text-decoration: none; }
.topbar .menu-panel a:hover, .topbar .menu-panel .link:hover { background: #f0f2f5; text-decoration: none; }
.menu-panel a.current { font-weight: 600; background: #eef3fd; }
.menu-panel .menu-extra { border-top: 1px solid var(--border); margin-top: 4px; color: var(--accent) !important; }
.menu-panel form { margin: 0; }
.tag { display: inline-block; font-size: .75rem; padding: 0 6px; border-radius: 4px; background: #eef0f3; color: var(--muted); font-weight: 500; }
.tag-readonly { background: #fff1dc; color: var(--warn); }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.plain-list { padding-left: 18px; }
.share-matrix select { width: auto; display: inline-block; margin: 0; }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.btn.primary:hover { background: #244aad; }
