/* ================================================================
   app.css — Supervision Industrielle v2
   Aesthetic : Industrial Monitoring — Precision & Data-Dense
   Font : IBM Plex Sans (body) + IBM Plex Mono (data/numbers)
   Theme : Deep navy + Crimson + Warm white
   ================================================================ */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  /* Core palette */
  --ink: #0d1117;
  --ink-mid: #1c2333;
  --ink-soft: #2d3748;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f4;
  --border: #dde1e9;
  --border-soft: #eaecf0;

  /* Crimson brand */
  --cr-900: #4a0a16;
  --cr-800: #6b1222;
  --cr-700: #8b1a30;
  --cr-600: #a8213b;
  --cr-500: #c42a4a; /* primary */
  --cr-400: #d94f6a;
  --cr-300: #e8849a;
  --cr-100: #fde8ed;
  --cr-50: #fff5f7;

  /* Semantic */
  --success: #0d7a4e;
  --success-bg: #e6f7f0;
  --success-border: #a3d9bf;
  --warning: #a16207;
  --warning-bg: #fefce8;
  --warning-border: #fde68a;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --info-border: #93c5fd;

  /* Machine status colors */
  --col-grey: #6b7280;
  --col-red: #dc2626;
  --col-violet: #7c3aed;
  --col-black: #111827;
  --col-blue: #2563eb;
  --col-orange: #ea580c;
  --col-green: #16a34a;

  /* Typography */
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Fira Code", monospace;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* Shadows */
  --sh-xs: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --sh-sm: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
  --sh-md: 0 4px 16px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
  --sh-lg: 0 8px 32px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.07);
  --sh-brand: 0 4px 20px rgba(196, 42, 74, 0.18);

  /* Sidebar */
  --sidebar-w: 240px;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--surface-2);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--cr-500);
  text-decoration: none;
  transition: color 0.15s;
}

a:hover {
  color: var(--cr-700);
}


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

ul,
ol {
  padding-left: 20px;
}
p {
  margin: 0 0 0.75em;
}
p:last-child {
  margin-bottom: 0;
}

/* ── App shell ──────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar-backdrop,
.mobile-menu-btn,
.sidebar__mobile-close {
  display: none;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  background: var(--ink);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, var(--cr-600) 0%, transparent 60%);
  pointer-events: none;
}

.sidebar__brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  position: relative;
}

.sidebar__brand::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--cr-500);
  border-radius: 0 2px 2px 0;
}

.sidebar__brand h1 {
  margin: 0 0 2px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar__brand p {
  margin: 0;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.sidebar__nav {
  flex: 1;
  padding: 12px 0 12px 10px;
}

.sidebar__nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 0.92rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  position: relative;
  margin-right: 10px;
}

.sidebar__nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar__nav a[aria-current="page"],
.sidebar__nav a.active {
  background: var(--cr-800);
  color: #fff;
  font-weight: 700;
  padding-left: 20px;
  border-radius: 20px 0 0 20px;
  margin-right: 0;
}

/* Concave Arcs */
.sidebar__nav a.active::before,
.sidebar__nav a.active::after {
  content: "";
  position: absolute;
  right: 0;
  width: 20px;
  height: 20px;
  background: transparent;
  pointer-events: none;
}

.sidebar__nav a.active::before {
  top: -20px;
  border-radius: 0 0 20px 0;
  box-shadow: 10px 10px 0 0 var(--cr-800);
}

.sidebar__nav a.active::after {
  bottom: -20px;
  border-radius: 0 20px 0 0;
  box-shadow: 10px -10px 0 0 var(--cr-800);
}

/* Nav section separators */
.sidebar__nav li::before {
  content: "";
  display: block;
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 8px 12px;
}
.sidebar__nav li:first-child::before,
.sidebar__nav a.active + li::before,
.sidebar__nav li:has(+ li a.active)::before {
  display: none;
}

.sidebar__footer {
  padding: 16px 20px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-family: var(--font-mono);
}


.main-content {
  padding: var(--sp-8) 36px;
  background: var(--surface-2);
  min-width: 0;
}

.main-content > * {
  min-width: 0;
  max-width: 100%;
}

/* ── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-5);
  margin-bottom: var(--sp-8);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
}

.page-header__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cr-500);
  margin: 0 0 6px;
  font-family: var(--font-mono);
}

.page-header__eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cr-500);
  flex-shrink: 0;
}

.page-header h2 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-header p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
}

.page-header__actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
}

/* ── Buttons ────────────────────────────────────────────────────── */
button,
.page-header__actions a,
.machine-card__action button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--cr-500);
  color: #fff;
  border: 0;
  border-radius: var(--r-sm);
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.84rem;
  letter-spacing: 0.01em;
  transition:
    background 0.15s,
    transform 0.1s,
    box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
  box-shadow: var(--sh-xs), var(--sh-brand);
  font-family: var(--font-body);
}

