:root {
  --blue: #004c97;
  --blue-dark: #003b73;
  --blue-soft: #eaf3ff;
  --bg: #eef3f8;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dbe4ef;
  --shadow: 0 14px 32px rgba(15, 23, 42, .10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ================================
   Mobile Top Bar
================================ */

.mobile-menu-bar {
  display: none;
}

.mobile-toggle {
  border: none;
  background: #ffffff;
  color: #06294f;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 800;
}

.mobile-close {
  display: none;
}

.mobile-sidebar-backdrop {
  display: none;
}

/* ================================
   Sidebar
================================ */

.sidebar {
  width: 280px;
  min-width: 280px;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 55%, #334155 100%);
  color: #ffffff;
  padding: 22px 18px;
  z-index: 9999;
  box-shadow: 8px 0 30px rgba(15, 23, 42, 0.18);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding-bottom: 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.14);
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(249, 115, 22, 0.35);
}

.brand h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #cbd5e1;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 22px;
}

.side-link {
  display: flex !important;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border-radius: 14px;
  text-decoration: none !important;
  color: #e5e7eb !important;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  transition: all 0.2s ease;
}

.side-link span {
  width: 24px;
  min-width: 24px;
  text-align: center;
  font-size: 17px;
}

.side-link:hover {
  transform: translateX(4px);
  color: #ffffff !important;
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.25);
}

.side-link.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: rgba(255,255,255,0.25);
  color: #ffffff !important;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

.side-section-title {
  margin: 13px 4px 4px;
  font-size: 11px;
  font-weight: 800;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.side-link-project {
  background: linear-gradient(135deg, rgba(14,165,233,0.24), rgba(59,130,246,0.18));
  border-color: rgba(96,165,250,0.28);
}

.side-link-success {
  background: linear-gradient(135deg, rgba(34,197,94,0.24), rgba(21,128,61,0.18));
  border-color: rgba(74,222,128,0.28);
}

.side-link-warning {
  background: linear-gradient(135deg, rgba(245,158,11,0.28), rgba(217,119,6,0.18));
  border-color: rgba(251,191,36,0.30);
}

.side-note {
  margin-top: 18px;
  padding: 15px;
  border-radius: 16px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.13);
}

.side-note strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.side-note span {
  display: block;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.45;
}

/* ================================
   Main Content
================================ */

.main-content {
  margin-left: 280px;
  width: calc(100% - 280px);
  padding: 30px;
  min-width: 0;
}

