/* =============================================================================
   [정푸드코리아] 에이전틱 AI 스마트 HACCP 전용 관제 콘솔 스타일시트
   JungFood Agentic AI Smart HACCP Operations Console (Pure Offline CSS3)
   - Zero External CDN Dependencies, Factory Waterproof Tablet Touch-Optimized
   - 4대 뷰: Document / Audit / Editor / Agent
   ============================================================================= */

:root {
  /* Color Palette (Deep Navy / Industrial Dark Mode) */
  --bg: #0b131e;
  --bg-darker: #070c14;
  --surface: #131f2f;
  --surface-elevated: #1a2a3f;
  --surface-hover: #223752;
  --border: #233348;
  --border-light: #324763;
  --border-focus: #5b90d6;

  /* Status Accents */
  --accent: #5b90d6;
  --accent-hover: #72a3e3;
  --accent2: #38bdf8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Typography & Sizing */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", Arial, sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

  /* ERP Compatibility Tokens (if queried by legacy inspection) */
  --sidebar-w: 0px;
  --sidebar-width: 220px;
  --navy: #1b3b6f;
  --erp-navy-deep: #0b131e;
  --erp-navy-primary: #1b3b6f;
}

/* ERP Sidebar & Layout Compatibility */
.app-sidebar {
  width: 220px;
  min-width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.app-body-container {
  display: flex;
  flex: 1;
  width: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.agentic-haccp-app,
body.erp-shell {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* Background Ambient Glow */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
}
.blob-1 { width: 500px; height: 500px; background: #2563eb; top: -100px; left: -100px; }
.blob-2 { width: 450px; height: 450px; background: #059669; bottom: 50px; right: -50px; }
.blob-3 { width: 400px; height: 400px; background: #7c3aed; top: 40%; left: 40%; }

/* =============================================================================
   1. Distinct Header Bar
   ============================================================================= */
.haccp-header,
.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 1.8rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.brand-title,
.page-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--accent2);
  font-weight: 500;
  display: block;
}

.header-center {
  display: flex;
  align-items: center;
}

.system-status-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.operator-profile-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-elevated);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.operator-profile-box label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.operator-select {
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.operator-select option {
  background: var(--surface);
  color: var(--text);
}

.header-clock {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-mock { background: rgba(59, 130, 246, 0.18); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.35); }
.badge-fail-closed { background: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.35); }
.badge-isolated { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.35); }
.badge-info { background: rgba(14, 165, 233, 0.18); color: #38bdf8; border: 1px solid rgba(14, 165, 233, 0.35); }
.badge-warning { background: var(--warn-bg); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.35); }
.badge-unverified { background: rgba(107, 114, 128, 0.2); color: #d1d5db; border: 1px solid rgba(156, 163, 175, 0.45); }
.document-node-unverified { color: #9ca3af; opacity: 0.82; }
.badge-danger { background: var(--danger-bg); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.35); }
.badge-success { background: var(--success-bg); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.35); }
.badge-discrepancy { background: rgba(168, 85, 247, 0.18); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.35); }

/* =============================================================================
   2. Realtime Operations & Safety KPI Banner
   ============================================================================= */
.haccp-kpi-banner {
  background: var(--bg-darker);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: relative;
  z-index: 10;
}

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

.kpi-banner-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  transition: transform 0.15s, border-color 0.15s;
}

.kpi-banner-item:hover {
  border-color: var(--border-light);
}

.kpi-banner-item.ari-item {
  border-left: 4px solid var(--warn);
}

.kpi-banner-item.danger-item {
  border-left: 4px solid var(--danger);
}

.kpi-banner-item.ccp-item {
  border-left: 4px solid var(--success);
}

.kpi-banner-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}

