﻿:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #111827;
  --muted: #566074;
  --line: #d5deea;
  --brand: #204ecf;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background: radial-gradient(circle at 20% 20%, #d4def8 0%, #f4f7fb 35%), linear-gradient(145deg, #f4f7fb, #eef3fb);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.shell {
  max-width: 1300px;
  margin: 24px auto;
  padding: 0 16px 30px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 12px 24px rgba(34, 46, 70, 0.08);
  border-radius: var(--radius);
}

.auth-card {
  max-width: 420px;
  margin: 48px auto;
  padding: 24px;
}

h1,
h2,
h3 {
  margin: 0 0 8px;
}

p,
small {
  color: var(--muted);
}

.hint-inline {
  align-self: center;
  display: block;
  margin-top: 0;
}

form {
  margin-top: 14px;
}

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

input,
textarea,
select {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: white;
}

input,
select,
button {
  min-height: 40px;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  padding: 10px 12px;
  cursor: pointer;
}

button.secondary {
  background: #e9eefb;
  color: #1f3f96;
}

button:hover {
  filter: brightness(0.98);
}

.hidden {
  display: none;
}

.topbar {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}

.left-col,
.main-col {
  padding: 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-toggle-row {
  display: flex;
  justify-content: flex-end;
}

.section-actions {
  margin-top: 10px;
}

#invoice-settings-toggle {
  min-width: 170px;
}

#invoice-settings-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#invoice-settings-panel.hidden {
  display: none;
}

#company-form-panel.hidden {
  display: none;
}

.row-2,
.row-3,
.row-4 {
  display: grid;
  gap: 10px;
}

.row-2 {
  grid-template-columns: 1fr 1fr;
}

.row-3 {
  grid-template-columns: repeat(3, 1fr);
}

.row-4 {
  grid-template-columns: repeat(4, 1fr);
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0;
  padding: 12px;
}

legend {
  color: #1f3f96;
  font-weight: 700;
  padding: 0 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}

th,
td {
  border-bottom: 1px solid #edf1f8;
  padding: 6px;
  text-align: left;
  font-size: 0.94rem;
}

td input {
  margin: 0;
}

td textarea,
td select {
  margin: 0;
}

.invoice-lines {
  table-layout: fixed;
}

.col-desc {
  width: 46%;
}

.col-qty {
  width: 11%;
}

.col-price {
  width: 13%;
}

.col-tax {
  width: 10%;
}

.col-total {
  width: 14%;
}

.col-act {
  width: 6%;
}

.line-description {
  min-height: 40px;
  resize: none;
  overflow: hidden;
}

.line-actions {
  width: 32px;
  text-align: center;
}

.remove-line {
  padding: 6px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #fde2e2;
  color: #8a1f1f;
}

.totals {
  background: #f7faff;
  border: 1px solid #e1eaf8;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ttc {
  color: #13317f;
  font-weight: 700;
}

.preview {
  margin-top: 14px;
  border-radius: 14px;
  border: 1px solid #e9edf5;
  background: #fff;
  overflow: hidden;
}

.preview-head {
  padding: 12px;
  color: white;
}

.preview-body {
  padding: 12px;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.preview table {
  margin-top: 6px;
}

.preview-legal {
  margin-top: 14px;
  padding-top: 8px;
  border-top: 1px solid #d6deed;
  font-size: 0.84rem;
  color: #475569;
  line-height: 1.4;
}

.hint {
  display: inline-block;
  margin-top: 10px;
}

@media (max-width: 1120px) {
  .shell {
    margin: 14px auto;
    padding: 0 12px 20px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .row-4 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .shell {
    margin: 10px auto;
    padding: 0 10px 16px;
  }

  .left-col,
  .main-col {
    padding: 12px;
  }

  input,
  textarea,
  select,
  button {
    font-size: 16px;
  }

  .row-2,
  .row-3,
  .row-4,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .topbar button {
    width: 100%;
  }

  .settings-toggle-row {
    justify-content: stretch;
  }

  .section-actions {
    grid-template-columns: 1fr;
  }

  #invoice-settings-toggle {
    width: 100%;
  }

  .invoice-lines {
    table-layout: auto;
  }

  .invoice-lines colgroup,
  .invoice-lines thead {
    display: none;
  }

  .invoice-lines,
  .invoice-lines tbody,
  .invoice-lines tr,
  .invoice-lines td {
    display: block;
    width: 100%;
  }

  .invoice-lines tr {
    border: 1px solid #e6edf7;
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 10px;
    background: #fff;
  }

  .invoice-lines td {
    border: 0;
    padding: 4px 0;
  }

  .invoice-lines td:not(.line-actions) {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 8px;
    align-items: center;
  }

  .invoice-lines td:nth-child(1)::before { content: "Description"; }
  .invoice-lines td:nth-child(2)::before { content: "Qte"; }
  .invoice-lines td:nth-child(3)::before { content: "PU HT"; }
  .invoice-lines td:nth-child(4)::before { content: "TVA"; }
  .invoice-lines td:nth-child(5)::before { content: "Total HT"; }

  .invoice-lines td::before {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
  }

  .invoice-lines td.line-actions {
    text-align: right;
    padding-top: 6px;
  }

  .preview {
    overflow: auto;
  }

  .preview table {
    min-width: 0;
  }

  .preview th,
  .preview td {
    font-size: 0.86rem;
    padding: 5px 4px;
  }

  .preview img {
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 430px) {
  .shell {
    padding-left: calc(10px + env(safe-area-inset-left));
    padding-right: calc(10px + env(safe-area-inset-right));
  }

  .auth-card {
    margin: 20px auto;
    padding: 16px;
  }

  .card {
    border-radius: 12px;
  }

  .topbar,
  .left-col,
  .main-col {
    padding: 10px;
  }

  .totals {
    padding: 8px;
  }
}
