:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d7dde8;
  --soft: #f7f9fc;
  --primary: #2457c5;
  --primary-dark: #173f91;
  --accent: #0f8b6f;
  --warning: #b77816;
  --danger: #b42318;
  --module: #fdfefe;
  --shadow: 0 20px 55px rgba(15, 23, 42, 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(36, 87, 197, 0.08), rgba(15, 139, 111, 0.05) 42%, transparent),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid rgba(215, 221, 232, 0.9);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
}

.eyebrow,
.sheet-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.button:hover {
  border-color: #aeb8ca;
  background: #f8fafc;
}

.button:active {
  transform: translateY(1px);
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.button.ghost {
  color: var(--danger);
}

.button.full {
  width: 100%;
}

.button.small {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 0.83rem;
}

.button.icon {
  width: 32px;
  min-height: 32px;
  padding: 0;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.side-panel {
  align-self: start;
  position: sticky;
  top: 88px;
  display: grid;
  gap: 14px;
}

.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: #3a4354;
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 87, 197, 0.14);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
  text-align: left;
}

.preset-button strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.84rem;
}

.preset-button span {
  color: var(--muted);
  font-size: 0.75rem;
}

.preset-button:hover {
  border-color: var(--primary);
  background: #f5f8ff;
}

.sheet-wrap {
  min-width: 0;
  overflow: auto;
}

.sheet {
  width: min(100%, 1440px);
  min-height: calc(100vh - 122px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.sheet-header {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(420px, 0.85fr);
  gap: 20px;
  align-items: start;
  padding-bottom: 16px;
  border-bottom: 2px solid #172033;
}

.sheet-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.1rem);
}

.meta-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.meta-list div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--soft);
}

.meta-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-list dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.rows {
  display: grid;
  gap: 18px;
  padding: 20px 0;
}

.board-row {
  border: 1px solid #bec7d6;
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  background: #fbfcff;
}

.row-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.row-title {
  display: grid;
  grid-template-columns: minmax(150px, 240px) minmax(140px, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.row-title input {
  min-height: 36px;
  padding: 7px 9px;
  font-weight: 850;
}

.row-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.row-content {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.differential {
  min-height: 220px;
  border: 2px solid #18263a;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #ffffff, #f6faf8);
  overflow: hidden;
}

.module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  background: #172033;
  color: #ffffff;
  font-weight: 850;
}

.module-head span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.76rem;
}

.differential-body {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.device-zone {
  min-width: 0;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.device {
  min-width: 0;
  border: 1px solid #aeb8ca;
  border-top: 7px solid var(--warning);
  border-radius: 8px;
  background: var(--module);
  overflow: hidden;
}

.device[data-kind="lumiere"] {
  border-top-color: #d9a441;
}

.device[data-kind="prise"] {
  border-top-color: #2457c5;
}

.device[data-kind="specialise"] {
  border-top-color: #b42318;
}

.device[data-kind="chauffage"] {
  border-top-color: #7a4cc2;
}

.device[data-kind="communication"] {
  border-top-color: #0f8b6f;
}

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.device-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.device-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.device-body {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.device-body label,
.differential-body label {
  margin-bottom: 0;
  font-size: 0.72rem;
}

.device-body input,
.device-body select,
.device-body textarea,
.differential-body input,
.differential-body select {
  min-height: 34px;
  padding: 6px 7px;
  border-radius: 6px;
  font-size: 0.84rem;
}

.empty-row {
  display: grid;
  min-height: 216px;
  place-items: center;
  border: 1px dashed #aeb8ca;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-weight: 750;
}

.summary {
  border-top: 2px solid #172033;
  padding-top: 16px;
}

.print-compact {
  display: none;
}

.summary-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.summary-heading h2 {
  margin-bottom: 8px;
}

.summary-heading span {
  color: var(--muted);
  font-weight: 800;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.84rem;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #edf2fb;
  color: #24324a;
  font-size: 0.74rem;
  text-transform: uppercase;
}

td {
  overflow-wrap: anywhere;
}

@media (max-width: 1040px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sheet-header {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .row-toolbar,
  .summary-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .row-actions {
    justify-content: stretch;
  }

  .top-actions .button,
  .row-actions .button {
    flex: 1 1 auto;
  }

  .main-layout {
    padding: 10px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .sheet {
    padding: 14px;
  }

  .row-title,
  .row-content,
  .meta-list {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  :root {
    --line: #9aa4b5;
  }

  body {
    background: #ffffff;
    color: #000000;
  }

  .no-print,
  .row-actions,
  .device-actions {
    display: none !important;
  }

  .main-layout,
  .sheet-wrap,
  .app-shell {
    display: block;
    padding: 0;
    overflow: visible;
  }

  .sheet {
    width: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .sheet-header {
    grid-template-columns: 1fr 1.2fr;
    gap: 12px;
    padding-bottom: 6px;
  }

  .sheet-kicker {
    display: none;
  }

  .sheet-header h2 {
    font-size: 15pt;
  }

  .meta-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .meta-list div {
    border-radius: 0;
    padding: 3px 5px;
  }

  .meta-list dt {
    font-size: 6.5pt;
  }

  .meta-list dd {
    font-size: 8pt;
  }

  .rows {
    display: none !important;
  }

  .summary {
    display: none !important;
  }

  .print-compact {
    display: grid;
    gap: 3mm;
    padding-top: 4mm;
  }

  .print-row {
    display: grid;
    grid-template-columns: 22mm minmax(0, 1fr);
    gap: 2mm;
    align-items: stretch;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-row h3 {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    border: 1px solid #000000;
    background: #f2f2f2;
    font-size: 8pt;
    line-height: 1.1;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .print-modules {
    display: flex;
    flex-wrap: nowrap;
    gap: 1mm;
    min-width: 0;
  }

  .print-module {
    display: grid;
    grid-template-rows: auto auto minmax(6mm, 1fr) auto;
    flex: 1 1 0;
    min-width: 0;
    min-height: 18mm;
    border: 1px solid #000000;
    padding: 1.2mm;
    background: #ffffff;
    overflow-wrap: anywhere;
    line-height: 1.08;
  }

  .print-differential {
    flex: 0.85 1 0;
    background: #f7f7f7;
  }

  .print-empty {
    background: #fafafa;
  }

  .print-module strong {
    display: block;
    font-size: 7.3pt;
    font-weight: 800;
  }

  .print-module small {
    display: block;
    margin-top: 0.5mm;
    color: #000000;
    font-size: 6.6pt;
    font-weight: 700;
  }

  .print-module span {
    display: block;
    margin-top: 1mm;
    font-size: 6.3pt;
  }

  .print-module em {
    display: block;
    align-self: end;
    margin-top: 1mm;
    color: #000000;
    font-size: 8.2pt;
    font-style: normal;
    font-weight: 850;
    text-align: right;
  }

  input,
  select,
  textarea {
    color: #000000;
  }

  label {
    gap: 1px;
  }

  table {
    min-width: 0;
    font-size: 0.72rem;
  }

  th,
  td {
    padding: 5px;
  }
}