.kpi-banner-val-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.kpi-banner-val {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.kpi-banner-unit {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.kpi-banner-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: auto;
}
.tag-warning { background: var(--warn-bg); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.tag-success { background: var(--success-bg); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }

.kpi-banner-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =============================================================================
   3. Compliance Notice Banner
   ============================================================================= */
.compliance-banner {
  background: rgba(30, 41, 59, 0.7);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  position: relative;
  z-index: 10;
}

.compliance-text {
  display: flex;
  align-items: center;
  gap: 10px;
}

.banner-icon {
  font-size: 1rem;
}

/* =============================================================================
   4. Primary 4 Core Views Navigation Bar
   ============================================================================= */
.haccp-views-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 64px;
  z-index: 90;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.nav-tabs-container {
  display: flex;
  gap: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
}

.nav-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.nav-tab.active {
  color: #ffffff;
  border-bottom-color: var(--accent);
  background: rgba(91, 144, 214, 0.08);
}

.tab-icon {
  font-size: 1.1rem;
}

.tab-chip {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--surface-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
}

.tab-chip.pulse {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.tab-badge {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}
.tab-badge.badge-accent { background: var(--accent); color: #ffffff; }
.tab-badge.badge-danger { background: var(--danger); color: #ffffff; }

/* =============================================================================
   5. Main View Workspace & Panels
   ============================================================================= */
.haccp-main-workspace {
  flex: 1;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.view-panel {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.view-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.panel-title-group h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffffff;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* =============================================================================
   6. Split Layouts & Sub-Panes
   ============================================================================= */
.split-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1024px) {
  .split-layout {
    grid-template-columns: 1fr;
  }
}

.split-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

/* Tree Component */
.tree-header {
  margin-bottom: 16px;
}

.tree-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.tree-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tree-tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tree-tab.active {
  background: var(--accent);
  color: #ffffff;
}

.tree-content {
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
}

.tree-item:hover,
.tree-item.active {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.discrepancy-box {
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
}

.doc-meta-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.document-warning,
.document-load-error {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
}

.document-warning {
  color: #d1d5db;
  background: rgba(107, 114, 128, 0.18);
  border: 1px solid rgba(156, 163, 175, 0.45);
}

.document-load-error {
  color: #fca5a5;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.4);
  overflow-wrap: anywhere;
}

.document-loading {
  margin-top: 16px;
  color: var(--text-muted);
}

.document-child-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.document-child-links h5 {
  flex-basis: 100%;
  margin: 0 0 4px;
}

.document-markdown-body {
  margin: 16px 0 0;
  padding: 18px;
  max-height: 620px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: 0.88rem/1.65 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.document-proposal-workbench { display: grid; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.document-proposal-workbench label { display: grid; gap: 5px; color: var(--text-muted); font-size: .8rem; }
.document-diff { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
.service-state { margin-left: 10px; font-size: .78rem; font-weight: 700; }
.service-state.connected { color: var(--success); }
.service-state.disconnected { color: var(--danger); }
.document-proposal-results { margin-top: 16px; display: grid; gap: 12px; }
.proposal-list { display: grid; gap: 10px; }
.proposal-list-item { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-elevated); }
.proposal-list-item pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 140px; overflow: auto; }
.proposal-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.proposal-actions input { min-width: 220px; flex: 1; }
.proposal-actions button:disabled { opacity: .45; cursor: not-allowed; }
.history-timeline { border-left: 2px solid var(--accent); margin-left: 6px; padding-left: 16px; display: grid; gap: 12px; }
.timeline-item { position: relative; padding: 10px; background: var(--surface-elevated); border-radius: var(--radius-md); }
.timeline-item::before { content: ''; position: absolute; left: -22px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline-item span { float: right; color: var(--text-muted); font-size: .75rem; }
.timeline-item p { margin-top: 6px; white-space: pre-wrap; }

.corpus-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.corpus-stat-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}

.cs-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.cs-val {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent2);
  margin: 2px 0;
}

.cs-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
}

.markdown-preview-box {
  background: var(--bg-darker);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  min-height: 240px;
  max-height: 380px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* =============================================================================
   7. Tables & Data Presentations
   ============================================================================= */
.card-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.card-section h3,
.card-section h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.data-table th {
  background: var(--surface-elevated);
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--surface-hover);
}

/* =============================================================================
   8. Guardrail Banners & Simulators
   ============================================================================= */
.guard-banner {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.guard-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.guard-content h4 {
  font-size: 0.95rem;
  color: #fbbf24;
  margin-bottom: 4px;
}

.guard-content p {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

.interlock-simulator-card {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(15, 23, 42, 0.8));
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.interlock-simulator-card h3 {
  font-size: 1.1rem;
  color: #f87171;
  margin-bottom: 6px;
}

.interlock-simulator-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.sim-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* =============================================================================
   9. Stepper & AI Proposals & Approvals
   ============================================================================= */
.approval-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 24px;
  margin-bottom: 20px;
  gap: 12px;
}

.step-card {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  text-align: center;
}

.step-card.active {
  border-color: var(--accent);
  background: rgba(91, 144, 214, 0.15);
}

.step-num {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.step-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
  margin: 2px 0;
}

.step-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.step-arrow {
  font-size: 1.2rem;
  color: var(--text-dim);
}

.proposal-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 14px;
}

.proposal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.ai-rationale-box {
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.8rem;
  margin-top: 12px;
}

.proposal-decision-bar {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.decision-buttons {
  display: flex;
  gap: 8px;
}

.agent-activity-stream {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.activity-item {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 0.82rem;
}

.activity-time {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* =============================================================================
   10. Form Controls & Buttons
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
}

.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }

.btn-success { background: var(--success); color: #ffffff; }
.btn-warning { background: var(--warn); color: #000000; }
.btn-danger { background: var(--danger); color: #ffffff; }

.btn-outline { background: transparent; border: 1px solid var(--border-light); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-outline-danger { background: transparent; border: 1px solid var(--danger); color: #f87171; }
.btn-outline-danger:hover { background: var(--danger-bg); }

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
}
.btn-sm:hover {
  background: var(--surface-hover);
}

.form-control {
  background: var(--bg-darker);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
}

/* =============================================================================
   11. Signature Canvas Modal
   ============================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

.canvas-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  margin: 14px 0 10px 0;
  overflow: hidden;
}

#signatureCanvas {
  width: 100%;
  height: 180px;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.canvas-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sig-meta-inputs .form-row {
  margin-bottom: 10px;
}
.sig-meta-inputs label {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-darker);
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.text-danger { color: #f87171 !important; }
.text-success { color: #34d399 !important; }
.text-accent { color: var(--accent) !important; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 24px; }

/* =============================================================================
   Operations Report View Specific Styling
   ============================================================================= */
.pane-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.pane-header-row h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
}

/* F3(웨이브4): 결과보고 탭 실데이터 요약 (app.js loadOperationsReport) — 구 triage·보고서 링크 카드 스타일 대체 */
.report-live-root { display: flex; flex-direction: column; gap: 16px; }
.report-checked-at { margin: 0; }
.report-live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.report-live-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-width: 0;
}
.report-live-card h3 { font-size: 1rem; font-weight: 700; margin: 0 0 12px; color: var(--text); }
.report-live-card .num { text-align: right; font-variant-numeric: tabular-nums; }
.report-total-row td { font-weight: 700; border-top: 2px solid var(--border-light); }
.report-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.report-kv dt { color: var(--text-muted); font-size: 0.85rem; }
.report-kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.report-probe {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm);
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.report-probe-ok { background: var(--success-bg); color: var(--success); }
.report-probe-warn { background: var(--warn-bg); color: var(--warn); }
.report-probe-bad { background: var(--danger-bg); color: var(--danger); }
.report-probe-unknown { background: var(--surface-elevated); color: var(--text-muted); }
.report-probe-mock { background: var(--warn-bg); color: var(--warn); border: 1px dashed var(--warn); }

/* F3: 목업 값 표기 태그 (KPI 배너·목업 시연 탭) · 런타임 값 미확정 탭 뱃지 */
.kpi-mock-tag {
  display: inline-block; margin-left: 4px; padding: 0 5px;
  border: 1px dashed var(--warn); border-radius: var(--radius-sm);
  color: var(--warn); font-size: 0.65rem; font-weight: 700; letter-spacing: 0.04em;
  vertical-align: middle;
}
.kpi-mock-tag.kpi-prov-connected {
  border: 1px solid var(--success);
  color: var(--success);
  background: var(--success-bg, rgba(16, 185, 129, 0.1));
}
.kpi-mock-tag.kpi-prov-simulated {
  border: 1px dashed var(--warn);
  color: var(--warn);
  background: var(--warn-bg, rgba(245, 158, 11, 0.1));
}
.kpi-mock-tag.kpi-prov-not-connected {
  border: 1px solid var(--danger);
  color: var(--danger);
  background: var(--danger-bg, rgba(239, 68, 68, 0.1));
}
.tab-badge.badge-unknown { opacity: 0.55; }

/* Responsive 390px Mobile Viewport Rules */
@media (max-width: 480px), (max-width: 390px) {
  .app-sidebar {
    width: 100%;
    min-width: 390px;
  }
}

/* ---------------------------------------------------------------------------
   Toast Notifications (success / error / warning · 5초 자동 닫힘)
   --------------------------------------------------------------------------- */
.toast-container {
  position: fixed; right: 20px; bottom: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px; max-width: min(460px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--surface-elevated); border: 1px solid var(--border-light); border-left-width: 4px;
  color: var(--text); font-size: .86rem; line-height: 1.45;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: toast-in .18s ease-out;
  overflow-wrap: anywhere;
}
.toast-success { border-left-color: var(--success); background: linear-gradient(90deg, var(--success-bg), var(--surface-elevated) 40%); }
.toast-error   { border-left-color: var(--danger);  background: linear-gradient(90deg, var(--danger-bg),  var(--surface-elevated) 40%); }
.toast-warning { border-left-color: var(--warn);    background: linear-gradient(90deg, var(--warn-bg),    var(--surface-elevated) 40%); }
.toast-info    { border-left-color: var(--accent); }
.toast-icon { font-weight: 800; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon   { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warn); }
.toast-info .toast-icon    { color: var(--accent); }
.toast-close {
  background: transparent; border: 0; color: var(--text-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 2px;
}
.toast-close:hover { color: var(--text); }
.toast-hide { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------------------
   approval-identity 로그인 세션 박스 (헤더)
   --------------------------------------------------------------------------- */
.identity-login-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.identity-login-form { display: flex; align-items: center; gap: 6px; }
.identity-login-form .form-control { width: 130px; padding: 4px 8px; font-size: .8rem; }
.auth-status { font-size: .74rem; font-weight: 700; white-space: nowrap; }
.auth-status.connected { color: var(--success); }
.auth-status.disconnected { color: var(--warn); }
.operator-select:disabled { opacity: .55; cursor: not-allowed; }

/* header: 로그인 박스 추가 후 줄바꿈 허용 · 라벨 세로 깨짐 방지 */
.header-right { flex-wrap: wrap; row-gap: 6px; justify-content: flex-end; }
.operator-profile-box label { white-space: nowrap; }
.proposal-meta { margin: 4px 0 6px; }
.history-timeline pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 120px; overflow: auto; font-size: .78rem; }


/* =============================================================================
   D1 · 문서관리 탭 ERP 모듈 테마 (body.erp-doc-mode 스코프 — 문서관리 탭 활성 시에만)
   - JFK ERP index.html 의 [data-theme="light"] / :root(dark) 토큰을 그대로 내장
     (ERP assets 경로 의존 없음 · 실제 ERP 편입 시 ERP 공통 헤더/사이드메뉴가 감싸므로
      본 앱은 콘텐츠 영역 규격(폭·여백·타이포)만 ERP 페이지와 일치시킨다)
   - 라이트 기본 · [data-theme="dark"] 는 ERP 다크 토큰(ERP 가 지원하는 범위)
   - 다른 탭(감사/에디터/센티넬/보고)은 기존 관제콘솔 스타일 그대로(범위 외)
   ============================================================================= */
body.erp-doc-mode {
  /* ── ERP 라이트 토큰 (ERP index.html L368~383 · L385 body #f2f4f7) ── */
  --erp-bg: #eef1f6;
  --erp-body-bg: #f2f4f7;
  --erp-surface: #ffffff;
  --erp-surface-2: #f7f9fc;
  --erp-border: #d7dee8;
  --erp-text: #16233d;
  --erp-muted: #5b6b85;
  --erp-accent: #2b5ea3;
  --erp-accent2: #2f8f5b;
  --erp-navy: #14284a;
  --erp-warn: #c08a2e;
  --erp-danger: #b23a3b;
  --erp-success: #2f8f5b;
  --erp-hover: rgba(0, 0, 0, .05);
  --erp-accent-soft: rgba(43, 94, 163, .12);
  --erp-th-border: rgba(60, 60, 67, .12);
  --erp-td-border: rgba(60, 60, 67, .08);
  --erp-input-border: rgba(60, 60, 67, .22);
  --erp-focus-ring: rgba(0, 122, 255, .12);
  --erp-primary-shadow: 0 2px 6px rgba(0, 122, 255, .25);
  /* ── 서체 2종: UI = ERP body 스택(Pretendard → 시스템 → 맑은고딕) · 본문 = 기준서 인쇄체(명조) ── */
  --erp-font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  --erp-doc-font: 'Noto Serif KR', 'Nanum Myeongjo', 'Batang', 'BatangChe', serif;
  /* ── 간격/치수 (ERP .content 24px · .card 20px · .grid gap 16px · topbar 52px · radius 6px) ── */
  --erp-topbar-h: 52px;
  --erp-content-pad: 24px;
  --erp-card-pad: 20px;
  --erp-gap: 16px;
  --erp-radius: 6px;
  --erp-radius-ctl: 8px;
  --erp-tree-w: 260px;
  --erp-meta-w: 340px;
  --erp-doc-measure: 65em;   /* 본문 한글 전각 65자 상한 */
  /* ── 기존 관제콘솔 토큰을 문서탭 범위에서만 ERP 값으로 재매핑 (C2 렌더 요소·토스트 자동 수렴) ── */
  --bg: var(--erp-bg);
  --bg-darker: var(--erp-bg);
  --surface: var(--erp-surface);
  --surface-elevated: var(--erp-surface-2);
  --surface-hover: var(--erp-hover);
  --border: var(--erp-border);
  --border-light: #c5cfdd;
  --border-focus: var(--erp-accent);
  --accent: var(--erp-accent);
  --accent-hover: #244f8a;
  --accent2: var(--erp-accent2);
  --success: var(--erp-success);
  --success-bg: rgba(47, 143, 91, .12);
  --warn: var(--erp-warn);
  --warn-bg: rgba(192, 138, 46, .14);
  --danger: var(--erp-danger);
  --danger-bg: rgba(178, 58, 59, .10);
  --text: var(--erp-text);
  --text-muted: var(--erp-muted);
  --text-dim: #7c8aa3;
  --font-family: var(--erp-font);
  --radius-sm: 4px;
  --radius-md: var(--erp-radius);
  --radius-lg: var(--erp-radius);
  --radius-xl: 8px;
  --shadow-sm: none;
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .12);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .06);

  background: var(--erp-body-bg);
  color: var(--erp-text);
  font-family: var(--erp-font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ERP 다크 토큰 (ERP index.html :root L343~353) — ERP 가 지원하는 경우에만 사용 */
body.erp-doc-mode[data-theme="dark"],
:root[data-theme="dark"] body.erp-doc-mode {
  --erp-bg: #0e1622;
  --erp-body-bg: #0e1622;
  --erp-surface: #16202e;
  --erp-surface-2: #1b2636;
  --erp-border: #2a3648;
  --erp-text: #e7ebf2;
  --erp-muted: #8d9bb3;
  --erp-accent: #5b90d6;
  --erp-accent2: #4a8fa0;
  --erp-navy: #1b3b6f;
  --erp-warn: #d2a24c;
  --erp-danger: #d96666;
  --erp-success: #4fb57e;
  --erp-hover: rgba(43, 94, 163, .08);
  --erp-accent-soft: rgba(91, 144, 214, .18);
  --erp-th-border: #2a3648;
  --erp-td-border: rgba(42, 54, 72, .6);
  --erp-input-border: #2a3648;
  --erp-focus-ring: rgba(91, 144, 214, .2);
  --erp-primary-shadow: 0 2px 8px rgba(43, 94, 163, .3);
  --border-light: #3a4a62;
  --text-dim: #6f7f9a;
  -webkit-font-smoothing: auto;
}

body.erp-doc-mode .bg-blobs { display: none; }

/* ── 상단바: ERP .topbar 규격(52px · surface · 하단 1px) ─────────────────────── */
body.erp-doc-mode .haccp-header {
  position: static;
  height: auto;
  min-height: var(--erp-topbar-h);
  padding: 6px var(--erp-content-pad);
  gap: 12px 20px;
  flex-wrap: wrap;
  background: var(--erp-surface);
  border-bottom: 1px solid var(--erp-th-border);
  box-shadow: none;
}
body.erp-doc-mode .header-left { gap: 14px; min-width: 0; }
body.erp-doc-mode .brand-icon,
body.erp-doc-mode .brand-sub,
body.erp-doc-mode .header-center { display: none; }
body.erp-doc-mode .brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.3px;
  color: var(--erp-text);
  white-space: nowrap;
}
.erp-breadcrumb, .erp-theme-toggle { display: none; }
body.erp-doc-mode .erp-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--erp-border);
  font-size: 13px;
  color: var(--erp-muted);
  white-space: nowrap;
}
body.erp-doc-mode .erp-breadcrumb-sep { color: var(--erp-border); }
body.erp-doc-mode .erp-breadcrumb-current { color: var(--erp-text); font-weight: 600; }
body.erp-doc-mode .header-right { gap: 10px; }
body.erp-doc-mode .identity-login-form .form-control,
body.erp-doc-mode .operator-profile-box {
  background: var(--erp-surface);
  border: 1px solid var(--erp-input-border);
  border-radius: var(--erp-radius-ctl);
  color: var(--erp-text);
  font-family: inherit;
}
body.erp-doc-mode .identity-login-form .form-control { padding: 6px 10px; font-size: 13px; width: 132px; }
body.erp-doc-mode .identity-login-form .form-control:focus { border-color: var(--erp-accent); box-shadow: 0 0 0 3px var(--erp-focus-ring); }
body.erp-doc-mode .operator-profile-box { padding: 4px 10px; gap: 6px; }
body.erp-doc-mode .operator-profile-box label { font-size: 12px; color: var(--erp-muted); }
body.erp-doc-mode .operator-select { font-size: 13px; font-weight: 500; color: var(--erp-text); font-family: inherit; }
body.erp-doc-mode .operator-select option { background: var(--erp-surface); color: var(--erp-text); }
body.erp-doc-mode .auth-status { font-size: 12px; font-weight: 600; }
body.erp-doc-mode .header-clock {
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--erp-muted);
  background: transparent;
  border: 0;
  padding: 0;
}
body.erp-doc-mode .erp-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 30px;
  background: none;
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-ctl);
  color: var(--erp-muted);
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
}
body.erp-doc-mode .erp-theme-toggle:hover { border-color: var(--erp-accent); color: var(--erp-accent); }

/* 목업 KPI 타일·컴플라이언스(센티넬) 배너 — 문서탭에서 제거 */
body.erp-doc-mode .haccp-kpi-banner,
body.erp-doc-mode .compliance-banner { display: none; }

/* ── 뷰 전환 탭: ERP .appr-tab(밑줄 + 개수 배지) ─────────────────────────── */
body.erp-doc-mode .haccp-views-nav {
  position: static;
  padding: 0 var(--erp-content-pad);
  background: var(--erp-surface);
  border-bottom: 1px solid var(--erp-border);
  box-shadow: none;
}
body.erp-doc-mode .nav-tabs-container { gap: 22px; overflow-x: auto; scrollbar-width: none; }
body.erp-doc-mode .nav-tabs-container::-webkit-scrollbar { display: none; }
body.erp-doc-mode .nav-tab {
  position: relative;
  padding: 11px 1px 12px;
  gap: 6px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--erp-muted);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
body.erp-doc-mode .nav-tab:hover { color: var(--erp-text); background: transparent; }
body.erp-doc-mode .nav-tab.active { color: var(--erp-accent); border-bottom-color: var(--erp-accent); font-weight: 700; background: transparent; }
body.erp-doc-mode .tab-icon { display: none; }
body.erp-doc-mode .tab-chip,
body.erp-doc-mode .tab-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--erp-border);
  color: var(--erp-muted);
  border: 0;
}
body.erp-doc-mode .nav-tab.active .tab-chip,
body.erp-doc-mode .nav-tab.active .tab-badge { background: var(--erp-accent-soft); color: var(--erp-accent); }
body.erp-doc-mode .tab-badge.badge-danger { background: rgba(178, 58, 59, .12); color: var(--erp-danger); }

/* ── 콘텐츠 영역: ERP .content(padding 24px) ─────────────────────────────── */
body.erp-doc-mode .haccp-main-workspace { padding: var(--erp-content-pad); }
body.erp-doc-mode .view-panel { animation: none; }

/* 상태 칩 (ERP .chip + 라이트 테두리 복원 규칙) */
body.erp-doc-mode .chip,
body.erp-doc-mode #view-document .badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
  white-space: nowrap;
  border: 1px solid transparent;
}
body.erp-doc-mode .chip-green,
body.erp-doc-mode #view-document .badge-success { background: rgba(34, 197, 94, .15); color: var(--erp-success); border-color: rgba(34, 197, 94, .40); }
body.erp-doc-mode .chip-yellow,
body.erp-doc-mode #view-document .badge-warning,
body.erp-doc-mode #view-document .badge-unverified { background: rgba(245, 158, 11, .15); color: var(--erp-warn); border-color: rgba(245, 158, 11, .40); }
body.erp-doc-mode .chip-red,
body.erp-doc-mode #view-document .badge-danger { background: rgba(239, 68, 68, .15); color: var(--erp-danger); border-color: rgba(239, 68, 68, .40); }
body.erp-doc-mode .chip-blue,
body.erp-doc-mode #view-document .badge-info { background: rgba(43, 94, 163, .15); color: var(--erp-accent); border-color: rgba(43, 94, 163, .40); }
body.erp-doc-mode .chip-gray,
body.erp-doc-mode #view-document .badge-isolated,
body.erp-doc-mode #view-document .badge-mock { background: rgba(128, 128, 128, .14); color: var(--erp-muted); border-color: rgba(128, 128, 128, .35); }
body.erp-doc-mode .chip-blue > span,
body.erp-doc-mode .chip-green > span,
body.erp-doc-mode .chip-yellow > span { font-variant-numeric: tabular-nums; }

/* ── 문서관리 탭 헤더: ERP .sec-head ─────────────────────────────────────── */
body.erp-doc-mode #view-document .panel-header { margin-bottom: var(--erp-gap); gap: 10px; }
body.erp-doc-mode #view-document .panel-title-group { display: grid; gap: 3px; }
body.erp-doc-mode #view-document .panel-title-group h2 { font-size: 15px; font-weight: 600; color: var(--erp-text); letter-spacing: -.2px; }
body.erp-doc-mode #view-document .panel-title-group .text-sm { font-size: 12px; color: var(--erp-muted); }
body.erp-doc-mode #view-document .standards-meta-badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── 3열: 목차(트리) / 본문 / 문서정보·개정이력·결재 ──────────────────────── */
body.erp-doc-mode #view-document .split-layout {
  display: grid;
  grid-template-columns: var(--erp-tree-w) minmax(0, 1fr) var(--erp-meta-w);
  gap: var(--erp-gap);
  align-items: start;
}
body.erp-doc-mode #view-document .split-pane {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-width: 0;
}

