:root {
  --bg-grad: linear-gradient(135deg, #eef4ff 0%, #f7f9fc 50%, #e9f2f9 100%);
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(148, 163, 184, 0.3);
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --secondary: #0f766e;
  --success: #15803d;
  --danger: #b91c1c;
  --warn: #b45309;
  --text: #0f172a;
  --muted: #475569;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

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

body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.45;
}

.app-shell {
  max-width: 1560px;
  margin: 0 auto;
  padding: 14px 18px 36px;
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* TOPBAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.brand h1 {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-ok { background: #dcfce7; color: #166534; }
.status-warn { background: #fef3c7; color: #92400e; }
.status-muted { background: #e2e8f0; color: #334155; }

/* NAV TABS */
.nav-tabs {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin-top: 12px;
  overflow-x: auto;
}

.nav-btn {
  border: none;
  background: transparent;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.nav-btn:hover { background: rgba(29, 78, 216, 0.08); color: var(--primary); }
.nav-btn.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(29, 78, 216, 0.25); }

/* PANELS */
.main-content { margin-top: 14px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s ease; }

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

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

@media (max-width: 1100px) {
  .grid-2-col, .side-by-side { grid-template-columns: 1fr !important; }
}

.panel-box { padding: 18px; }

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

.panel-header h2 { font-size: 16px; font-weight: 700; }
.panel-header h3 { font-size: 14px; font-weight: 700; }

/* BUTTONS */
.btn-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #115e59; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #166534; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid #cbd5e1; }
.btn-outline:hover:not(:disabled) { background: #f1f5f9; }
.file-label { cursor: pointer; }

/* DROP ZONE */
.drop-zone {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  background: rgba(248, 250, 252, 0.7);
  transition: all 0.2s;
  margin-bottom: 14px;
}
.drop-zone.dragover { border-color: var(--primary); background: #eff6ff; }
.drop-icon { font-size: 32px; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); }
.muted-text { font-size: 12px; color: var(--muted); }

/* CHECKLIST */
.spec-checklist {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}
.spec-checklist h3 { font-size: 13px; margin-bottom: 8px; color: var(--primary); }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.check-item { font-size: 12.5px; display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* TABLES (Single-row layout with hover tooltips) */
.table-wrap { overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}
.data-table th { background: #f1f5f9; font-weight: 700; color: #1e293b; }
.single-row-table td {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table input[type="number"], .data-table select {
  padding: 4px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
}
.data-table input[type="number"] { width: 58px; }

.badge-p1 { background: #fee2e2; color: #991b1b; padding: 2px 7px; border-radius: 6px; font-weight: 700; font-size: 11px; }
.badge-p2 { background: #fef3c7; color: #92400e; padding: 2px 7px; border-radius: 6px; font-weight: 700; font-size: 11px; }
.badge-p3 { background: #e2e8f0; color: #475569; padding: 2px 7px; border-radius: 6px; font-weight: 600; font-size: 11px; }

/* THUMBNAIL GRID */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  max-height: 620px;
  overflow-y: auto;
  padding: 4px;
}
.thumb-card {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.thumb-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.thumb-card canvas { width: 100%; height: auto; border: 1px solid #e2e8f0; }
.thumb-label { font-size: 11px; font-weight: 700; margin-top: 4px; color: #334155; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted); }

/* TAB 2: TOOLBAR & SIDE BY SIDE */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-label { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.input-ctrl {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  background: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
}
.progress-track { flex: 1; height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.2s; }

.side-by-side {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  align-items: start;
}

.viewer-pane, .form-pane { padding: 16px; }
.canvas-holder {
  background: #334155;
  border-radius: 10px;
  overflow: auto;
  max-height: 660px;
  display: flex;
  justify-content: center;
  padding: 12px;
}
#pdfViewerCanvas { background: #fff; box-shadow: 0 6px 20px rgba(0,0,0,0.35); }
.page-indicator { font-weight: 700; font-size: 12.5px; min-width: 56px; text-align: center; }

.raw-ocr-box { margin-top: 10px; }
.raw-ocr-box summary { cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--primary); }
.raw-ocr-box textarea {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-family: Consolas, monospace;
  font-size: 12px;
}

/* FORM */
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  padding: 6px 10px;
  border-radius: 7px;
  margin: 12px 0 8px;
}
.form-section-title:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full-span { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid rgba(29, 78, 216, 0.25); border-color: var(--primary); }
.req { color: var(--danger); }
.phase-hidden { display: none !important; }

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  gap: 10px;
  flex-wrap: wrap;
}

/* SIGN PREVIEW (Times New Roman 10pt chuẩn Điều 8 TT 05) */
.sign-preview-box {
  margin-top: 14px;
  padding: 14px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
}
.sign-preview-label { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.sign-preview-stamp {
  font-family: "Times New Roman", Times, serif;
  font-size: 10pt;
  color: #000;
  font-weight: 400;
  font-style: normal;
  text-align: right;
  border: 1px dashed #94a3b8;
  padding: 8px 12px;
  background: #fafafa;
}

.code-viewer {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 10px;
  font-family: Consolas, monospace;
  font-size: 12px;
  max-height: 520px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* AUDIT LOG */
.audit-list {
  max-height: 220px;
  overflow-y: auto;
  margin-top: 8px;
  font-size: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}
.audit-row {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* CUSTOM MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}
.modal-card { width: 100%; max-width: 520px; padding: 18px; background: #fff; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { font-size: 13.5px; color: #1e293b; margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; }

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }

.hidden { display: none !important; }
