:root {
  --ink: #303040;
  --muted: #5b6478;
  --line: #c8e0f0;
  --paper: #f7fbfd;
  --white: #ffffff;
  --teal: #28b8c0;
  --teal-dark: #307080;
  --navy: #303040;
  --slate: #404860;
  --ice: #c8e0f0;
  --red: #9b3e52;
  --green: #287a5d;
  --amber: #a87321;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 72px;
  padding: 14px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid rgba(48, 48, 64, 0.12);
  background: rgba(247, 251, 253, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--teal);
  color: var(--white);
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; }

.top-actions, .detail-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button, button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  background: var(--white);
}

.button:disabled, button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button.primary, button[type="submit"], #copyDraft {
  background: var(--teal);
  color: #101822;
}

.button.ghost, .icon-button {
  border-color: var(--line);
  background: var(--white);
}

.copy-status {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.copy-status.success { color: var(--green); }
.copy-status.error { color: var(--red); }

.icon-button {
  width: 42px;
  padding: 0;
}

.reset-button {
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.76fr) minmax(520px, 1.55fr) minmax(320px, 0.88fr);
  gap: 18px;
  padding: 18px;
}

.side-panel, .main-panel, .detail-panel, .mini-panel, .quick-add, .table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.side-panel, .detail-panel {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 18px;
}

.identity {
  position: relative;
  overflow: hidden;
  min-height: 240px;
  padding: 22px;
  border-radius: 8px;
  color: var(--white);
  background:
    linear-gradient(135deg, rgba(48, 48, 64, 0.96), rgba(48, 48, 64, 0.82)),
    linear-gradient(135deg, var(--navy), var(--teal-dark));
}

.identity::after {
  content: "";
  position: absolute;
  right: -58px;
  bottom: -34px;
  width: 220px;
  height: 118px;
  transform: skewX(-36deg);
  background: var(--teal);
  opacity: 0.9;
}

.identity h1 {
  position: relative;
  z-index: 1;
  max-width: 360px;
  margin: 0;
  font-size: clamp(32px, 4vw, 52px);
  line-height: 0.98;
}

.identity p:not(.eyebrow) {
  position: relative;
  z-index: 1;
  max-width: 390px;
  margin: 18px 0 0;
  color: rgba(255, 255, 255, 0.86);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.identity .eyebrow { color: var(--ice); }

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

.kpi {
  min-height: 102px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1;
}

.mini-panel { padding: 16px; }

.settings-grid {
  display: grid;
  gap: 10px;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.invoice-readiness .panel-head {
  align-items: center;
}

#invoiceReadinessScore {
  color: var(--teal-dark);
  font-size: 28px;
}

.readiness-bar {
  height: 10px;
  margin: 14px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4f2f7;
}

.readiness-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 180ms ease;
}

.checklist {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 10px;
  border: 1px solid #dceaf2;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-transform: none;
}

.checklist input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
  accent-color: var(--teal);
}

.panel-head, .toolbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.panel-head h2, .toolbar h2 {
  margin: 0;
  font-size: 22px;
}

#recapDate {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.recap-list, #activityLog {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.recap-list li, #activityLog li {
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef7fb;
  color: var(--slate);
  font-size: 14px;
}

.main-panel {
  min-width: 0;
  padding: 18px;
}

.toolbar { margin-bottom: 16px; }

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf7fb;
}

.segmented button {
  min-height: 36px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.segmented .is-active {
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 5px 18px rgba(48, 48, 64, 0.08);
}

.quick-add {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--white);
}

textarea {
  resize: vertical;
  min-height: 230px;
  line-height: 1.45;
  text-transform: none;
}

.table-wrap { overflow: auto; }

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

th, td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.is-selected { background: #eef7fb; }

.client-cell strong, .client-cell span { display: block; }
.client-cell span, .muted { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 5px 9px;
  border-radius: 8px;
  background: #eef7fb;
  color: var(--slate);
  font-size: 13px;
  font-weight: 800;
}

.badge.due { background: #ffeef2; color: var(--red); }
.badge.hot { background: #e9faf4; color: var(--green); }
.badge.invoice { background: #fff5df; color: var(--amber); }

.score {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 8px;
  background: #eef7fb;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.detail-stats div {
  min-height: 86px;
  padding: 14px;
  background: var(--white);
}

.detail-stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-stats dd {
  margin: 8px 0 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.draft-box {
  display: grid;
  gap: 8px;
}

.activity h3 { margin: 0; }

.detail-panel.is-empty #mailtoDraft {
  pointer-events: none;
  opacity: 0.58;
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(260px, 0.9fr) minmax(520px, 1.2fr); }
  .detail-panel { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .app-shell, .panel-head, .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .quick-add { grid-template-columns: 1fr; }

  .segmented {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-actions, .detail-actions { align-items: stretch; }
  .top-actions .button, .top-actions button, .detail-actions .button, .detail-actions button { flex: 1; }
  .kpi-grid, .detail-stats { grid-template-columns: 1fr; }

  .reset-button {
    flex: 0 0 auto;
    min-width: 0;
    padding-inline: 10px;
    font-size: 13px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    padding: 12px;
    border: 1px solid #dceaf2;
    border-radius: 8px;
    background: var(--white);
  }

  tbody tr.is-selected {
    box-shadow: inset 4px 0 0 var(--teal);
  }

  td {
    display: grid;
    grid-template-columns: minmax(104px, 0.36fr) minmax(0, 1fr);
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid #edf4f8;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  td:nth-child(1)::before { content: "Document"; }
  td:nth-child(2)::before { content: "Client / tiers"; }
  td:nth-child(3)::before { content: "Statut"; }
  td:nth-child(4)::before { content: "Montant"; }
  td:nth-child(5)::before { content: "Action"; }
}

@media (max-width: 520px) {
  .identity { min-height: 210px; }
  .brand span:last-child { min-width: 0; }
  .brand strong, .brand small {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
