:root {
    --mh-blue: #1d4ed8;
    --mh-blue-dark: #123a91;
    --mh-cyan: #06b6d4;
    --mh-slate: #0f172a;
    --mh-muted: #64748b;
    --mh-border: #dbe4f0;
    --mh-soft: #f5f8fc;
    --mh-success: #0f9f6e;
    --mh-danger: #dc2626;
    --mh-orange: #f59e0b;
}

.mh-page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 22px 60px;
    color: var(--mh-slate);
    font-family: inherit;
}

.mh-page * { box-sizing: border-box; }

.mh-hero {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1.15fr .85fr;
    gap: 34px;
    align-items: center;
    min-height: 390px;
    padding: 52px;
    border-radius: 30px;
    background:
        radial-gradient(circle at 85% 10%, rgba(6,182,212,.28), transparent 32%),
        linear-gradient(135deg, #0f172a, #123a91 72%, #0b6a8f);
    color: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .18);
}

.mh-hero h1,
.mh-sim-header h1 {
    margin: 8px 0 14px;
    font-size: clamp(2.2rem, 5vw, 4.3rem);
    line-height: 1;
    letter-spacing: -.045em;
}

.mh-hero p {
    max-width: 720px;
    margin: 0;
    color: rgba(255,255,255,.88);
    font-size: 1.08rem;
    line-height: 1.75;
}

.mh-kicker {
    display: inline-block;
    font-size: .82rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: #0ea5e9;
}

.mh-hero .mh-kicker { color: #a5f3fc; }

.mh-actions,
.mh-sim-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}

.mh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 11px 18px;
    border: 0;
    border-radius: 12px;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.mh-btn:hover { transform: translateY(-1px); }

.mh-btn-primary {
    background: linear-gradient(135deg, #2563eb, #0891b2);
    color: #fff;
    box-shadow: 0 9px 24px rgba(37, 99, 235, .25);
}

.mh-hero .mh-btn-primary {
    background: #fff;
    color: #123a91;
}

.mh-btn-secondary {
    background: #e8f1ff;
    color: #174ea6;
}

.mh-hero .mh-btn-secondary {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.22);
    color: #fff;
}

.mh-btn-light {
    background: #fff;
    color: #334155;
    border: 1px solid var(--mh-border);
}

.mh-btn-full { width: 100%; }

.mh-bus-demo {
    min-height: 260px;
    padding: 24px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 24px;
    background: rgba(255,255,255,.08);
    backdrop-filter: blur(12px);
}

.mh-bus-device,
.mh-bus-load {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 230px;
    padding: 15px;
    border-radius: 15px;
    background: #fff;
    color: var(--mh-slate);
    box-shadow: 0 10px 25px rgba(0,0,0,.12);
}

.mh-bus-device strong { display: block; }
.mh-bus-device small { margin-left: auto; color: var(--mh-muted); }
.mh-actuator { margin-left: auto; }
.mh-bus-load { width: 64px; justify-content: center; margin: 16px 0 0 auto; font-size: 1.6rem; }

.mh-bus-line {
    position: relative;
    height: 68px;
    margin: 4px 24px;
}
.mh-bus-line::before {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 33px;
    height: 4px;
    border-radius: 99px;
    background: #67e8f9;
}
.mh-bus-line span {
    position: absolute;
    left: 50%;
    top: 21px;
    transform: translateX(-50%);
    z-index: 1;
    padding: 4px 9px;
    border-radius: 99px;
    background: #123a91;
    font-size: .75rem;
    font-weight: 800;
}

.mh-section { padding: 48px 4px 0; }

.mh-section-heading {
    max-width: 800px;
    margin-bottom: 22px;
}
.mh-section-heading h2 {
    margin: 6px 0 8px;
    font-size: clamp(1.65rem, 3vw, 2.45rem);
    letter-spacing: -.03em;
}
.mh-section-heading p { margin: 0; color: var(--mh-muted); line-height: 1.65; }

.mh-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}
.mh-card-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.mh-card,
.mh-example-card,
.mh-rule,
.mh-admin-card {
    padding: 22px;
    border: 1px solid var(--mh-border);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .055);
}
.mh-card h3,
.mh-example-card h3,
.mh-rule h3 { margin: 12px 0 7px; }
.mh-card p,
.mh-example-card p,
.mh-rule p { margin: 0; color: var(--mh-muted); line-height: 1.6; }

.mh-letter {
    display: inline-flex;
    min-width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border-radius: 12px;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 900;
}

