:root {
  --accent: #1a73e8;
  --border: #dadce0;
  --text: #202124;
  --text-secondary: #5f6368;
  --bg: #ffffff;
  --bg-hover: #f8f9fa;
  --success: #188038;
  --warning: #b06000;
  --danger: #d93025;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Google Sans", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 24px 12px;
}

.sidebar .brand {
  font-size: 18px;
  font-weight: 500;
  padding: 0 12px 24px;
  color: var(--accent);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 14px;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.active {
  background: #e8f0fe;
  color: var(--accent);
  font-weight: 500;
}

.main {
  flex: 1;
  padding: 24px 32px;
  min-width: 0;
}

.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 0 0 16px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 400;
  margin: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 500;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

button, .btn {
  font-family: inherit;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 8px 20px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

button:hover {
  background: var(--bg-hover);
}

button.primary:hover {
  filter: brightness(0.95);
}

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
}

textarea {
  border-radius: 12px;
  width: 100%;
  resize: vertical;
}

.filters-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody tr .row-actions {
  visibility: hidden;
  display: flex;
  gap: 4px;
}

tbody tr:hover .row-actions {
  visibility: visible;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: #f1f3f4;
  color: var(--text-secondary);
}

.badge.state-DELIVERED, .badge.state-FOLLOWUP { background: #e6f4ea; color: var(--success); }
.badge.state-AWAITING_PAYMENT, .badge.state-PAID { background: #fef7e0; color: var(--warning); }
.badge.state-FAILED { background: #fce8e6; color: var(--danger); }
.badge.state-CANCELLED { background: #f1f3f4; color: var(--text-secondary); }
.badge.state-MANUAL_REVIEW { background: #e8f0fe; color: var(--accent); }

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.pagination button {
  height: 32px;
  width: 32px;
  padding: 0;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 400;
  text-align: center;
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  color: var(--text-secondary);
}

.error-text {
  color: var(--danger);
  font-size: 12px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.prompt-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.prompt-editor .prompt-key {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.prompt-editor .prompt-vars {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.prompt-editor .prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Écran « Styles » : aide de format visible à l'écran, zone de texte monospace (un
   réglage par ligne, aligné), et rappel repliable du profil d'usine. */
.style-help {
  margin-bottom: 16px;
}

.style-help h2 {
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 10px;
}

.style-help details,
.style-default {
  margin-top: 10px;
}

.style-help summary,
.style-default summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
}

.style-help-block {
  white-space: pre-wrap;
  overflow-x: auto;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.style-field-list {
  font-size: 12.5px;
  line-height: 1.7;
  margin: 8px 0 0;
  padding-left: 18px;
}

.style-field-list code {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

.style-editor textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.badge.style-custom {
  background: #e8f0fe;
  color: var(--accent);
}

.cards-list {
  display: none;
}

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

.message-log {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.message-row {
  padding: 8px 0;
  border-bottom: 1px solid #f1f3f4;
  font-size: 13px;
}

.message-row:last-child {
  border-bottom: none;
}

.message-row .meta {
  color: var(--text-secondary);
  font-size: 11px;
}

.chart-svg {
  width: 100%;
  height: 160px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
}

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    padding: 12px;
  }
  .sidebar .brand {
    display: none;
  }
  .nav-item {
    white-space: nowrap;
  }
  .main {
    padding: 16px;
  }
  table thead {
    display: none;
  }
  table, tbody, tr, td {
    display: block;
    width: 100%;
  }
  tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 8px 12px;
  }
  tbody td {
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
  }
  tbody tr .row-actions {
    visibility: visible;
    justify-content: flex-end;
  }
  .detail-grid, .two-col {
    grid-template-columns: 1fr;
  }
}