.hero-card {
  background: linear-gradient(135deg, #fff, #eaf3ff);
  border-radius: 26px;
  padding: 32px;
  box-shadow: var(--shadow);
  border-left: 8px solid var(--blue);
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: center;
}

.eyebrow {
  color: var(--blue);
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-size: .82rem;
  margin: 0 0 6px;
}

.hero-card h1 {
  margin: 0;
  color: var(--blue-dark);
  font-size: clamp(2rem, 4vw, 3.25rem);
  font-weight: 900;
}

.hero-text {
  max-width: 780px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.hero-badge {
  min-width: 170px;
  padding: 18px;
  border-radius: 20px;
  text-align: center;
  background: #fff;
  box-shadow: 0 10px 24px rgba(0, 76, 151, .12);
  border: 1px solid var(--border);
}

.hero-badge span {
  display: block;
  color: var(--muted);
  font-size: .8rem;
}

.hero-badge strong {
  color: var(--blue);
  font-size: 1.05rem;
}

.status-area {
  margin: 18px 0;
}

.search-card,
.content-card {
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-title h2 {
  margin: 0;
  color: var(--blue-dark);
  font-weight: 850;
  font-size: 1.35rem;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.hint-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--muted);
  font-size: .92rem;
}

.table thead th {
  background: var(--blue);
  color: #fff;
  white-space: nowrap;
  border: none;
}

.table td {
  vertical-align: middle;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-item {
  padding: 14px 16px;
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 16px;
}

.detail-item strong {
  display: block;
  color: var(--blue-dark);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 4px;
}

.detail-item span {
  color: #111827;
  overflow-wrap: anywhere;
}

.finalize-card {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid #bbf7d0;
  border-radius: 18px;
  background: #f0fdf4;
}

.action-bar {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.upload-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0;
}

.btn-purple {
  background: #6d28d9;
  color: #fff;
  border-color: #6d28d9;
}

.btn-purple:hover {
  background: #5b21b6;
  color: #fff;
}

.btn-indigo {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

.btn-indigo:hover {
  background: #4338ca;
  color: #fff;
}

.signed-note {
  color: var(--muted);
  font-size: .9rem;
}

.custom-modal {
  border: none;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .22);
}

.modal-primary {
  background: var(--blue);
  color: #fff;
}

.modal-blue-soft {
  background: var(--blue-soft);
  color: #004085;
}

.modal-blue-soft small {
  color: #004085;
  font-weight: normal;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid-span-2 {
  grid-column: span 2;
}

/* ================================
   Tablet
================================ */

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 18px;
  }

  .hero-card {
    display: block;
  }

  .hero-badge {
    margin-top: 18px;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .details-grid,
  .edit-grid {
    grid-template-columns: 1fr;
  }

  .grid-span-2 {
    grid-column: span 1;
  }
}

/* ================================
   Mobile Sidebar Fix
   This matches your JS: body.sidebar-open
================================ */

@media (max-width: 991px) {
  body {
    background: #f3f7fb;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-menu-bar {
    display: flex !important;
    position: sticky;
    top: 0;
    z-index: 100000;
    background: #06294f;
    color: #fff;
    padding: 12px 14px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 18px rgba(0,0,0,.18);
  }

  .mobile-menu-title {
    font-weight: 900;
    letter-spacing: .02em;
  }

  .mobile-toggle {
    display: inline-block !important;
    background: #ffffff;
    color: #06294f;
    border: 0;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 800;
  }

  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 285px !important;
    min-width: 285px !important;
    max-width: 86vw !important;
    height: 100vh !important;
    z-index: 100002 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transform: translateX(-110%) !important;
    transition: transform .28s ease !important;
    border-radius: 0 22px 22px 0;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0) !important;
  }

  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    z-index: 100001;
  }

  body.sidebar-open .sidebar {
    z-index: 100003 !important;
  }

  .mobile-close {
    display: flex !important;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 12px;
    background: rgba(255,255,255,0.18);
    color: #ffffff;
    font-size: 26px;
    line-height: 1;
    align-items: center;
    justify-content: center;
    z-index: 100004;
    cursor: pointer;
  }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 14px !important;
  }

  .hero-card {
    padding: 22px;
    border-radius: 20px;
  }

  .hero-card h1 {
    font-size: 1.85rem;
    line-height: 1.1;
  }

  .hero-text {
    font-size: .96rem;
  }

  .hero-badge {
    min-width: auto;
    width: 100%;
    margin-top: 16px;
  }

  .search-card,
  .content-card {
    padding: 16px;
    border-radius: 18px;
  }

  .section-title {
    display: block;
  }

  .section-title h2 {
    font-size: 1.15rem;
  }

  .section-title p {
    font-size: .9rem;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  #query {
    font-size: 1rem;
    min-height: 48px;
  }

  #searchBtn {
    width: 100%;
    min-height: 48px;
  }

  .hint-box {
    font-size: .85rem;
  }

  .details-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .detail-item {
    padding: 12px 13px;
    border-radius: 14px;
  }

  .finalize-card {
    padding: 14px;
  }

  .action-bar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .action-bar .btn,
  .upload-inline,
  .upload-inline .btn,
  #viewSignedDocBtn,
  #viewCertBtn {
    width: 100%;
  }

  .upload-inline {
    display: grid;
    grid-template-columns: 1fr;
  }

  .signed-note {
    text-align: center;
  }

  .table-responsive {
    border-radius: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #matchesTable thead {
    display: none;
  }

  #matchesTable tbody,
  #matchesTable tr,
  #matchesTable td {
    display: block;
    width: 100%;
  }

  #matchesTable tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 6px 14px rgba(15,23,42,.06);
  }

  #matchesTable td {
    border: 0;
    padding: 5px 0;
  }

  #matchesTable td:nth-child(1)::before {
    content: "Unique ID: ";
    font-weight: 800;
    color: var(--blue-dark);
  }

  #matchesTable td:nth-child(2)::before {
    content: "Name: ";
    font-weight: 800;
    color: var(--blue-dark);
  }

  #matchesTable .btnSelect {
    width: 100%;
    margin-top: 8px;
    min-height: 42px;
  }

  .modal-dialog {
    margin: 12px;
  }

  .modal-content {
    border-radius: 18px;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .grid-span-2 {
    grid-column: span 1;
  }
}

/* ================================
   Small Phone
================================ */

@media (max-width: 520px) {
  .main-content {
    padding: 10px !important;
  }

  .hero-card {
    padding: 18px;
  }

  .hero-card h1 {
    font-size: 1.55rem;
  }

  .search-card,
  .content-card {
    padding: 14px;
  }

  .brand h2 {
    font-size: 1.1rem;
  }

  .brand-icon {
    width: 48px;
    height: 48px;
  }
}

/* ================================
   Desktop Protection
================================ */

@media (min-width: 992px) {
  .mobile-menu-bar,
  .mobile-close,
  .mobile-sidebar-backdrop {
    display: none !important;
  }

  .sidebar {
    transform: none !important;
  }
}