:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --text: #1d232c;
  --muted: #6c7480;
  --line: #dfe3e8;
  --dark: #15181d;
  --dark-2: #20242b;
  --accent: #d78219;
  --accent-dark: #b7680d;
  --danger: #b32d2e;
  --success: #2c8a55;
  --shadow: 0 14px 40px rgba(21, 24, 29, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 255px minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, var(--dark), #0f1115);
  color: #fff;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #111;
  font-weight: 900;
  font-size: 24px;
}
.brand strong { display: block; letter-spacing: 1px; font-size: 18px; }
.brand span { display: block; color: #aeb5bf; font-size: 12px; margin-top: 3px; }

.main-nav { display: grid; gap: 8px; }
.nav-btn {
  border: 0;
  background: transparent;
  color: #c8cdd5;
  text-align: left;
  padding: 13px 14px;
  border-radius: 10px;
  transition: .18s ease;
}
.nav-btn:hover, .nav-btn.active { background: var(--dark-2); color: #fff; }
.nav-btn.active { box-shadow: inset 3px 0 var(--accent); }

.sidebar-footer {
  margin-top: auto;
  color: #aeb5bf;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot { width: 8px; height: 8px; background: #4ed17d; border-radius: 50%; box-shadow: 0 0 0 4px rgba(78,209,125,.12); }

.main-content { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.topbar h1 { margin: 0; font-size: 28px; }
.topbar p { margin: 6px 0 0; color: var(--muted); }

.view { display: none; }
.active-view { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.stat-card { padding: 22px; }
.stat-card span { color: var(--muted); font-size: 14px; }
.stat-card strong { display: block; font-size: 30px; margin-top: 10px; }

.panel-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.panel { padding: 22px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.panel-header h2 { margin: 0; font-size: 20px; }
.panel-header p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.quick-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  text-align: left;
  background: #fafbfc;
  transition: .18s ease;
}
.quick-card:hover { transform: translateY(-2px); border-color: #c3c8ce; }
.quick-card strong, .quick-card small { display: block; }
.quick-card strong { margin-top: 14px; font-size: 16px; }
.quick-card small { margin-top: 7px; color: var(--muted); line-height: 1.45; }
.quick-icon { color: var(--accent-dark); font-weight: 800; }

.two-column-layout { display: grid; grid-template-columns: 350px minmax(0, 1fr); gap: 18px; align-items: start; }
.form-panel { position: sticky; top: 24px; }

label { display: grid; gap: 7px; font-weight: 650; font-size: 13px; color: #353b44; }
form label + label { margin-top: 16px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd5dc;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(215,130,25,.13); }
textarea { resize: vertical; }

.form-actions, .quote-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 750;
}
.btn-primary { background: var(--accent); color: #17120b; }
.btn-primary:hover { background: #e3942d; }
.btn-secondary { background: #e9edf1; color: #30353c; }
.btn-dark { background: var(--dark-2); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 7px 10px; font-size: 12px; }

.toolbar-header { align-items: center; }
.search-input { max-width: 280px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #5d6672; background: #f7f8fa; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.numeric { text-align: right; white-space: nowrap; }
.actions-col { width: 145px; text-align: right; }
.action-buttons { display: flex; justify-content: flex-end; gap: 7px; }
.empty-row { text-align: center; color: var(--muted); padding: 30px; }

.quote-panel { max-width: 1280px; margin: 0 auto; }
.quote-heading { align-items: center; }
.quote-number-box { background: #f4f5f7; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 150px; text-align: right; }
.quote-number-box span { display: block; color: var(--muted); font-size: 11px; }
.quote-number-box strong { display: block; margin-top: 3px; font-size: 17px; }
.quote-meta-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.quote-meta-grid label + label { margin-top: 0; }
.line-adder { display: grid; grid-template-columns: minmax(280px, 1fr) 130px auto; gap: 12px; align-items: end; padding: 16px; background: #f8f9fb; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; }
.quote-table-wrap { min-height: 190px; }
.quote-bottom { display: grid; grid-template-columns: 1fr 330px; gap: 20px; margin-top: 18px; align-items: start; }
.notes-field textarea { min-height: 125px; }
.totals-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.totals-card > div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.totals-card > div:last-child { border-bottom: 0; }
.totals-card span { color: var(--muted); }
.totals-card .grand-total { background: var(--dark-2); color: #fff; }
.totals-card .grand-total span { color: #d7dbe1; }

.backup-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.info-box { background: #fff5e7; border-left: 4px solid var(--accent); padding: 14px; line-height: 1.5; color: #624416; }
.file-label { margin-bottom: 18px; }
.danger-panel { border-color: #efc8c9; }

.empty-state { color: var(--muted); padding: 22px 0; }
.recent-item { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: 0; }
.recent-item strong, .recent-item span { display: block; }
.recent-item span { color: var(--muted); font-size: 12px; margin-top: 4px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--dark-2);
  color: #fff;
  padding: 13px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .2s ease;
  max-width: 380px;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.hidden { display: none !important; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .two-column-layout { grid-template-columns: 1fr; }
  .form-panel { position: static; }
  .panel-grid, .backup-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; }
  .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-footer { display: none; }
  .main-content { padding: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .stats-grid, .quick-actions, .quote-meta-grid, .line-adder, .quote-bottom { grid-template-columns: 1fr; }
  .toolbar-header { align-items: stretch; flex-direction: column; }
  .search-input { max-width: none; }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .line-adder, .article-picker, .quote-actions, .actions-col, #quote-lines-body .delete-line { display: none !important; }
  .app-shell { display: block; }
  .main-content { padding: 0; }
  .view { display: none !important; }
  #view-quote { display: block !important; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  input, select, textarea { border: 0; padding: 0; box-shadow: none !important; }
  .quote-meta-grid { grid-template-columns: 2fr 1fr 1fr; }
  .quote-bottom { grid-template-columns: 1fr 300px; }
}

/* Version 0.2 — recherche d’articles dans les devis */
.article-picker {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8f9fb;
  padding: 16px;
  margin-bottom: 16px;
}
.article-picker-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 180px;
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
}
.article-search-results {
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  background: #fff;
  max-height: 390px;
  overflow-y: auto;
}
.article-result-head,
.article-result-row {
  display: grid;
  grid-template-columns: minmax(130px, .7fr) minmax(280px, 2fr) minmax(100px, .55fr) 90px;
  gap: 12px;
  align-items: center;
  padding: 11px 13px;
}
.article-result-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f2f5;
  color: #5d6672;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
}
.article-result-row { border-bottom: 1px solid var(--line); }
.article-result-row:last-of-type { border-bottom: 0; }
.article-result-row:hover { background: #fffaf3; }
.article-result-row .btn { justify-self: end; }
.article-result-empty,
.article-result-hint {
  padding: 18px;
  text-align: center;
  color: var(--muted);
}
.article-result-hint {
  padding: 10px 14px;
  font-size: 12px;
  background: #f7f8fa;
  border-top: 1px solid var(--line);
}

/* Version 0.2 — module de mise à jour */
.update-grid { grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); }
.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  background: #fff2df;
  color: #8a4d08;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.update-steps { display: grid; gap: 12px; margin-bottom: 18px; }
.update-steps > div { display: grid; grid-template-columns: 34px 1fr; gap: 11px; align-items: center; }
.update-steps strong {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--dark-2);
  color: #fff;
}
.update-steps span { line-height: 1.45; }
.check-list { margin: 0 0 22px; padding: 0; list-style: none; display: grid; gap: 11px; }
.check-list li { position: relative; padding-left: 28px; line-height: 1.45; }
.check-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e3f5ea;
  color: var(--success);
  font-weight: 900;
  font-size: 12px;
}

@media (max-width: 1050px) {
  .update-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .article-picker-toolbar,
  .article-result-head,
  .article-result-row { grid-template-columns: 1fr; }
  .article-result-head { display: none; }
  .article-result-row { gap: 7px; padding: 14px; }
  .article-result-row .numeric { text-align: left; }
  .article-result-row .btn { justify-self: stretch; }
}

/* Version 0.3 — édition serveur, tablette et mode hors connexion */
body { padding-top: 34px; }
.connection-banner {
  position: fixed;
  inset: 0 0 auto 0;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .01em;
  background: #fff0d8;
  color: #74430d;
  border-bottom: 1px solid #e8c995;
}
.connection-banner.online { background: #e9f7ef; color: #1f6d43; border-bottom-color: #b7dfc8; }
.connection-banner.offline { background: #fff0d8; color: #74430d; }
.sidebar { top: 34px; height: calc(100vh - 34px); }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sync-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  background: #edf0f3;
  color: #4f5863;
}
.sync-chip.online { background: #e5f5eb; color: #1f6d43; }
.sync-chip.dirty { background: #fff0d8; color: #74430d; }
.install-button {
  width: 100%;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  color: #fff;
  padding: 11px 12px;
  font-weight: 800;
}
.install-button:hover { background: rgba(255,255,255,.14); }
.four-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card small { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.three-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sync-layout { display: grid; grid-template-columns: minmax(300px,.75fr) minmax(480px,1.5fr); gap: 18px; align-items: start; }
.sync-main-panel { grid-row: span 2; }
.install-panel { grid-column: 1; }
.login-grid { display: grid; gap: 14px; }
.login-grid label + label { margin-top: 0; }
.connected-user { padding: 13px 15px; margin-bottom: 12px; background: #edf9f2; border-left: 4px solid var(--success); color: #1b6039; }
.sync-cards { display: grid; gap: 14px; }
.sync-action-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fafbfc;
}
.sync-action-card p { margin: 5px 0 0; color: var(--muted); line-height: 1.45; font-size: 13px; }
.sync-number {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--dark-2);
  color: #fff;
  font-weight: 900;
}
.sync-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; margin-top: 18px; }
.sync-summary > div { border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: #fff; }
.sync-summary span, .sync-summary strong { display: block; }
.sync-summary span { color: var(--muted); font-size: 12px; }
.sync-summary strong { margin-top: 7px; font-size: 15px; }
.warning-box { margin-top: 18px; padding: 14px 15px; border-left: 4px solid #d29a16; background: #fff8e7; color: #624416; line-height: 1.5; }
.info-box a { color: inherit; font-weight: 850; }
.install-steps { margin: 0; padding-left: 22px; display: grid; gap: 10px; line-height: 1.45; }
.small-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 14px 0 0; }
.stacked-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.button-link { display: inline-block; text-decoration: none; }
.server-backup-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 1180px) {
  .four-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three-actions { grid-template-columns: 1fr; }
  .sync-layout { grid-template-columns: 1fr; }
  .sync-main-panel { grid-row: auto; }
  .install-panel { grid-column: auto; }
}

@media (max-width: 760px) {
  body { padding-top: 42px; }
  .connection-banner { height: 42px; padding: 0 12px; text-align: center; }
  .sidebar { top: 0; height: auto; }
  .main-nav { grid-template-columns: 1fr 1fr; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .four-stats, .server-backup-grid, .sync-summary { grid-template-columns: 1fr; }
  .sync-action-card { grid-template-columns: 38px 1fr; }
  .sync-action-card .btn { grid-column: 1 / -1; width: 100%; }
  .main-content { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
