:root {
  --bg: #f5f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0b1220;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-2: #eef0f4;
  --primary: #1e3a8a;
  --primary-2: #1e40af;
  --primary-soft: #eef2ff;
  --accent: #ea580c;
  --accent-soft: #fff7ed;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(11,18,32,.04);
  --shadow: 0 1px 3px rgba(11,18,32,.06), 0 12px 28px rgba(11,18,32,.06);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Inter, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

/* ============================================================
   AUTH
   ============================================================ */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(at 20% 0%, #c7d2fe 0%, transparent 50%),
    radial-gradient(at 100% 100%, #fed7aa 0%, transparent 50%),
    var(--bg);
  padding: 24px;
}
.auth-shell { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand-row { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-row h1 { margin: 0; font-size: 22px; font-weight: 700; }
.brand-row .muted { margin: 2px 0 0; font-size: 12px; }
.logo-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white; font-weight: 800; font-size: 20px;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(30,58,138,.3);
}
.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  background: transparent; border: none;
  padding: 8px 12px; border-radius: 7px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.auth-tab.active { background: white; color: var(--primary); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-google {
  background: white; color: var(--text); font-weight: 600;
  display: inline-flex; align-items: center; gap: 10px; justify-content: center;
}
.btn-google:hover { background: var(--panel-2); }
.auth-divider { text-align: center; margin: 16px 0 14px; position: relative; }
.auth-divider::before, .auth-divider::after {
  content: ""; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }
.auth-divider span { background: white; padding: 0 10px; color: var(--muted); font-size: 12px; }
.auth-banner {
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px;
  background: var(--primary-soft); color: var(--primary);
}
.auth-banner.success { background: var(--success-soft); color: var(--success); }
.auth-banner.error { background: var(--danger-soft); color: var(--danger); }
.auth-foot { text-align: center; margin: 16px 0 0; font-size: 11px; }
.auth-credit { text-align: center; margin: 16px 0 0; font-size: 11px; }
.hint { margin: -4px 0 0; font-size: 11px; color: var(--muted); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: white;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sb-brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 18px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sb-brand h1 { margin: 0; font-size: 17px; font-weight: 700; }
.sb-brand .muted { margin: 0; font-size: 11px; }

.sb-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sb-link {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none;
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: #374151;
  cursor: pointer; text-align: left;
  font-family: inherit;
}
.sb-link:hover { background: var(--panel-2); }
.sb-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sb-icon { font-size: 15px; }

.sb-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.sb-user { display: flex; gap: 10px; align-items: center; padding: 4px; }
.sb-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white; display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-email { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: transparent; border: none; padding: 0; color: var(--muted); font-size: 11px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--text); }

.main { padding: 28px 32px; max-width: 1200px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-actions { margin-top: 12px; display: flex; gap: 8px; }

.empty { text-align: center; padding: 30px 12px; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.full { grid-column: 1 / -1; }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: white;
  font-family: inherit;
  transition: border .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,.12);
}
textarea { resize: vertical; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger.ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger.ghost:hover { background: var(--danger-soft); }

.search { width: 100%; margin-bottom: 14px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-2); }
th { background: var(--panel-2); font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 2px 8px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* Prestations */
.prestations { display: flex; flex-direction: column; gap: 12px; }
.prestation {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--panel-2);
}
.prestation-head {
  display: flex; gap: 10px; align-items: flex-end;
  flex-wrap: wrap; margin-bottom: 10px;
}
.prestation-head label { flex: 1; min-width: 200px; }
.item-row {
  display: grid;
  grid-template-columns: 80px 1fr 100px 90px 70px 100px 100px 30px;
  gap: 6px; align-items: center;
  padding: 7px 0; border-top: 1px dashed var(--border);
}
.item-row:first-child { border-top: none; }
.item-row select, .item-row input { padding: 7px 9px; font-size: 13px; }
.item-badge {
  padding: 3px 6px; border-radius: 5px; font-size: 10px; font-weight: 700;
  text-align: center; letter-spacing: .04em; text-transform: uppercase;
}
.badge-mat { background: #dbeafe; color: #1e40af; }
.badge-lab { background: #dcfce7; color: #166534; }

.prestation-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.prestation-totals { display: flex; justify-content: flex-end; gap: 16px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; font-weight: 600; }

/* Totals card */
.totals-card { display: flex; justify-content: flex-end; }
.totals { width: 100%; max-width: 360px; }
.trow { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.trow strong { font-weight: 700; }
.trow-big { margin-top: 8px; padding-top: 12px; border-top: 2px solid var(--text); font-size: 18px; color: var(--primary); }
.tva-rows { flex-direction: column; gap: 2px; padding: 0; }
.tva-rows .tva-line { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); font-size: 13px; }
.trow-acc { color: var(--accent); margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(11,18,32,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: white; border-radius: 14px; padding: 24px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h3 { margin: 0 0 16px; }
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* Dictée vocale */
.btn-mic {
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: white;
  border: none;
  font-weight: 600;
}
.btn-mic:hover { background: linear-gradient(135deg, #c2410c, #d97706); color: white; }
.mic-icon { font-size: 16px; }

.dictate-card { max-width: 600px; }
.dictate-mic-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 20px 0;
}
.dictate-mic {
  width: 88px; height: 88px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: white;
  display: grid; place-items: center;
  font-size: 38px;
  box-shadow: 0 6px 20px rgba(234, 88, 12, 0.4);
  transition: all .2s;
}
.dictate-mic:hover { transform: scale(1.05); }
.dictate-mic.recording {
  background: linear-gradient(135deg, var(--danger), #ef4444);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  70% { box-shadow: 0 0 0 18px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}
.dictate-mic-icon { display: block; }
.dictate-status {
  font-size: 13px; color: var(--muted); font-weight: 500;
  text-align: center; min-height: 20px;
}
.dictate-status.recording { color: var(--danger); font-weight: 600; }
.dictate-tip {
  font-size: 12px; line-height: 1.5;
  background: var(--accent-soft);
  padding: 10px 12px; border-radius: 8px; border-left: 3px solid var(--accent);
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: white;
  padding: 11px 18px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 100; font-size: 13px; font-weight: 500;
  animation: slideIn .2s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Responsive */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative; height: auto; flex-direction: row; align-items: center;
    overflow-x: auto; padding: 12px 14px;
  }
  .sb-brand { padding: 0 10px 0 0; border: none; margin: 0; flex-shrink: 0; }
  .sb-brand h1 { font-size: 14px; }
  .sb-brand .muted { display: none; }
  .sb-nav { flex-direction: row; flex: 1; overflow-x: auto; gap: 4px; }
  .sb-link { white-space: nowrap; flex-shrink: 0; padding: 7px 10px; font-size: 12px; }
  .sb-link span { display: none; }
  .sb-foot { border: none; padding: 0; flex-shrink: 0; }
  .sb-user-email { display: none; }
  .main { padding: 18px; }
}
@media (max-width: 600px) {
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}