button:hover,
.page-header__actions a:hover,
.machine-card__action button:hover {
  background: var(--cr-600);
  transform: translateY(-1px);
  box-shadow:
    var(--sh-sm),
    0 4px 16px rgba(196, 42, 74, 0.22);
  text-decoration: none;
}

button:active {
  transform: translateY(0);
  box-shadow: var(--sh-xs);
}

button:disabled,
button[disabled] {
  background: var(--surface-3);
  color: var(--ink-soft);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Secondary button */
.btn-secondary,
button[type="button"].btn-secondary {
  background: var(--surface) !important;
  color: var(--ink-mid) !important;
  border: 1.5px solid var(--border) !important;
  box-shadow: var(--sh-xs) !important;
}
.btn-secondary:hover {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
  box-shadow: var(--sh-sm) !important;
  transform: translateY(-1px) !important;
}

/* Table action buttons */
.btn-table {
  background: var(--surface) !important;
  color: var(--cr-700) !important;
  border: 1.5px solid var(--cr-100) !important;
  box-shadow: none !important;
  padding: 4px 10px !important;
  font-size: 0.77rem !important;
  font-weight: 600 !important;
  border-radius: var(--r-sm) !important;
}
.btn-table:hover {
  background: var(--cr-50) !important;
  border-color: var(--cr-300) !important;
  transform: none !important;
  box-shadow: var(--sh-xs) !important;
}

/* Bouton suppression — même style que btn-table */
.btn-delete-machine.btn-table,
.btn-delete-moule.btn-table {
  background: var(--surface) !important;
  color: var(--cr-700) !important;
  border: 1.5px solid var(--cr-100) !important;
  box-shadow: none !important;
}
.btn-delete-machine.btn-table:hover,
.btn-delete-moule.btn-table:hover {
  background: var(--cr-50) !important;
  border-color: var(--cr-300) !important;
  transform: none !important;
}

/* Close button */
.btn-close {
  background: var(--surface-3) !important;
  color: var(--ink-soft) !important;
  border: 1.5px solid var(--border) !important;
  box-shadow: none !important;
  padding: 5px 10px !important;
  font-size: 0.82rem !important;
}

/* PDF button */
button[type="button"]#btn-telecharger-pdf {
  background: var(--surface) !important;
  color: var(--cr-700) !important;
  border: 1.5px solid var(--border) !important;
  box-shadow: var(--sh-xs) !important;
}
button[type="button"]#btn-telecharger-pdf:hover {
  background: var(--cr-50) !important;
  border-color: var(--cr-300) !important;
}

/* Quick links */
.quick-link {
  min-height: 56px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 0.88rem;
  background: var(--surface) !important;
  color: var(--cr-700) !important;
  border: 1.5px solid var(--border) !important;
  box-shadow: var(--sh-xs) !important;
  transition: all 0.15s !important;
}
.quick-link:hover {
  background: var(--cr-50) !important;
  border-color: var(--cr-300) !important;
  transform: translateY(-2px) !important;
  box-shadow: var(--sh-sm) !important;
  text-decoration: none !important;
}

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--sh-xs);
  margin-bottom: var(--sp-5);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--sh-sm);
}

