:root {
  --fip-dark: #1a1f2c;
  --fip-red: #c0392b;
  --fip-gray: #f4f5f7;
  --fip-line: #dde2ea;
  --fip-text: #17202e;
  --fip-muted: #687385;
  --fip-green: #16803c;
  --fip-blue: #1d4ed8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body, #root { width: 100%; height: 100%; margin: 0; }
body {
  background: var(--fip-gray);
  color: var(--fip-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Open Sans", Arial, sans-serif;
  overscroll-behavior: none;
}
button, input, select { font: inherit; }
input[type="file"] { display: none; }
.no-select { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.logo { height: 34px; object-fit: contain; pointer-events: none; display: block; }

.app-shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  background: #fff;
  min-height: calc(62px + var(--safe-top));
  padding: calc(var(--safe-top) + 10px) 16px 12px;
  border-bottom: 1px solid var(--fip-line);
  box-shadow: 0 1px 8px rgba(23, 32, 46, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 20;
}
.topbar .side { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .side.right { justify-content: flex-end; }
.topbar .center { flex: 0 0 auto; display: flex; justify-content: center; }

.main { flex: 1; padding: 18px; max-width: 1180px; width: 100%; margin: 0 auto; }
.login-main { min-height: calc(100vh - 90px); display: flex; justify-content: center; align-items: center; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--fip-line); border-radius: 22px; padding: 26px; box-shadow: 0 20px 60px rgba(23, 32, 46, 0.08); text-align: center; }
.login-card .logo { margin: 0 auto 22px; height: 42px; }

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  background: #fff;
  color: var(--fip-text);
  box-shadow: 0 1px 3px rgba(23, 32, 46, 0.12);
  transition: transform .12s ease, background .12s ease, border-color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--fip-red); color: #fff; border-color: var(--fip-red); }
.btn.dark { background: var(--fip-dark); color: #fff; border-color: var(--fip-dark); }
.btn.green { background: var(--fip-green); color: #fff; border-color: var(--fip-green); }
.btn.blue { background: var(--fip-blue); color: #fff; border-color: var(--fip-blue); }
.btn.ghost { background: #fff; border-color: var(--fip-line); box-shadow: none; }
.btn.danger { background: #fff; color: var(--fip-red); border-color: rgba(192, 57, 43, .35); box-shadow: none; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 42px; padding: 0; }
.btn.icon.sm { width: 34px; }

.status-pill, .role-pill {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  background: #eef2f6;
  color: #4b5565;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.status-pill.active { background: #e6f6ec; color: var(--fip-green); }
.status-pill.pending { background: #e9efff; color: var(--fip-blue); }
.status-pill.deactivated, .status-pill.missing { background: #fdebea; color: var(--fip-red); }
.status-pill.new { background: #e6f6ec; color: var(--fip-green); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.section-head h1, .section-head h2 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.subtle { color: var(--fip-muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.job-card, .drawing-row, .panel {
  background: #fff;
  border: 1px solid var(--fip-line);
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(23, 32, 46, 0.06);
}
.job-card {
  min-height: 190px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
}
.job-card.pending, .job-card.deactivated { opacity: .72; filter: grayscale(.15); }
.job-tile {
  height: 92px;
  border-radius: 16px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: .02em;
}
.job-card h3 { margin: 0; font-size: 16px; line-height: 1.25; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }

.drawing-list { display: flex; flex-direction: column; gap: 10px; }
.drawing-row { padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.drawing-row .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawing-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.panel { padding: 16px; }
.empty { text-align: center; color: var(--fip-muted); padding: 40px 20px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .48); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal { background: #fff; width: min(680px, 100%); max-height: min(86vh, 760px); overflow: auto; border-radius: 24px; box-shadow: 0 30px 100px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--fip-line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 18px 20px 22px; }
.field { margin: 12px 0; }
.field label { display: block; font-weight: 800; font-size: 13px; margin-bottom: 7px; }
.field select, .field input[type="text"] { width: 100%; min-height: 42px; border: 1px solid var(--fip-line); border-radius: 12px; padding: 0 12px; background: #fff; }
.inline-list { display: flex; flex-wrap: wrap; gap: 8px; }
.person-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.person-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--fip-line); border-radius: 12px; background: #f8fafc; }
.person-main { min-width: 0; }
.person-main strong, .person-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-main span { font-size: 12px; color: var(--fip-muted); }

.viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: #e5e7eb; overflow: hidden; }
.viewer-filebar { background: #fff; border-bottom: 1px solid var(--fip-line); min-height: 32px; display: flex; align-items: center; justify-content: center; padding: 4px 12px; font-size: 12px; font-weight: 700; color: var(--fip-muted); z-index: 10; }
.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #d7dbe2; touch-action: none; }
.pdf-stage { position: absolute; top: 0; left: 0; transform-origin: top left; background: #fff; box-shadow: 0 12px 40px rgba(0,0,0,.22); }
.pdf-stage canvas { display: block; pointer-events: none; }
.marker { position: absolute; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--fip-dark); border-radius: 2px; box-shadow: 0 4px 12px rgba(0,0,0,.25); transform: translate(-50%, -50%); touch-action: none; }
.marker img { width: 100%; height: 100%; display: block; pointer-events: none; }
.marker.jiggle { animation: jiggle .3s infinite; z-index: 30; }
.marker-remove { position: absolute; top: -7px; left: -7px; width: 13px; height: 13px; border-radius: 999px; background: var(--fip-red); color: #fff; border: none; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 900; padding: 0; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
@keyframes jiggle { 0% { transform: translate(-50%, -50%) rotate(-1.5deg); } 50% { transform: translate(-50%, -50%) rotate(1.5deg); } 100% { transform: translate(-50%, -50%) rotate(-1.5deg); } }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #d7dbe2; border-top-color: var(--fip-red); animation: spin .7s linear infinite; }
.loading-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.92); z-index: 40; }
@keyframes spin { to { transform: rotate(360deg); } }

.zoom-pill { position: absolute; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); display: inline-flex; align-items: center; padding: 4px; background: rgba(255,255,255,.96); border: 1px solid var(--fip-line); border-radius: 999px; box-shadow: 0 12px 38px rgba(23, 32, 46, .18); z-index: 30; }
.zoom-pill button { box-shadow: none; }
.zoom-menu-wrap { position: relative; display: flex; }
.zoom-menu { position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); background: #fff; border: 1px solid var(--fip-line); border-radius: 18px; box-shadow: 0 18px 60px rgba(23, 32, 46, .22); padding: 8px; min-width: max-content; max-height: 320px; overflow: auto; z-index: 40; }
.zoom-menu button { display: flex; width: 150px; justify-content: center; margin: 2px 0; border-radius: 12px; min-height: 34px; box-shadow: none; }
.zoom-current { min-width: 88px; }

.scanner-overlay { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; }
.scanner-title { color: #fff; font-weight: 900; margin-bottom: 16px; }
#reader { width: min(520px, 100%); background: #111827; border-radius: 16px; overflow: hidden; }
#reader video { object-fit: contain !important; width: 100% !important; height: auto !important; }
.scanner-overlay .btn { margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); background: var(--fip-dark); color: #fff; padding: 12px 16px; border-radius: 999px; z-index: 120; box-shadow: 0 16px 40px rgba(0,0,0,.25); font-weight: 700; max-width: min(90vw, 680px); text-align: center; }

@media (max-width: 720px) {
  .topbar { padding-left: 10px; padding-right: 10px; }
  .topbar .side { gap: 6px; }
  .main { padding: 12px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .drawing-row { grid-template-columns: 1fr; }
  .drawing-actions { justify-content: flex-start; }
  .btn { min-height: 40px; padding: 0 14px; }
}

.status-pill.locked { background: #fff7ed; color: #c2410c; }
.drawing-row.locked { border-color: rgba(194, 65, 12, .28); background: #fffaf5; }
.viewer-banner {
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--fip-line);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}
.viewer-banner.readonly { background: #fff7ed; color: #9a3412; }
.viewer-banner.warning { background: #fef3c7; color: #92400e; justify-content: space-between; }
.viewer-banner .banner-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.marker.readonly { transition: left .28s ease, top .28s ease; }
.marker.pulse { animation: markerPulse 1.2s ease-out 1; }
@keyframes markerPulse {
  0% { box-shadow: 0 0 0 0 rgba(192, 57, 43, .55), 0 4px 12px rgba(0,0,0,.25); transform: translate(-50%, -50%) scale(.86); }
  60% { box-shadow: 0 0 0 10px rgba(192, 57, 43, 0), 0 4px 12px rgba(0,0,0,.25); transform: translate(-50%, -50%) scale(1.08); }
  100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0), 0 4px 12px rgba(0,0,0,.25); transform: translate(-50%, -50%) scale(1); }
}
@media (max-width: 720px) {
  .viewer-banner { flex-direction: column; align-items: stretch; }
  .viewer-banner.warning { justify-content: center; }
  .viewer-banner .banner-actions { justify-content: center; }
}

/* Tag tracking and revision review */
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.small-modal { width: min(520px, 100%); }
.tag-chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip { border: 1px solid var(--fip-line); background: #fff; border-radius: 999px; padding: 8px 12px; font-weight: 800; color: var(--fip-text); }
.tag-chip.selected { border-color: var(--fip-red); background: #fdebea; color: var(--fip-red); }
.detected-tag { border: 1px solid var(--fip-line); border-radius: 16px; padding: 14px; background: #f8fafc; font-size: 24px; font-weight: 900; text-align: center; letter-spacing: .02em; }
.progress-block { margin-top: 10px; max-width: 360px; }
.progress-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; color: var(--fip-muted); margin-bottom: 5px; }
.progress-head strong { color: var(--fip-text); }
.progress-track { height: 8px; background: #e9eef5; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--fip-green); border-radius: inherit; transition: width .25s ease; }
.status-pill.review-green { background: #e6f6ec; color: var(--fip-green); }
.status-pill.review-amber { background: #fff7ed; color: #c2410c; }
.status-pill.review-red { background: #fdebea; color: var(--fip-red); }
.compare-bar { z-index: 15; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px 12px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--fip-line); font-size: 13px; font-weight: 800; }
.compare-bar label { color: var(--fip-muted); font-weight: 700; }
.compare-bar input[type="range"] { width: min(260px, 38vw); accent-color: var(--fip-red); }
.previous-pdf-canvas { position: absolute; top: 0; left: 0; z-index: 0; }
.current-pdf-canvas { position: relative; z-index: 1; }
.marker { width: auto; height: auto; min-width: 24px; min-height: 24px; flex-direction: column; gap: 2px; padding: 1px; border-color: var(--fip-dark); }
.marker-qr { display: flex; align-items: center; justify-content: center; background: #fff; }
.marker-label { font-size: 8px; line-height: 1; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fip-dark); font-weight: 900; background: rgba(255,255,255,.92); padding: 1px 2px; border-radius: 2px; }
.marker.review-automoved { border-color: var(--fip-green); background: #e6f6ec; box-shadow: 0 0 0 3px rgba(22,128,60,.16), 0 4px 12px rgba(0,0,0,.25); }
.marker.review-review { border-color: #c2410c; background: #fff7ed; box-shadow: 0 0 0 3px rgba(194,65,12,.16), 0 4px 12px rgba(0,0,0,.25); }
.marker.review-missing { border-color: var(--fip-red); background: #fdebea; box-shadow: 0 0 0 3px rgba(192,57,43,.16), 0 4px 12px rgba(0,0,0,.25); }
.tag-panel { position: absolute; right: 18px; top: calc(120px + var(--safe-top)); bottom: calc(84px + var(--safe-bottom)); z-index: 55; width: min(390px, calc(100vw - 36px)); background: rgba(255,255,255,.94); backdrop-filter: blur(10px); border: 1px solid var(--fip-line); border-radius: 22px; box-shadow: 0 24px 80px rgba(23,32,46,.24); display: flex; flex-direction: column; overflow: hidden; touch-action: pan-y; }
.tag-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px; border-bottom: 1px solid var(--fip-line); background: rgba(255,255,255,.9); }
.tag-panel-head h3 { margin: 0; font-size: 18px; }
.tag-panel-head p { margin: 4px 0 0; }
.tag-list { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 7px; }
.tag-list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border: 1px solid var(--fip-line); border-radius: 14px; background: #fff; }
.tag-list-row.done { background: #f8fafc; }
.tag-list-row.automoved { border-color: rgba(22,128,60,.32); background: #f0fbf4; }
.tag-list-row.review { border-color: rgba(194,65,12,.32); background: #fff7ed; }
.tag-list-row.missing { border-color: rgba(192,57,43,.32); background: #fff5f4; }
.tag-list-id { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
  .compare-bar { flex-wrap: wrap; }
  .tag-panel { top: calc(108px + var(--safe-top)); left: 10px; right: 10px; width: auto; bottom: calc(78px + var(--safe-bottom)); }
  .progress-block { max-width: none; }
}