.mh-rule-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.mh-rule-config {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.mh-rule-config span,
.mh-badge,
.mh-difficulty {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: .76rem;
    font-weight: 900;
}

.mh-example-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.mh-difficulty { background: #f8fafc; color: #475569; }
.mh-link {
    display: inline-flex;
    margin-top: 17px;
    color: #1d4ed8;
    font-weight: 850;
    text-decoration: none;
}

.mh-teacher-box {
    margin-top: 48px;
    padding: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-radius: 22px;
    background: linear-gradient(135deg, #eff6ff, #ecfeff);
}
.mh-teacher-box h2 { margin: 6px 0 8px; }
.mh-teacher-box p { margin: 0; color: #475569; max-width: 820px; line-height: 1.6; }

.mh-alert {
    margin: 20px 0;
    padding: 15px 18px;
    border-radius: 14px;
    font-weight: 700;
}
.mh-alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.mh-alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.mh-empty { padding: 30px; border: 1px dashed var(--mh-border); border-radius: 18px; color: var(--mh-muted); text-align: center; }

/* Simulateur */
.mh-sim-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: end;
    padding: 22px 0 25px;
    border-bottom: 1px solid var(--mh-border);
}
.mh-sim-header h1 { margin-top: 7px; font-size: clamp(2rem, 4vw, 3.3rem); }
.mh-sim-header p { margin: 0; color: var(--mh-muted); }
.mh-back { display: inline-block; margin-bottom: 12px; color: #475569; font-weight: 800; text-decoration: none; }

.mh-example-select {
    min-width: 300px;
}
.mh-example-select span,
.mh-admin-form label > span {
    display: block;
    margin-bottom: 7px;
    color: #475569;
    font-size: .82rem;
    font-weight: 850;
}
.mh-example-select select,
.mh-admin-form input,
.mh-admin-form select,
.mh-admin-form textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    background: #fff;
    color: #0f172a;
    font: inherit;
}

.mh-mission {
    margin: 24px 0;
    display: grid;
    grid-template-columns: 1.25fr .75fr;
    gap: 18px;
    padding: 24px;
    border: 1px solid #bfdbfe;
    border-radius: 20px;
    background: linear-gradient(135deg, #eff6ff, #f8fafc);
}
.mh-mission h2 { margin: 8px 0 6px; }
.mh-mission p { margin: 0; color: #475569; }
.mh-mission-objective {
    padding: 17px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid #dbeafe;
}
.mh-mission-objective strong { display: block; margin-bottom: 6px; }

.mh-sim-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    align-items: start;
}

.mh-palette-panel {
    position: sticky;
    top: 18px;
    padding: 18px;
    border: 1px solid var(--mh-border);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 10px 26px rgba(15,23,42,.06);
}
.mh-panel-title { display: flex; gap: 11px; align-items: center; }
.mh-panel-title > span { font-size: 1.7rem; }
.mh-panel-title strong,
.mh-panel-title small { display: block; }
.mh-panel-title small { color: var(--mh-muted); }

.mh-palette-help {
    margin: 14px 0;
    padding: 11px;
    border-radius: 10px;
    background: #f8fafc;
    color: #64748b;
    font-size: .82rem;
    line-height: 1.45;
}

.mh-palette-group { margin: 14px 0; }
.mh-palette-group > strong {
    display: block;
    margin-bottom: 8px;
    font-size: .76rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.mh-palette-chips { display: flex; flex-wrap: wrap; gap: 7px; }

.mh-config-chip {
    display: inline-flex;
    min-width: 37px;
    height: 35px;
    padding: 0 9px;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    border-radius: 8px;
    font-weight: 900;
    line-height: 1;
    cursor: grab;
    user-select: none;
}
button.mh-config-chip { font: inherit; font-weight: 900; }
.mh-config-chip.is-number {
    background: #1d4ed8;
    color: #fff;
}
.mh-config-chip.is-mode {
    background: #0f766e;
    color: #fff;
}
.mh-config-chip.is-selected {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.mh-legend {
    display: grid;
    gap: 5px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--mh-border);
    color: #64748b;
    font-size: .79rem;
}
.mh-legend strong { color: #334155; }

.mh-workspace {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.mh-device-card {
    padding: 18px;
    border: 1px solid var(--mh-border);
    border-top: 4px solid #2563eb;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(15,23,42,.055);
}
.mh-device-card.is-actuator { border-top-color: #0891b2; }
.mh-device-head { display: flex; gap: 10px; align-items: center; }
.mh-device-icon { font-size: 1.55rem; }
.mh-device-head small,
.mh-device-head strong { display: block; }
.mh-device-head small { color: #64748b; font-size: .72rem; text-transform: uppercase; font-weight: 800; }
.mh-device-id {
    margin-left: auto;
    padding: 4px 7px;
    border-radius: 7px;
    background: #f1f5f9;
    color: #64748b;
    font-size: .75rem;
    font-weight: 900;
}
.mh-associated-load {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 13px 0 4px;
    color: #64748b;
}
.mh-associated-load > span { font-size: 1.35rem; }

.mh-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}
.mh-slot-wrap { width: 64px; }
.mh-slot-label {
    display: block;
    margin-bottom: 5px;
    text-align: center;
    font-size: .73rem;
    font-weight: 900;
    color: #475569;
}
.mh-slot {
    width: 64px;
    height: 52px;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #94a3b8;
    border-radius: 11px;
    background: #f8fafc;
    cursor: pointer;
}
.mh-slot.is-over { border-color: #2563eb; background: #eff6ff; }
.mh-slot.is-locked {
    border-style: solid;
    border-color: #cbd5e1;
    background: #f1f5f9;
    cursor: not-allowed;
}
.mh-empty-slot { font-size: 1.3rem; color: #94a3b8; }
.mh-device-test {
    width: 100%;
    margin-top: 16px;
    min-height: 39px;
    border: 0;
    border-radius: 10px;
    background: #eff6ff;
    color: #1d4ed8;
    font: inherit;
    font-weight: 850;
    cursor: pointer;
}

.mh-feedback {
    margin-top: 18px;
    display: flex;
    gap: 18px;
    align-items: flex-start;
    padding: 18px;
    border-radius: 16px;
}
.mh-feedback.is-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.mh-feedback.is-error { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; }
.mh-feedback-score {
    min-width: 70px;
    font-size: 1.7rem;
    font-weight: 950;
}
.mh-feedback p { margin: 5px 0 0; }
.mh-feedback ul { margin: 7px 0 0; padding-left: 18px; }

.mh-live-panel {
    margin-top: 34px;
    padding: 26px;
    border-radius: 22px;
    background: #0f172a;
    color: #fff;
}
.mh-live-panel .mh-section-heading p { color: #94a3b8; }
.mh-live-commands,
.mh-live-loads { display: flex; flex-wrap: wrap; gap: 12px; }
.mh-live-commands { margin-bottom: 18px; }
.mh-live-command {
    min-width: 170px;
    padding: 12px 14px;
    border: 1px solid #334155;
    border-radius: 12px;
    background: #1e293b;
    color: #fff;
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.mh-live-command strong,
.mh-live-command small { display: block; }
.mh-live-command small { margin-top: 4px; color: #94a3b8; }

.mh-live-load {
    min-width: 220px;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 13px;
    border: 1px solid #334155;
    border-radius: 13px;
    background: #111827;
}
.mh-live-load.is-on {
    border-color: #facc15;
    box-shadow: 0 0 30px rgba(250,204,21,.16);
}
.mh-live-load-icon { font-size: 1.6rem; filter: grayscale(1); }
.mh-live-load.is-on .mh-live-load-icon { filter: none; }
.mh-live-load strong,
.mh-live-load small { display: block; }
.mh-live-load small { color: #94a3b8; margin-top: 3px; }
.mh-state-pill {
    margin-left: auto;
    padding: 4px 7px;
    border-radius: 99px;
    background: #334155;
    color: #cbd5e1;
    font-size: .72rem;
    font-weight: 900;
}
.mh-live-load.is-on .mh-state-pill { background: #fde047; color: #713f12; }

.mh-live-message {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 11px;
    background: #1e293b;
    color: #cbd5e1;
}
.mh-live-message.is-success { color: #a7f3d0; }
.mh-live-message.is-error { color: #fecaca; }

/* Administration */
.mh-admin-grid {
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    gap: 20px;
    margin-top: 24px;
}
.mh-admin-card h2 { margin-top: 0; }
.mh-admin-form { display: grid; gap: 15px; }
.mh-form-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mh-form-row:first-of-type { grid-template-columns: 1.4fr 1fr; }
.mh-codearea {
    min-height: 190px !important;
    font-family: Consolas, Monaco, monospace !important;
    font-size: .84rem !important;
    line-height: 1.5;
}
.mh-checkbox { display: flex; gap: 9px; align-items: center; font-weight: 700; }
.mh-checkbox input { width: auto; min-height: auto; }
.mh-admin-list { display: grid; gap: 10px; }
.mh-admin-item {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--mh-border);
    border-radius: 12px;
}
.mh-admin-item strong,
.mh-admin-item small { display: block; }
.mh-admin-item small { margin-top: 3px; color: #64748b; }
.mh-admin-actions { display: flex; gap: 5px; margin-left: auto; }
.mh-admin-actions form { margin: 0; }
.mh-icon-btn {
    display: inline-flex;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 9px;
    background: #eff6ff;
    text-decoration: none;
    cursor: pointer;
}
.mh-icon-btn.mh-danger { background: #fef2f2; }

.mh-config-admin { margin-top: 20px; }
.mh-config-table { display: grid; gap: 9px; margin-top: 15px; }
.mh-config-row {
    display: grid;
    grid-template-columns: 70px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #edf2f7;
}
.mh-config-row small { display: block; margin-top: 3px; color: #64748b; }

@media (max-width: 980px) {
    .mh-hero { grid-template-columns: 1fr; padding: 36px; }
    .mh-card-grid-4,
    .mh-rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mh-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mh-sim-layout { grid-template-columns: 1fr; }
    .mh-palette-panel { position: static; }
    .mh-admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    .mh-page { padding: 18px 12px 40px; }
    .mh-hero { padding: 26px 20px; border-radius: 22px; }
    .mh-card-grid,
    .mh-card-grid-4,
    .mh-rule-grid,
    .mh-workspace { grid-template-columns: 1fr; }
    .mh-sim-header { display: block; }
    .mh-example-select { min-width: 0; margin-top: 20px; }
    .mh-mission { grid-template-columns: 1fr; }
    .mh-form-row,
    .mh-form-row:first-of-type { grid-template-columns: 1fr; }
    .mh-teacher-box { display: block; }
    .mh-teacher-box .mh-btn { margin-top: 18px; }
}