.card h3 {
  margin: 0 0 var(--sp-5);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3::before {
  content: "";
  width: 3px;
  height: 16px;
  background: var(--cr-500);
  border-radius: 2px;
  flex-shrink: 0;
}

/* Card warning variant */
.card--warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

/* ── Flash message ──────────────────────────────────────────────── */
.flash-message {
  margin-bottom: var(--sp-5);
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
  font-size: 0.88rem;
  font-weight: 500;
}

/* ── Tables ─────────────────────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
  margin: 0 -2px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 600px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

thead th {
  background: var(--ink-mid);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border: none;
  font-family: var(--font-mono);
}

thead th:first-child {
  border-radius: var(--r-sm) 0 0 0;
}
thead th:last-child {
  border-radius: 0 var(--r-sm) 0 0;
}

thead th.is-sortable {
  cursor: pointer;
  user-select: none;
}
thead th.is-sortable:hover {
  background: var(--ink-soft);
  color: #fff;
}
thead th[data-sort-dir="asc"]::after {
  content: " ↑";
  opacity: 0.7;
}
thead th[data-sort-dir="desc"]::after {
  content: " ↓";
  opacity: 0.7;
}

tbody tr {
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.1s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:nth-child(even) {
  background: var(--surface-2);
}
tbody tr:hover {
  background: var(--cr-50);
}

tbody td {
  padding: 10px 14px;
  vertical-align: middle;
  color: var(--ink);
  line-height: 1.45;
}

/* Mono for numbers/dates */
tbody td[data-ta-s],
.cell-mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* Table search */
.table-search {
  margin-bottom: var(--sp-3);
}

.table-search__input {
  width: 100%;
  max-width: 320px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  font-size: 0.84rem;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.table-search__input:focus {
  border-color: var(--cr-500);
  box-shadow: 0 0 0 3px rgba(196, 42, 74, 0.1);
}

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
}

.badge--grey {
  background: var(--surface-3);
  color: var(--ink-soft);
}
.badge--green {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.badge--orange {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}
.badge--red {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.badge--blue {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid var(--info-border);
}
.badge--crimson {
  background: var(--cr-100);
  color: var(--cr-700);
  border: 1px solid var(--cr-300);
}

.badge--green.badge--done {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
  font-size: 0.85rem;
}

.badge--warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning-border);
  cursor: pointer;
  text-decoration: none;
  border-radius: var(--r-sm);
  padding: 3px 10px;
}

/* ── Badge Fiche ─────────────────────────────────────────────────── */
.badge-fiche {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 0.77rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.12s;
}
.badge-fiche:hover {
  opacity: 0.82;
  text-decoration: none;
}
.badge-fiche--ok {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.badge-fiche--missing {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  cursor: pointer;
}

/* ── Forms ──────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-4);
  align-items: end;
}

.form-grid .form-grid__full {
  grid-column: 1 / -1;
}

.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
}

label,
legend {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-mid);
  display: block;
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="search"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  font-size: 0.88rem;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cr-500);
  box-shadow: 0 0 0 3px rgba(196, 42, 74, 0.1);
}

input[readonly] {
  background: var(--surface-2);
  color: var(--ink-soft);
  cursor: default;
  border-color: var(--border-soft);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

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

.form-help {
  font-size: 0.77rem;
  color: var(--ink-soft);
  margin: 4px 0 0;
  font-style: italic;
}

/* ── Stats list (dl) ────────────────────────────────────────────── */
.stats-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-4);
  margin: 0;
}

.stats-list > div {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 14px 16px;
}

.stats-list dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  margin: 0 0 4px;
  font-family: var(--font-mono);
}

.stats-list dd {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  font-family: var(--font-mono);
}

/* ── Machine cards grid (dashboard) ────────────────────────────── */
.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-5);
}

/* Machine card */
.machine-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-xs);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  position: relative;
}

.machine-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--sh-md);
}

/* Status strip on left */
.machine-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.machine-card--grey::before {
  background: var(--col-grey);
}
.machine-card--red::before {
  background: var(--col-red);
}
.machine-card--violet::before {
  background: var(--col-violet);
}
.machine-card--black::before {
  background: var(--col-black);
}
.machine-card--blue::before {
  background: var(--col-blue);
}
.machine-card--orange::before {
  background: var(--col-orange);
}
.machine-card--green::before {
  background: var(--col-green);
}

.machine-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px 12px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.machine-card__header h3 {
  margin: 0 0 2px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  border: none;
  padding: 0;
  text-transform: none;
  letter-spacing: 0;
}
.machine-card__header h3::before {
  display: none;
}

.machine-card__header p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-family: var(--font-mono);
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 99px;
  font-family: var(--font-mono);
}

.machine-card--grey .status-badge {
  background: #f3f4f6;
  color: var(--col-grey);
}
.machine-card--red .status-badge {
  background: var(--danger-bg);
  color: var(--col-red);
}
.machine-card--violet .status-badge {
  background: #f5f3ff;
  color: var(--col-violet);
}
.machine-card--black .status-badge {
  background: #f1f2f4;
  color: var(--col-black);
}
.machine-card--blue .status-badge {
  background: var(--info-bg);
  color: var(--col-blue);
}
.machine-card--orange .status-badge {
  background: #fff7ed;
  color: var(--col-orange);
}
.machine-card--green .status-badge {
  background: var(--success-bg);
  color: var(--col-green);
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.machine-card--green .status-badge::before,
.machine-card--blue .status-badge::before {
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

/* Metrics */
.machine-card__metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  padding: 0;
}

.machine-card__metrics > div {
  padding: 10px 16px 10px 20px;
  border-bottom: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
}

.machine-card__metrics > div:nth-child(even) {
  border-right: none;
}
.machine-card__metrics > div:nth-last-child(-n + 2) {
  border-bottom: none;
}

.machine-card__metrics dt {
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 2px;
  font-family: var(--font-mono);
}

.machine-card__metrics dd {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  font-family: var(--font-mono);
}

/* Machine card action section */
.machine-card__action {
  padding: 12px 16px 14px 20px;
  background: var(--surface-2);
  border-top: 1px solid var(--border-soft);
}

.machine-card__action h4 {
  margin: 0 0 8px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.machine-card__action form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.machine-card__cause-label {
  font-size: 0.83rem;
  color: var(--ink);
  margin: 0 0 8px;
}

/* ── Legend list ────────────────────────────────────────────────── */
.legend-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-2);
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 0.83rem;
  border: 1px solid var(--border-soft);
}

