:root {
  --font: "Segoe UI Variable", "Avenir Next", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --bg: #eef1f4;
  --bg-deep: #e4e9ef;
  --panel: #fbfcfd;
  --panel-raise: #ffffff;
  --text: #12151a;
  --muted: #5c6570;
  --line: #d5dbe3;
  --accent: #0f6b63;
  --accent-hover: #0c5852;
  --accent-soft: #e4f3f1;
  --accent-ink: #084842;
  --shadow: 0 18px 40px rgba(18, 28, 40, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; }

.shell {
  min-height: 100dvh;
  background:
    linear-gradient(180deg, #f5f7fa 0%, var(--bg) 42%, var(--bg-deep) 100%);
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
}

.brand-mark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-sub {
  font-size: 13px;
  color: var(--muted);
}

.nav-link {
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-ink);
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  transition: transform 0.15s ease, background 0.15s ease;
}

.nav-link:hover { background: #d7ebe8; }
.nav-link:active { transform: translateY(1px); }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 24px 56px;
}

.hero-split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: end;
  min-height: calc(100dvh - 140px);
  padding-top: 28px;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: -0.045em;
  max-width: 10ch;
}

.hero-copy p {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
  max-width: 34ch;
}

.hero-visual {
  position: relative;
  min-height: 280px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(145deg, #0f6b63 0%, #14635c 38%, #1b3a45 100%);
  box-shadow: var(--shadow);
}

.hero-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.22), transparent 42%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.08), transparent 40%),
    repeating-linear-gradient(
      -18deg,
      transparent 0 14px,
      rgba(255, 255, 255, 0.04) 14px 15px
    );
}

.hero-visual-label {
  position: absolute;
  left: 22px;
  bottom: 22px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  z-index: 1;
}

.tools {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 14px;
}

.tool {
  display: grid;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  background: var(--panel-raise);
  border: 1px solid rgba(213, 219, 227, 0.9);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.18s ease;
}

.tool:hover {
  transform: translateY(-2px);
  border-color: #b9c8c5;
}

.tool:active { transform: translateY(0) scale(0.99); }

.tool-kicker {
  font-size: 12px;
  font-weight: 650;
  color: var(--accent);
}

.tool h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.tool p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  max-width: 42ch;
}

.tool-cta {
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--accent-ink);
}

.tool.featured {
  background:
    linear-gradient(180deg, #ffffff 0%, #f4faf9 100%);
}

.foot {
  margin-top: 28px;
  color: var(--muted);
  font-size: 13px;
}

/* Tool pages */
.panel-page {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 24px 48px;
}

.tool-hero {
  margin: 18px 0 22px;
}

.tool-hero h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.6vw, 2.15rem);
  letter-spacing: -0.035em;
}

.tool-hero p {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-raise);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(18, 28, 40, 0.04);
}

.panel + .panel { margin-top: 14px; }

.panel h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 650;
  color: var(--accent-ink);
}

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

.full { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  font-weight: 550;
  color: #2a313a;
}

input, textarea, select {
  border: 1px solid #c9d1db;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 107, 99, 0.14);
}

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

.inline-control {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px dashed #b7d4cf;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-ink);
}

.inline-control input { width: 16px; height: 16px; }

.actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.note { color: var(--muted); font-size: 12.5px; }

.sig-local {
  margin-top: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: #f7f9fa;
  padding: 0 12px;
}

.sig-local > summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sig-local > summary::-webkit-details-marker { display: none; }

.sig-local-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e8edf2;
  color: #5c6570;
}

.sig-local-badge.is-on {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.sig-local-body {
  padding: 0 0 14px;
}

.sig-local-help {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--muted);
  max-width: 52ch;
}

.sig-local-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sig-local-file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sig-local-preview {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  max-width: 240px;
}

.sig-local-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 90px;
  object-fit: contain;
}

.sig-local-divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.cache-refresh-btn {
  width: 100%;
  margin-top: 10px;
  font-size: 12.5px;
  padding: 10px 12px;
}

.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 107, 99, 0.25);
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.65; cursor: wait; }

.btn-secondary {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}

.btn-secondary:hover { background: #f5f7f9; }

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

.total-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f7f9fb;
  padding: 12px;
}

.total-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.total-card strong {
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

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

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

th, td { padding: 8px 6px; vertical-align: top; }

th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
  border-bottom: 1px solid var(--line);
}

td input, td select {
  width: 100%;
  padding: 9px 10px;
}

.row-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #fde8e8;
  color: #b42318;
  font-weight: 700;
  cursor: pointer;
}

.row-actions .row-btn {
  width: auto;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 650;
}

.row-action-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dup-btn {
  background: var(--accent-soft) !important;
  color: var(--accent-ink) !important;
}

.col-move { width: 92px; }

.move-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.move-handle,
.move-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #3a4550;
  border-radius: 8px;
  height: 30px;
  min-width: 28px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.move-handle {
  cursor: grab;
  letter-spacing: -2px;
  color: var(--muted);
}

.move-handle:active { cursor: grabbing; }

.move-btn:hover,
.move-handle:hover {
  background: var(--accent-soft);
  border-color: #b7d4cf;
}

.frais-row.is-dragging {
  opacity: 0.45;
}

.frais-row.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}


.toolbar { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

.km-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.km-fields input {
  min-width: 0;
}

.line-ttc.is-computed {
  background: #f3f6f5;
  color: var(--accent-ink);
  font-weight: 650;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}

.flatpickr-day.inRange {
  background: var(--accent-soft) !important;
  border-color: var(--accent-soft) !important;
  color: var(--accent-ink) !important;
}

@media (prefers-reduced-motion: reduce) {
  .tool, .nav-link, .btn, .tool-row { transition: none; }
  .tool:hover, .nav-link:hover, .tool-row:hover { transform: none; }
}

@media (max-width: 820px) {
  .hero-split,
  .tools,
  .grid,
  .totals {
    grid-template-columns: 1fr;
  }

  .hero-split {
    min-height: auto;
    padding-top: 18px;
  }

  .hero-visual { min-height: 180px; }

  .topbar {
    height: auto;
    min-height: 56px;
    padding: 10px 16px;
    flex-wrap: wrap;
  }

  .page,
  .panel-page {
    padding-left: 16px;
    padding-right: 16px;
  }

  .panel {
    padding: 14px;
  }

  .tool-hero h1 {
    font-size: 1.45rem;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn,
  .btn-primary,
  .btn-secondary {
    width: 100%;
    text-align: center;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  table thead {
    display: none;
  }

  table tbody tr {
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 12px;
    margin-bottom: 10px;
  }

  table tbody td {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    padding: 0;
  }

  table tbody td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 650;
    color: var(--muted);
  }

  table tbody td.actions,
  table tbody td.row-actions,
  table tbody td.move-cell {
    width: auto;
    grid-template-columns: 1fr;
  }

  table tbody td.actions::before,
  table tbody td.row-actions::before {
    display: none;
  }

  table tbody td.actions .row-btn,
  table tbody td.row-actions .row-btn {
    width: 100%;
  }

  .row-action-btns {
    flex-direction: row;
  }

  .move-controls {
    width: 100%;
  }

  .move-handle,
  .move-btn {
    flex: 1;
    height: 36px;
  }
}

@media (max-width: 480px) {
  .brand-sub {
    display: none;
  }

  .inline-control {
    align-items: flex-start;
  }

  table tbody td {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