/* 1열 · 목차 트리 (ERP 사이드 .nav-item 규격: 13px · 9px 라운드 · hover rgba(0,0,0,.05) · active 액센트) */
body.erp-doc-mode .pane-tree {
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
  position: sticky;
  top: var(--erp-gap);
  max-height: calc(100vh - var(--erp-gap) * 2);
  overflow: hidden;
}
body.erp-doc-mode .tree-header { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--erp-border); }
body.erp-doc-mode .tree-header h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--erp-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
body.erp-doc-mode .tree-content { max-height: calc(100vh - var(--erp-gap) * 2 - 44px); padding: 8px; gap: 1px; }
body.erp-doc-mode .document-node-group { margin-top: 6px; }
body.erp-doc-mode .document-node-group:first-child { margin-top: 0; }
body.erp-doc-mode .tree-item.document-chapter {
  display: grid;
  gap: 1px;
  padding: 10px 10px 6px;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: default;
}
body.erp-doc-mode .tree-item.document-chapter strong { font-size: 10px; color: var(--erp-muted); letter-spacing: .08em; text-transform: uppercase; }
body.erp-doc-mode .tree-item.document-chapter span { font-size: 12.5px; font-weight: 600; color: var(--erp-text); }
body.erp-doc-mode .tree-item.document-section {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: 0;
  border-radius: 9px;
  color: var(--erp-text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
body.erp-doc-mode .tree-item.document-section:hover { background: var(--erp-hover); color: var(--erp-text); }
body.erp-doc-mode .tree-item.document-section:focus-visible { outline: 2px solid var(--erp-accent); outline-offset: -2px; }
body.erp-doc-mode .tree-item.document-section.active { background: var(--erp-accent); color: #fff; box-shadow: var(--erp-primary-shadow); }
body.erp-doc-mode .tree-item.document-section.active .chip { background: rgba(255, 255, 255, .22); color: #fff; border-color: rgba(255, 255, 255, .35); }
body.erp-doc-mode .tree-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.erp-doc-mode .tree-chip { padding: 1px 6px; font-size: 10px; flex-shrink: 0; }
body.erp-doc-mode .document-node-unverified { color: var(--erp-muted); opacity: 1; }

/* 2열 · 본문 */
body.erp-doc-mode .doc-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  max-width: var(--erp-doc-measure);
}
body.erp-doc-mode .doc-viewer-header h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--erp-text); letter-spacing: -.2px; }
body.erp-doc-mode .doc-viewer-actions { display: flex; gap: 6px; }
body.erp-doc-mode .markdown-preview-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-height: 0;
  max-height: none;
  overflow: visible;
  font-size: inherit;
  line-height: inherit;
}
body.erp-doc-mode .doc-empty-hint {
  max-width: var(--erp-doc-measure);
  padding: 40px 24px;
  border: 1px dashed var(--erp-border);
  border-radius: var(--erp-radius);
  color: var(--erp-muted);
  font-size: 13px;
  text-align: center;
}
/* 기준서 인쇄체 종이 시트 — ERP 지출결의서 서식 원칙(테마와 무관하게 흰 종이·검정 글자) */
body.erp-doc-mode .doc-paper {
  margin: 0;
  max-width: var(--erp-doc-measure);
  max-height: none;
  overflow: visible;
  padding: 40px 48px;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
  font: 15px/1.8 var(--erp-doc-font);
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
body.erp-doc-mode .doc-paper h1 { font-size: 22px; font-weight: 700; margin: 0 0 16px; padding-bottom: 10px; border-bottom: 2px solid #1a1a1a; letter-spacing: -.01em; line-height: 1.4; }
body.erp-doc-mode .doc-paper h2 { font-size: 19px; font-weight: 700; margin: 28px 0 10px; line-height: 1.45; }
body.erp-doc-mode .doc-paper h3 { font-size: 17px; font-weight: 700; margin: 24px 0 8px; line-height: 1.5; }
body.erp-doc-mode .doc-paper h4 { font-size: 15.5px; font-weight: 700; margin: 18px 0 6px; line-height: 1.6; }
body.erp-doc-mode .doc-paper h5 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
body.erp-doc-mode .doc-paper h6 { font-size: 14px; font-weight: 700; margin: 12px 0 4px; color: #333; }
body.erp-doc-mode .doc-paper h1:first-child, body.erp-doc-mode .doc-paper h2:first-child, body.erp-doc-mode .doc-paper h3:first-child { margin-top: 0; }
body.erp-doc-mode .doc-paper p { margin: 0 0 10px; }
body.erp-doc-mode .doc-paper ul, body.erp-doc-mode .doc-paper ol { margin: 0 0 10px 1.5em; padding: 0; }
body.erp-doc-mode .doc-paper li { margin: 2px 0; }
body.erp-doc-mode .doc-paper li > ul, body.erp-doc-mode .doc-paper li > ol { margin-bottom: 0; margin-top: 2px; }
body.erp-doc-mode .doc-paper blockquote { margin: 0 0 12px; padding: 8px 14px; border-left: 3px solid var(--erp-accent); background: #f5f7fa; color: #333; font-size: 13.5px; }
body.erp-doc-mode .doc-paper blockquote p:last-child { margin-bottom: 0; }
body.erp-doc-mode .doc-paper hr { border: 0; border-top: 1px solid #c9ced6; margin: 16px 0; }
body.erp-doc-mode .doc-paper table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 13px; line-height: 1.55; }
body.erp-doc-mode .doc-paper th, body.erp-doc-mode .doc-paper td { border: 1px solid #555; padding: 6px 8px; vertical-align: top; }
body.erp-doc-mode .doc-paper th { background: #eee; font-weight: 700; text-align: center; white-space: nowrap; }
body.erp-doc-mode .doc-paper code { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; background: #f1f3f5; padding: 1px 5px; border-radius: 3px; }
body.erp-doc-mode .doc-paper pre { margin: 0 0 12px; padding: 12px 14px; background: #f1f3f5; border-radius: 4px; overflow: auto; }
body.erp-doc-mode .doc-paper pre code { background: transparent; padding: 0; }
body.erp-doc-mode .doc-paper a { color: var(--erp-accent); }
body.erp-doc-mode .doc-raw { max-width: var(--erp-doc-measure); font-size: 12px; color: var(--erp-muted); }
body.erp-doc-mode .doc-raw summary { cursor: pointer; padding: 4px 0; }
body.erp-doc-mode .doc-raw pre {
  margin-top: 8px;
  padding: 14px;
  max-height: 480px;
  overflow: auto;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
  color: var(--erp-text);
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
body.erp-doc-mode .document-warning,
body.erp-doc-mode .document-load-error,
body.erp-doc-mode .document-loading {
  max-width: var(--erp-doc-measure);
  margin: 0;
}
body.erp-doc-mode .document-warning {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 14px;
  background: rgba(245, 158, 11, .12);
  border: 1px solid rgba(245, 158, 11, .40);
  border-radius: var(--erp-radius);
  color: var(--erp-text);
  font-size: 13px;
}
body.erp-doc-mode .document-warning strong { color: var(--erp-warn); }
body.erp-doc-mode .document-load-error {
  padding: 10px 14px;
  background: var(--danger-bg);
  border: 1px solid rgba(178, 58, 59, .4);
  border-radius: var(--erp-radius);
  color: var(--erp-danger);
  font-size: 13px;
}
body.erp-doc-mode .document-loading { font-size: 13px; color: var(--erp-muted); }
body.erp-doc-mode .document-child-links {
  order: 10;
  max-width: var(--erp-doc-measure);
  margin: 0;
  padding: 12px 14px;
  gap: 6px;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
}
body.erp-doc-mode .document-child-links h5 { margin: 0 0 4px; font-size: 11px; font-weight: 600; color: var(--erp-muted); letter-spacing: .04em; text-transform: uppercase; }

/* 3열 · 문서 정보 / 개정제안 / 제안 목록 / 개정 이력 */
body.erp-doc-mode .pane-doc-meta {
  display: grid;
  gap: var(--erp-gap);
  position: sticky;
  top: var(--erp-gap);
  max-height: calc(100vh - var(--erp-gap) * 2);
  overflow-y: auto;
}
body.erp-doc-mode .doc-meta-card,
body.erp-doc-mode .document-proposal-results {
  margin: 0;
  padding: 16px 18px;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
}
body.erp-doc-mode .doc-meta-card h4,
body.erp-doc-mode .document-proposal-results h4,
body.erp-doc-mode .document-proposal-workbench h4 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--erp-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
body.erp-doc-mode .document-proposal-results h4 + h4 { margin-top: 4px; }
body.erp-doc-mode .doc-meta-list { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 6px 10px; margin: 0; font-size: 13px; }
body.erp-doc-mode .doc-meta-list dt { color: var(--erp-muted); font-size: 12px; line-height: 1.6; }
body.erp-doc-mode .doc-meta-list dd { margin: 0; color: var(--erp-text); line-height: 1.6; overflow-wrap: anywhere; }
body.erp-doc-mode .doc-meta-list code { font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--erp-muted); }
body.erp-doc-mode .document-proposal-workbench { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--erp-border); gap: 10px; }
body.erp-doc-mode .document-proposal-workbench label { font-size: 12px; color: var(--erp-muted); gap: 5px; }
body.erp-doc-mode .document-proposal-workbench .form-control {
  width: 100%;
  padding: 8px 10px;
  background: var(--erp-surface);
  border: 1px solid var(--erp-input-border);
  border-radius: var(--erp-radius-ctl);
  color: var(--erp-text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}
body.erp-doc-mode .document-proposal-workbench .form-control:focus { border-color: var(--erp-accent); box-shadow: 0 0 0 3px var(--erp-focus-ring); outline: none; }
body.erp-doc-mode .document-diff { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
body.erp-doc-mode .proposal-submit-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
body.erp-doc-mode .service-state { margin-left: 0; font-size: 11px; font-weight: 600; }
body.erp-doc-mode .doc-meta-card > .text-muted.text-sm { margin-top: 8px; font-size: 12px; line-height: 1.5; }
body.erp-doc-mode .proposal-list { gap: 8px; }
body.erp-doc-mode .proposal-list-item {
  padding: 10px 12px;
  background: var(--erp-surface-2);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius);
  font-size: 12.5px;
}
body.erp-doc-mode .proposal-list-item pre {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: 4px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--erp-text);
}
body.erp-doc-mode .proposal-actions { gap: 6px; }
body.erp-doc-mode .history-timeline { margin-left: 4px; padding-left: 14px; gap: 8px; border-left: 2px solid var(--erp-border); }
body.erp-doc-mode .timeline-item { padding: 8px 10px; background: var(--erp-surface-2); border: 1px solid var(--erp-border); border-radius: var(--erp-radius); font-size: 12.5px; }
body.erp-doc-mode .timeline-item::before { left: -21px; top: 12px; width: 8px; height: 8px; background: var(--erp-accent); border: 2px solid var(--erp-surface); box-sizing: content-box; }
body.erp-doc-mode .timeline-item span { font-size: 11px; color: var(--erp-muted); }
body.erp-doc-mode .history-timeline pre { font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--erp-text); }
body.erp-doc-mode #view-document .text-muted { color: var(--erp-muted); }
body.erp-doc-mode #view-document .text-danger { color: var(--erp-danger) !important; }

/* 버튼 (ERP 라이트 .btn-primary / .btn-outline 규격) — 문서탭 + 상단바 범위 */
body.erp-doc-mode .btn,
body.erp-doc-mode .btn-sm {
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--erp-radius-ctl);
  border: 0;
  background: var(--erp-hover);
  color: var(--erp-text);
  cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
  box-shadow: none;
}
body.erp-doc-mode .btn { padding: 8px 16px; font-size: 13px; }
body.erp-doc-mode .btn-sm { padding: 6px 12px; font-size: 12px; }
body.erp-doc-mode .btn:hover, body.erp-doc-mode .btn-sm:hover { background: rgba(0, 122, 255, .1); color: var(--erp-accent); }
body.erp-doc-mode .btn-primary, body.erp-doc-mode .btn-sm.btn-primary { background: var(--erp-accent); color: #fff; box-shadow: var(--erp-primary-shadow); }
body.erp-doc-mode .btn-primary:hover, body.erp-doc-mode .btn-sm.btn-primary:hover { background: var(--accent-hover); color: #fff; }
body.erp-doc-mode .btn-success, body.erp-doc-mode .btn-sm.btn-success { background: var(--erp-success); color: #fff; }
body.erp-doc-mode .btn-success:hover, body.erp-doc-mode .btn-sm.btn-success:hover { background: var(--erp-success); color: #fff; opacity: .85; }
body.erp-doc-mode .btn-secondary, body.erp-doc-mode .btn-sm.btn-secondary { background: var(--erp-hover); color: var(--erp-text); border: 0; }
body.erp-doc-mode .btn:disabled, body.erp-doc-mode .btn-sm:disabled { opacity: .45; cursor: not-allowed; }
body.erp-doc-mode .btn:disabled:hover, body.erp-doc-mode .btn-sm:disabled:hover { background: var(--erp-hover); color: var(--erp-text); }
body.erp-doc-mode .btn-sm.btn-primary:disabled:hover { background: var(--erp-accent); color: #fff; }

/* 토스트 — ERP 라이트 톤 */
body.erp-doc-mode .toast { background: var(--erp-surface); border-color: var(--erp-border); box-shadow: 0 4px 16px rgba(0, 0, 0, .12); }
body.erp-doc-mode .toast-success, body.erp-doc-mode .toast-error, body.erp-doc-mode .toast-warning { background: var(--erp-surface); }

/* ── 반응형: 1199px 이하 2열(정보 패널 본문 아래) · 899px 이하 1열 · 480px(400px 폭) 압축 ── */
@media (max-width: 1199px) {
  body.erp-doc-mode #view-document .split-layout { grid-template-columns: 220px minmax(0, 1fr); }
  body.erp-doc-mode .pane-doc-meta { grid-column: 2; position: static; max-height: none; overflow: visible; }
}
@media (max-width: 899px) {
  body.erp-doc-mode #view-document .split-layout { grid-template-columns: minmax(0, 1fr); }
  body.erp-doc-mode .pane-tree { position: static; max-height: 44vh; }
  body.erp-doc-mode .tree-content { max-height: calc(44vh - 44px); }
  body.erp-doc-mode .pane-doc-meta { grid-column: auto; }
  body.erp-doc-mode .doc-paper { padding: 24px 20px; }
}
@media (max-width: 480px) {
  body.erp-doc-mode .haccp-header { padding: 8px 12px; gap: 8px 12px; }
  body.erp-doc-mode .header-left { flex-wrap: wrap; gap: 8px; }
  body.erp-doc-mode .erp-breadcrumb { padding-left: 0; border-left: 0; }
  body.erp-doc-mode .header-right { width: 100%; justify-content: flex-start; gap: 6px; }
  body.erp-doc-mode .identity-login-form { flex-wrap: wrap; }
  body.erp-doc-mode .identity-login-form .form-control { width: 116px; }
  body.erp-doc-mode .haccp-views-nav { padding: 0 12px; }
  body.erp-doc-mode .nav-tabs-container { gap: 16px; }
  body.erp-doc-mode .haccp-main-workspace { padding: 12px; }
  body.erp-doc-mode #view-document .panel-header { flex-direction: column; align-items: flex-start; margin-bottom: 12px; }
  body.erp-doc-mode #view-document .split-layout { gap: 12px; }
  body.erp-doc-mode .tree-item.document-section { padding: 9px 10px; }
  body.erp-doc-mode .doc-paper { padding: 18px 14px; font-size: 14px; line-height: 1.75; }
  body.erp-doc-mode .doc-paper h1 { font-size: 19px; }
  body.erp-doc-mode .doc-paper h2 { font-size: 17px; }
  body.erp-doc-mode .doc-paper h3 { font-size: 16px; }
  body.erp-doc-mode .doc-paper table { display: block; overflow-x: auto; font-size: 12px; }
  body.erp-doc-mode .doc-meta-list { grid-template-columns: 62px minmax(0, 1fr); }
  body.erp-doc-mode .doc-meta-card, body.erp-doc-mode .document-proposal-results { padding: 12px 14px; }
}

/* ── 인쇄: 기준서 본문 + 문서정보 요약만 A4 출력 ───────────────────────────── */
@media print {
  @page { size: A4; margin: 18mm 16mm; }
  body.erp-doc-mode { background: #fff; color: #000; }
  body.erp-doc-mode .haccp-header,
  body.erp-doc-mode .haccp-views-nav,
  body.erp-doc-mode .haccp-kpi-banner,
  body.erp-doc-mode .compliance-banner,
  body.erp-doc-mode .bg-blobs,
  body.erp-doc-mode .toast-container,
  body.erp-doc-mode #signatureModal,
  body.erp-doc-mode #view-document .panel-header,
  body.erp-doc-mode .pane-tree,
  body.erp-doc-mode .doc-viewer-actions,
  body.erp-doc-mode .document-proposal-workbench,
  body.erp-doc-mode .doc-meta-card > .text-muted.text-sm,
  body.erp-doc-mode .document-proposal-results,
  body.erp-doc-mode .document-child-links,
  body.erp-doc-mode .doc-raw,
  body.erp-doc-mode .document-loading,
  body.erp-doc-mode .doc-empty-hint { display: none !important; }
  body.erp-doc-mode .haccp-main-workspace { padding: 0; }
  body.erp-doc-mode #view-document .split-layout { display: flex; flex-direction: column; gap: 6mm; }
  body.erp-doc-mode .pane-doc-meta { order: -1; position: static; max-height: none; overflow: visible; display: block; }
  body.erp-doc-mode .doc-meta-card { padding: 0; border: 0; border-radius: 0; background: #fff; }
  body.erp-doc-mode .doc-meta-card h4 { color: #000; margin-bottom: 4px; }
  body.erp-doc-mode .doc-meta-list {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
    padding: 6px 0;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    font-size: 9.5pt;
    color: #000;
  }
  body.erp-doc-mode .doc-meta-list dt { color: #444; font-size: 9.5pt; }
  body.erp-doc-mode .doc-meta-list dt::after { content: ':'; }
  body.erp-doc-mode .doc-meta-list dd { margin-right: 4px; color: #000; }
  body.erp-doc-mode .doc-meta-list code { color: #000; }
  body.erp-doc-mode .doc-meta-list .chip { border: 1px solid #000; background: none; color: #000; padding: 0 4px; }
  body.erp-doc-mode .doc-meta-list .text-xs { display: none; }
  body.erp-doc-mode .doc-viewer-header { display: none; }
  body.erp-doc-mode .markdown-preview-box { display: block; }
  body.erp-doc-mode .document-warning { border: 1px solid #000; background: none; color: #000; margin-bottom: 4mm; }
  body.erp-doc-mode .document-warning strong { color: #000; }
  body.erp-doc-mode .doc-paper {
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    font-size: 11pt;
    line-height: 1.7;
    color: #000;
  }
  body.erp-doc-mode .doc-paper h1 { font-size: 16pt; border-bottom-color: #000; }
  body.erp-doc-mode .doc-paper h2 { font-size: 14pt; }
  body.erp-doc-mode .doc-paper h3 { font-size: 12.5pt; }
  body.erp-doc-mode .doc-paper h4, body.erp-doc-mode .doc-paper h5 { font-size: 11pt; }
  body.erp-doc-mode .doc-paper h1, body.erp-doc-mode .doc-paper h2, body.erp-doc-mode .doc-paper h3, body.erp-doc-mode .doc-paper h4 { page-break-after: avoid; }
  body.erp-doc-mode .doc-paper table { font-size: 9.5pt; page-break-inside: auto; }
  body.erp-doc-mode .doc-paper tr { page-break-inside: avoid; }
  body.erp-doc-mode .doc-paper th, body.erp-doc-mode .doc-paper td { border-color: #000; }
  body.erp-doc-mode .doc-paper th { background: #e8e8e8; }
  body.erp-doc-mode .doc-paper blockquote { background: none; border-left-color: #000; color: #000; }
}