.legend-list li strong {
  color: var(--ink);
  font-weight: 700;
}

/* ── Home grid ──────────────────────────────────────────────────── */
.grid--cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.grid--quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-3);
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  border: none;
  padding: 0;
  text-transform: none;
  letter-spacing: 0;
}
.modal-header h3::before {
  display: none;
}

.modal-box .form-grid {
  padding: 20px 24px 24px;
}

/* Inline modal (historique arrêts) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}
.modal[hidden] {
  display: none;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.55);
  backdrop-filter: blur(3px);
}
.modal__box {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: 24px 28px;
  max-width: 440px;
  width: 100%;
  z-index: 1;
  border: 1px solid var(--border);
}
.modal__box h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
.modal__box p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

/* ── Metric colors (indicateurs) ───────────────────────────────── */
.metric-danger {
  color: var(--danger);
  font-weight: 700;
  font-family: var(--font-mono);
}
.metric-warning {
  color: var(--warning);
  font-weight: 700;
  font-family: var(--font-mono);
}
.metric-good {
  color: var(--success);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ── Indicateurs table ─────────────────────────────────────────── */
.indicateurs-table td:first-child {
  font-weight: 600;
  color: var(--ink-mid);
}

.indicateurs-table tbody td:nth-child(3) {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Chain of calculation */
.card ol {
  counter-reset: chain;
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}

.card ol li {
  counter-increment: chain;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  font-size: 0.84rem;
  font-family: var(--font-mono);
}

.card ol li::before {
  content: counter(chain, decimal-leading-zero);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  background: var(--cr-500);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ── Historique arrêts — cause column ──────────────────────────── */
#table-arrets td:nth-child(2) {
  font-weight: 600;
}

/* Action cell links */
.link-choose-moule,
.link-fill-form {
  font-weight: 600;
  color: var(--cr-600);
  font-size: 0.82rem;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.link-identify-cause {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* Cause select inline */
.cause-select-inline select {
  border-color: var(--cr-300);
  font-size: 0.82rem;
}

/* ── Maintenance / Entretiens ───────────────────────────────────── */
.maintenance-block {
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.maintenance-block h4 {
  margin: 0 0 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink-mid);
}

.maintenance-block--green {
  border-left: 3px solid var(--col-green);
}
.maintenance-block--orange {
  border-left: 3px solid var(--col-orange);
}
.maintenance-block--red {
  border-left: 3px solid var(--col-red);
}

/* Maintenance progress */
.maintenance-progress__fill {
  transition:
    width 0.8s ease,
    background 0.4s ease;
}

/* Chatbot */
.chatbot-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 940;
  border-radius: 999px;
  padding: 12px 18px;
  box-shadow: var(--sh-lg), var(--sh-brand);
}

.chatbot-panel {
  position: fixed;
  right: 24px;
  bottom: 86px;
  width: min(420px, calc(100vw - 32px));
  max-height: min(76vh, 720px);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: linear-gradient(180deg, #fff 0%, #fff7f8 100%);
  border: 1px solid var(--cr-100);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  overflow: hidden;
  z-index: 945;
}

.chatbot-panel[hidden] {
  display: none;
}

.chatbot-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 16px 18px 14px;
  background: linear-gradient(135deg, var(--ink-mid) 0%, var(--cr-800) 100%);
  color: #fff;
}

.chatbot-panel__header strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.chatbot-panel__header p {
  margin: 0;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.45;
}

.chatbot-panel__close {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.chatbot-panel__close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chatbot-panel__messages {
  padding: 14px 14px 6px;
  overflow-y: auto;
  background:
    radial-gradient(circle at top right, rgba(232, 132, 154, 0.22), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(255, 245, 247, 0.94) 100%);
}

.chatbot-message {
  display: flex;
  margin-bottom: 12px;
}

.chatbot-message--user {
  justify-content: flex-end;
}

.chatbot-message__bubble {
  max-width: 88%;
  border-radius: 16px;
  padding: 11px 13px;
  font-size: 0.84rem;
  line-height: 1.55;
  box-shadow: var(--sh-xs);
  white-space: pre-wrap;
}

.chatbot-message--assistant .chatbot-message__bubble {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border-soft);
}

.chatbot-message__bubble--typing {
  display: inline-flex;
  align-items: center;
  min-width: auto;
  min-height: auto;
}

.chatbot-message__bubble--streaming::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 1.1em;
  margin-left: 2px;
  border-radius: 999px;
  vertical-align: -0.18em;
  background: rgba(123, 18, 47, 0.72);
  animation: chatbot-caret-blink 0.9s steps(1) infinite;
}

.chatbot-message--user .chatbot-message__bubble {
  background: linear-gradient(135deg, var(--cr-500) 0%, var(--cr-700) 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.chatbot-message__meta {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.chatbot-typing {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.chatbot-typing__label {
  color: rgba(66, 75, 90, 0.78);
  font-size: 0.83rem;
  font-weight: 500;
}

.chatbot-typing__bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  height: 16px;
}

.chatbot-typing__bar {
  width: 3px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(173, 35, 69, 0.36) 0%, rgba(173, 35, 69, 0.82) 100%);
  animation: chatbot-typing-bars 1.1s infinite ease-in-out;
}

.chatbot-typing__bar:nth-child(2) {
  animation-delay: 0.12s;
}

.chatbot-typing__bar:nth-child(3) {
  animation-delay: 0.24s;
}

.chatbot-typing__bar:nth-child(4) {
  animation-delay: 0.36s;
}

.chatbot-panel__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 12px;
  border-top: 1px solid rgba(221, 225, 233, 0.45);
}

.chatbot-suggestion {
  background: #fff;
  color: var(--cr-700);
  border: 1px solid var(--cr-100);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.75rem;
  line-height: 1.35;
  box-shadow: none;
}

.chatbot-suggestion:hover {
  background: var(--cr-50);
  transform: none;
  box-shadow: var(--sh-xs);
}

.chatbot-panel__form {
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(221, 225, 233, 0.65);
  background: rgba(255, 255, 255, 0.92);
}

.chatbot-panel__composer {
  border: 1px solid rgba(212, 220, 232, 0.95);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(28, 35, 51, 0.06);
  padding: 10px 14px 8px;
}

.chatbot-panel__input {
  display: block;
  width: 100%;
  min-height: 24px;
  max-height: 110px;
  height: 24px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: none;
  background: transparent;
  padding: 0;
  line-height: 1.45;
  color: var(--ink);
}

.chatbot-panel__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(234, 236, 240, 0.95);
}

.chatbot-panel__hint {
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.assistant-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

body.assistant-ia-page {
  overflow: hidden;
}

body.assistant-ia-page .app-shell {
  height: 100vh;
}

body.assistant-ia-page .main-content {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.assistant-ia-page .page-header {
  flex-shrink: 0;
  margin-bottom: var(--sp-6);
}

body.assistant-ia-page .assistant-layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.assistant-chat {
  display: grid;
  grid-template-rows: 1fr auto;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.assistant-chat__messages.chatbot-panel__messages {
  padding: 8px 0 28px;
  overflow-y: auto;
  background: transparent;
}

.assistant-chat__messages .chatbot-message {
  width: min(100%, 1100px);
  margin-left: auto;
  margin-right: auto;
  padding-inline: 18px;
}

.assistant-chat__messages .chatbot-message__bubble {
  max-width: min(880px, 82%);
}

.assistant-chat__messages .chatbot-message--assistant .chatbot-message__bubble {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  max-width: min(980px, 86%);
}

.assistant-chat__messages .chatbot-message--user .chatbot-message__bubble {
  box-shadow: 0 14px 34px rgba(159, 23, 58, 0.18);
}

.assistant-chat__messages .chatbot-message--assistant .chatbot-message__meta {
  margin-top: 10px;
  color: rgba(66, 75, 90, 0.88);
}

.assistant-chat__messages .chatbot-message--typing .chatbot-message__bubble--typing {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.assistant-chat__form {
  position: relative;
  padding: 10px 0 0;
  background:
    linear-gradient(180deg, rgba(248, 249, 252, 0) 0%, rgba(248, 249, 252, 0.92) 32%, rgba(248, 249, 252, 1) 100%);
  border-top: 1px solid rgba(221, 225, 233, 0.65);
}

.assistant-chat__composer {
  width: min(100%, 1100px);
  margin: 0 auto;
  border-radius: 24px;
  padding: 10px 14px 10px;
  box-shadow: 0 14px 38px rgba(28, 35, 51, 0.08);
}

.assistant-chat__actions {
  align-items: center;
}

.assistant-chat__composer #chatbot-submit {
  min-width: 92px;
  padding: 8px 16px;
}

.assistant-layout__aside {
  display: grid;
  gap: 20px;
}

.doc-rag-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* Document RAG Dropdown & Utilities */
.doc-rag-head-actions {
  position: relative;
}

.doc-rag-dropdown {
  position: relative;
}

.doc-rag-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.88rem;
}

.doc-rag-dropdown-trigger::-webkit-details-marker {
  display: none;
}

.doc-rag-dropdown-content {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1000;
  padding: 24px;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.12), 0 5px 15px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(173, 35, 69, 0.1);
  background: white;
  border-radius: 16px;
}

.doc-rag-copy {
  color: var(--ink-soft);
  line-height: 1.6;
}

.doc-rag-filter {
  display: grid;
  gap: 6px;
  margin: 0 0 16px;
}

.doc-rag-filter__label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.doc-rag-filter__input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  font-size: 0.85rem;
}

.doc-rag-sidebar__scope {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(221, 225, 233, 0.9);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(249, 251, 255, 0.94) 100%);
  margin-bottom: 14px;
}

.doc-rag-sidebar__scope-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.doc-rag-active-scope,
.doc-rag-question-scope {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.doc-rag-question-scope {
  background: rgba(196, 42, 74, 0.08);
  color: var(--cr-800);
  border: 1px solid rgba(173, 35, 69, 0.1);
  margin-bottom: 4px;
}

.doc-rag-active-scope {
  background: #fff;
  color: var(--ink-soft);
  border: 1px solid rgba(221, 225, 233, 0.8);
}

.doc-rag-sidebar__actions {
  display: flex;
  margin-bottom: 16px;
}

.doc-rag-sidebar__actions .btn-secondary {
  width: 100%;
  justify-content: center;
}

.doc-rag-files-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.doc-rag-target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--surface);
}

