:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --pri: #1d4ed8;
  --pri-hover: #1e40af;
  --pri-soft: #eff6ff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid #1e293b;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.brand-sub { font-size: 11px; font-weight: 500; color: #94a3b8; }
.search-box {
  flex: 1;
  min-width: 240px;
  max-width: 620px;
  display: flex;
  gap: 6px;
}
.search-box input {
  flex: 1;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #fff;
  font-size: 13px;
  outline: none;
}
.search-box input:focus { border-color: #60a5fa; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn-pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn-pri:hover { background: var(--pri-hover); }
.btn-dark { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.btn-dark:hover { background: #334155; color: #fff; }
.btn-danger { background: var(--red-soft); border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 4px 9px; font-size: 11px; }

.select-dark {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
}
.input-sm, .select-sm {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

/* Main Layout */
.container { max-width: 1480px; margin: 16px auto; padding: 0 16px 48px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 700; }

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.kpi .k { font-size: 11px; color: var(--muted); }
.kpi .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* Badges & Banners */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}
.badge-pri { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }

.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
}
.banner-warn { background: var(--amber-soft); border: 1px solid #fcd34d; color: #78350f; }
.banner-danger { background: var(--red-soft); border: 1px solid #fca5a5; color: #7f1d1d; }
.banner-info { background: var(--pri-soft); border: 1px solid #bfdbfe; color: #1e3a8a; }

/* Version Timeline */
.ver-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.ver-pill {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.ver-pill:hover { border-color: var(--pri); background: var(--pri-soft); }
.ver-pill.cur { background: #0f172a; color: #fff; border-color: #0f172a; font-weight: 600; }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab {
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.tab:hover { background: var(--surface-alt); }
.tab.active { background: #0f172a; color: #fff; border-color: #0f172a; }

/* Dossier Folder Explorer */
.explorer {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
  align-items: start;
}
@media (max-width: 820px) { .explorer { grid-template-columns: 1fr; } }
.slot-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.slot-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-size: 12px;
  color: var(--text);
}
.slot-item:hover { background: var(--surface-alt); }
.slot-item.active { background: var(--pri-soft); border-color: #bfdbfe; color: var(--pri); font-weight: 600; }
.slot-item.locked { opacity: 0.55; cursor: not-allowed; }
.slot-meta { display: flex; align-items: center; gap: 5px; }

/* Tables */
.tbl-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td {
  padding: 7px 9px;
  border-bottom: 1px solid #eef2f7;
  text-align: left;
  white-space: nowrap;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
}
th { position: sticky; top: 0; background: var(--surface-alt); font-weight: 600; color: var(--text-2); z-index: 2; }
tr.clickable:hover td { background: #eff6ff; cursor: pointer; }
tr:nth-child(even) td { background: #fbfcfd; }

/* Photo Grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 10px; }
.photo-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.photo-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08); }
.photo-card img { width: 100%; height: 142px; object-fit: cover; display: block; background: #f1f5f9; }
.photo-meta { padding: 7px 8px; font-size: 11px; color: var(--muted); }
.photo-meta b { display: block; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Slide-Over Preview Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 60;
  display: none;
  justify-content: flex-end;
}
.drawer-backdrop.open { display: flex; }
.drawer {
  width: min(920px, 94vw);
  height: 100vh;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.drawer-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface-alt);
}
.drawer-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body {
  position: relative;
  flex: 1;
  overflow: auto;
  padding: 14px 16px;
  background: #fff;
}
.watermark-layer {
  position: fixed;
  pointer-events: none;
  z-index: 80;
  inset: 0;
  background-repeat: repeat;
  opacity: 0.14;
}
.preview-img { max-width: 100%; max-height: 76vh; display: block; margin: 0 auto; border-radius: 6px; border: 1px solid var(--border); }
.preview-pdf { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 6px; }
.preview-code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 6px;
  overflow: auto;
  max-height: 70vh;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(400px, 92vw);
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
}

.empty { color: var(--muted); padding: 20px; text-align: center; }
.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.recent-item {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  background: var(--surface-alt);
  cursor: pointer;
}
.recent-item:hover { border-color: var(--pri); background: var(--pri-soft); }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  background: #0f172a;
  color: #fff;
  padding: 9px 14px;
  border-radius: 7px;
  font-size: 12px;
  box-shadow: var(--shadow-lg);
  display: none;
}
mark.hl {
  background: #fef08a;
  color: #713f12;
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 700;
}
.match-reason {
  margin-top: 6px;
  padding: 4px 7px;
  border-radius: 5px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  font-size: 11px;
  color: #78350f;
  line-height: 1.4;
  word-break: break-all;
}
.stage-bar {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--muted);
}
.stage-steps {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
@media (max-width: 780px) { .stage-steps { grid-template-columns: repeat(3, 1fr); } }
.stage-step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 6px 4px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
}
.stage-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  margin-bottom: 4px;
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.06);
}
.stage-dot.done { background: #16a34a; box-shadow: 0 0 0 3px #dcfce7; }
.stage-dot.in_progress { background: #2563eb; box-shadow: 0 0 0 3px #dbeafe; }
.stage-dot.alert { background: #dc2626; box-shadow: 0 0 0 3px #fee2e2; }
.stage-dot.pending { background: #cbd5e1; box-shadow: 0 0 0 3px #f1f5f9; }
.stage-lbl { font-size: 11px; font-weight: 700; color: var(--text); }
.stage-det { font-size: 10px; color: var(--muted); margin-top: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin: 0 3px 0 8px; vertical-align: middle; }