.doc-rag-target-row.is-scoped {
  border-color: rgba(173, 35, 69, 0.2);
  background: rgba(173, 35, 69, 0.02);
}

.doc-rag-target-row__name {
  min-width: 0;
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-rag-scope-btn {
  padding: 4px 10px;
  font-size: 0.72rem;
  border-radius: 999px;
}

.doc-rag-scope-btn.is-active {
  background: var(--cr-600);
  color: white;
  border: none;
}

.assistant-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(173, 35, 69, 0.14);
  color: var(--cr-700);
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.assistant-list {
  margin: 0;
  padding-left: 18px;
  color: var(--ink-soft);
  line-height: 1.7;
}

.assistant-list li + li {
  margin-top: 8px;
}

.sidebar__nav {
  flex: 1;
  padding: 12px 0 12px 10px;
}

.sidebar__nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 0.92rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  position: relative;
  margin-right: 10px;
}

.sidebar__nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar__nav a[aria-current="page"],
.sidebar__nav a.active {
  background: var(--cr-800);
  color: #fff;
  font-weight: 700;
  padding-left: 20px;
  border-radius: 20px 0 0 20px;
  margin-right: 0;
}

/* Concave Arcs */
.sidebar__nav a.active::before,
.sidebar__nav a.active::after {
  content: "";
  position: absolute;
  right: 0;
  width: 20px;
  height: 20px;
  background: transparent;
  pointer-events: none;
}

.sidebar__nav a.active::before {
  top: -20px;
  border-radius: 0 0 20px 0;
  box-shadow: 10px 10px 0 0 var(--cr-800);
}

.sidebar__nav a.active::after {
  bottom: -20px;
  border-radius: 0 20px 0 0;
  box-shadow: 10px -10px 0 0 var(--cr-800);
}

/* Nav section separators */
.sidebar__nav li::before {
  content: "";
  display: block;
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 8px 12px;
}
.sidebar__nav li:first-child::before {
  display: none;
}

.sidebar__footer {
  padding: 16px 20px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-family: var(--font-mono);
}

.chatbot-panel--page {
  position: static;
  right: auto;
  bottom: auto;
  width: 100%;
  max-height: none;
  height: 100%;
  min-height: 0;
  box-shadow: var(--sh-md);
}

.chatbot-panel__header--page {
  padding: 20px 22px 18px;
}

.chatbot-panel--page .chatbot-panel__messages {
  min-height: 0;
  max-height: none;
}

.chatbot-panel--page .chatbot-panel__suggestions {
  padding: 12px 18px 14px;
}

.chatbot-panel--page .chatbot-panel__form {
  padding: 14px 18px 18px;
}

.chatbot-panel--page .chatbot-panel__input {
  min-height: 52px;
}

.chatbot-panel--page #chatbot-submit {
  border-radius: 999px;
  padding: 10px 18px;
  min-width: 108px;
}

/* Document RAG */
body.assistant-docs-page {
  overflow: hidden;
  background: #f8fafc;
}



body.assistant-docs-page .main-content {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

body.assistant-docs-page .page-header {
  flex-shrink: 0;
  margin-bottom: 8px;
  padding: 20px 40px 10px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
}

.doc-rag-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.doc-rag-chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 40px 20px;
}

.doc-rag-chat-surface {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  margin-bottom: 0;
  background: white;
  overflow: visible;
  padding: 0;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
  border: 1px solid #e2e8f0;
}

.doc-rag-chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.doc-rag-chat-head h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e293b;
}

.doc-rag-chat-eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--cr-600);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.doc-rag-chat-copy {
  display: none; /* Let's hide the long copy to save space */
}

/* Dropdown */
.doc-rag-head-actions {
  position: relative;
}

.doc-rag-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-weight: 600;
  font-size: 0.85rem;
  color: #475569;
  transition: all 0.2s;
}

.doc-rag-dropdown-trigger:hover {
  background: white;
  border-color: var(--cr-300);
  color: var(--cr-700);
}

.doc-rag-dropdown-content {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 80px);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1000;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid #e2e8f0;
  background: white;
  border-radius: 12px;
}

/* Chat Content Area */
.doc-rag-empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.doc-rag-empty-state[hidden] {
  display: none !important;
}

.doc-rag-empty-state__box {
  max-width: 440px;
  padding: 40px;
  border-radius: 24px;
  background: white;
  border: 1px solid #e2e8f0;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.03);
}

.doc-rag-empty-state__box strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: #1e293b;
}

.doc-rag-empty-state__box p {
  color: #64748b;
  font-size: 0.95rem;
  line-height: 1.6;
}

.doc-rag-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.doc-rag-message {
  display: flex;
  width: 100%;
}

.doc-rag-message--user { justify-content: flex-end; }

.doc-rag-message__bubble {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 0.94rem;
  line-height: 1.6;
}

.doc-rag-message--user .doc-rag-message__bubble {
  background: var(--cr-600);
  color: white;
  border-bottom-right-radius: 4px;
}

.doc-rag-message--assistant .doc-rag-message__bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

.doc-rag-question-form {
  padding: 10px 24px 12px;
  background: white;
  border-top: 1px solid #f1f5f9;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

.doc-rag-composer {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 4px 10px;
  width: 100%;
}

.doc-rag-composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.92rem;
  background: transparent;
  padding: 6px 8px;
  color: #1e293b;
}

.doc-rag-composer__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
  padding-top: 4px;
}

.doc-rag-composer__buttons {
  display: flex;
  gap: 8px;
}

.doc-rag-hint {
  font-size: 0.75rem;
  color: #94a3b8;
}


/* ── Responsiveness Restoration ────────────────────────────────── */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -240px; /* Hidden off-screen by default */
    width: 240px;
    height: 100vh;
    z-index: 2000;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.15);
  }

  body.sidebar-mobile-open .sidebar {
    left: 0;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(13, 17, 23, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  body.sidebar-mobile-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar__mobile-close {
    display: flex !important;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  .main-content {
    padding: 20px 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 0 0 16px;
  }

  /* Cards & Grids globally */
  .grid--cards, .machine-grid, .stats-list, .legend-list {
    grid-template-columns: 1fr;
  }
}

/* Assistant Docs Specific Mobile Optimization */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }

  body.assistant-docs-page .page-header {
    padding: 10px 16px 8px;
    margin-bottom: 0;
    border-bottom: none;
  }

  body.assistant-docs-page .page-header h2 {
    font-size: 1.1rem;
    margin: 0;
  }

  body.assistant-docs-page .page-header__eyebrow {
    font-size: 0.6rem;
  }

  body.assistant-docs-page .page-header .page-header__actions {
    margin-top: 4px;
  }

  body.assistant-docs-page .main-content {
    height: 100vh;
    height: 100dvh;
  }

  .doc-rag-chat {
    padding: 0;
  }

  .doc-rag-chat-surface {
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  /* Chat head: stack title and button vertically */
  .doc-rag-chat-head {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px;
    gap: 10px;
    background: #fdfdfd;
  }

  .doc-rag-head-actions {
    position: static;
  }

  /* Dropdown: fullscreen overlay on mobile instead of absolute */
  .doc-rag-dropdown-content {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 9998 !important;
    padding: 16px;
    box-sizing: border-box;
  }

  .doc-rag-empty-state__box {
    padding: 24px 20px;
    margin: 20px;
    border-radius: 16px;
    background: white;
    border-style: solid;
    border-color: #f1f5f9;
  }

  .doc-rag-manage-dialog {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    border: none !important;
  }

  .doc-rag-manage-head {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .doc-rag-manage-head h3 {
    font-size: 1rem;
  }

  /* Stack the 2-column grid into 1 column on mobile */
  .doc-rag-manage-grid {
    grid-template-columns: 1fr !important;
    overflow-y: auto;
  }

  .doc-rag-admin-upload {
    border-right: none !important;
    border-bottom: 1px solid #f1f5f9;
    padding: 16px;
  }

  .doc-rag-admin-library {
    padding: 16px;
  }

  /* File picker smaller on mobile */
  .doc-rag-file-picker {
    padding: 20px 14px;
    margin: 12px 0;
  }

  /* File rows: stack name and buttons vertically */
  .doc-rag-admin-row {
    padding: 10px 12px;
  }

  .doc-rag-admin-row__view {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .doc-rag-admin-row__name {
    font-size: 0.82rem;
    word-break: break-word;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    width: 100%;
  }

  .doc-rag-admin-row__actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
    gap: 6px;
  }

  .doc-rag-admin-row__actions button {
    font-size: 0.72rem;
    padding: 5px 12px;
  }

  .doc-rag-messages {
    padding: 15px 14px;
    gap: 16px;
  }

  .doc-rag-message__bubble {
    max-width: 92%;
    padding: 12px 16px;
    font-size: 0.9rem;
  }

  .doc-rag-question-form {
    padding: 10px 10px 14px;
    border-radius: 0;
  }

  /* Premium Buttons */
  #doc-rag-ask-submit {
    background: linear-gradient(135deg, var(--cr-600) 0%, var(--cr-700) 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(173, 35, 69, 0.2);
  }

  .doc-rag-composer {
    padding: 4px 8px;
  }
  
  .doc-rag-composer textarea {
    font-size: 0.9rem;
    padding: 4px 6px;
  }
}

.doc-rag-selected-files {
  margin: 10px 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.doc-rag-feedback {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.doc-rag-feedback[data-tone="success"] { color: #16a34a; }
.doc-rag-feedback[data-tone="error"] { color: #dc2626; }
.doc-rag-feedback[data-tone="warning"] { color: #d97706; }
.doc-rag-feedback[data-tone="info"] { color: #2563eb; }

/* ── File Management Modal ─────────────────────────────────────── */
.doc-rag-manage-modal {
  position: fixed;
  inset: 0;
  z-index: 9999; /* Higher than everything */
  display: flex;
  align-items: center;
  justify-content: center;
}

.doc-rag-manage-modal[hidden] {
  display: none !important;
}

.doc-rag-manage-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.4);
  backdrop-filter: blur(8px);
}

.doc-rag-manage-dialog {
  position: relative;
  z-index: 10;
  width: min(900px, 95vw);
  max-height: 90vh;
  background: white;
  border-radius: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 !important;
  border: 1px solid #e2e8f0;
}

.doc-rag-manage-head {
  padding: 24px 30px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: #fdfdfd;
}

.doc-rag-manage-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.doc-rag-admin-upload, .doc-rag-admin-library {
  padding: 30px;
  overflow-y: auto;
}

.doc-rag-admin-upload {
  background: #f8fafc;
  border-right: 1px solid #f1f5f9;
}

.doc-rag-admin-library {
  background: white;
}

.doc-rag-admin-upload h4, .doc-rag-admin-library h4 {
  margin-bottom: 20px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-rag-file-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  margin: 20px 0;
}

.doc-rag-file-picker:hover {
  border-color: var(--cr-400);
  background: var(--cr-50);
}

.doc-rag-file-picker span {
  font-weight: 600;
  color: var(--cr-700);
  margin-bottom: 4px;
}

.doc-rag-admin-row {
  padding: 12px 14px;
  border: 1px solid #f1f5f9;
  border-radius: 10px;
  margin-bottom: 10px;
  background: #fdfdfd;
}

.doc-rag-admin-row__view {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.doc-rag-admin-row__name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1e293b;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-rag-admin-row__actions {
  display: flex;
  gap: 6px;
}

.doc-rag-admin-row__actions button {
  padding: 4px 10px;
  font-size: 0.7rem;
}
