:root {
  --navy: #0F172A;
  --navy-soft: #1E293B;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-alt: #F8FAFC;
  --border: #CBD5E1;
  --border-light: #E2E8F0;
  --teal: #0F766E;
  --teal-soft: #CCFBF1;
  --cobalt: #1D4ED8;
  --cobalt-soft: #DBEAFE;
  --amber: #B45309;
  --amber-soft: #FEF3C7;
  --red: #B91C1C;
  --red-soft: #FEE2E2;
  --green: #15803D;
  --green-soft: #DCFCE7;
  --muted: #475569;
  --sidebar-w: 238px;
  --topbar-h: 52px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.09);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--navy);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14.5px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .font-heading {
  font-family: 'Outfit', 'Plus Jakarta Sans', sans-serif;
  margin: 0;
  color: var(--navy);
  letter-spacing: -0.015em;
}

.mono, code, .code-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

/* High-visibility manual entry inputs */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="search"],
select,
textarea {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14.5px;
  font-weight: 600;
  color: #0F172A;
  background: #FFFFFF;
  border: 1.5px solid #94A3B8;
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cobalt);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

input::placeholder, textarea::placeholder {
  color: #64748B;
  font-weight: 400;
}

label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 4px;
}

.req-star {
  color: #DC2626;
  font-weight: 800;
  margin-left: 2px;
}

/* Login Gate */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 55%, #0F766E 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 410px;
  background: #FFFFFF;
  border-radius: 12px;
  padding: 28px 28px 24px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-brand img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  overflow-y: auto;
  border-right: 1px solid #1E293B;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand img {
  width: 34px;
  height: 34px;
  border-radius: 6px;
}

.sidebar-brand-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: #FFFFFF;
  line-height: 1.15;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: #94A3B8;
}

.nav-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748B;
  padding: 12px 14px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7.5px 14px;
  color: #CBD5E1;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
}

.nav-item.active {
  background: rgba(15, 118, 110, 0.25);
  color: #FFFFFF;
  border-left-color: #14B8A6;
  font-weight: 600;
}

.nav-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.12);
  color: #E2E8F0;
  padding: 1px 6px;
  border-radius: 10px;
}

.nav-item.active .nav-badge {
  background: var(--teal);
  color: #FFFFFF;
}

/* Main Area */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-title {
  font-family: 'Outfit', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.updated-by-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
}

.updated-by-wrap span {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.updated-by-wrap select {
  border: none;
  background: transparent;
  padding: 2px 4px;
  font-size: 13px;
  font-weight: 700;
  width: auto;
}

.updated-by-wrap select:focus {
  box-shadow: none;
}

.content-body {
  padding: 18px 20px 40px;
  max-width: 1480px;
  width: 100%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 6px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-sm {
  padding: 4.5px 9.5px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--cobalt);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: #1E40AF;
}

.btn-teal {
  background: var(--teal);
  color: #FFFFFF;
}
.btn-teal:hover {
  background: #0D5F58;
}

.btn-navy {
  background: var(--navy);
  color: #FFFFFF;
}
.btn-navy:hover {
  background: var(--navy-soft);
}

.btn-outline {
  background: #FFFFFF;
  color: var(--navy);
  border-color: var(--border);
}
.btn-outline:hover {
  background: var(--surface-alt);
  border-color: #94A3B8;
}

.btn-danger {
  background: #FEF2F2;
  color: var(--red);
  border-color: #FECACA;
}
.btn-danger:hover {
  background: #FEE2E2;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 13px 15px;
  border-top: 3px solid var(--cobalt);
  box-shadow: var(--shadow-sm);
}

.kpi-card.teal { border-top-color: var(--teal); }
.kpi-card.amber { border-top-color: var(--amber); }
.kpi-card.navy { border-top-color: var(--navy); }

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-family: 'Outfit', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  margin-top: 3px;
}

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

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

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* Stage Guide Banner */
.stage-guide-banner {
  background: linear-gradient(90deg, #F0FDFA 0%, #EFF6FF 100%);
  border: 1px solid #99F6E4;
  border-left: 4px solid var(--teal);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stage-guide-banner strong {
  color: var(--navy);
  font-size: 13.5px;
}

.stage-guide-meta {
  font-size: 13px;
  color: #334155;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  background: #F8FAFC;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  color: var(--navy);
}

tr:hover td {
  background: #F8FAFC;
}

.num {
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-cobalt { background: var(--cobalt-soft); color: #1E40AF; }
.badge-teal { background: var(--teal-soft); color: #115E59; }
.badge-amber { background: var(--amber-soft); color: #92400E; }
.badge-red { background: var(--red-soft); color: #991B1B; }
.badge-green { background: var(--green-soft); color: #166534; }
.badge-slate { background: #E2E8F0; color: #334155; }

.chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}

.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: #FFFFFF;
  border: 1px solid var(--border);
  color: var(--navy);
  cursor: pointer;
}

.chip.active {
  background: var(--navy);
  color: #FFFFFF;
  border-color: var(--navy);
}

/* Costing Box */

.costing-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

.costing-box {
  background: #FFFBEB;
  border: 1.5px solid #FCD34D;
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 10px;
}

.costing-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: #FFFFFF;
  border-radius: 10px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
}

.modal-box.wide {
  max-width: 980px;
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast-host {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--navy);
  color: #FFFFFF;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--teal);
}

.toast.error {
  border-left-color: #EF4444;
}

/* Mobile-only elements hidden on desktop */
.mobile-menu-btn,
.mobile-bottom-bar,
.drawer-overlay {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 60;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .drawer-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 55;
  }
  .main-wrap {
    margin-left: 0;
    padding-bottom: 66px;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .mobile-bottom-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--navy);
    border-top: 1px solid #334155;
    z-index: 50;
  }
  .mobile-bottom-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #CBD5E1;
    font-size: 11px;
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
  }
  .mobile-bottom-btn.active {
    color: #2DD4BF;
  }
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 0 10px;
    gap: 8px;
  }
  .topbar-title {
    font-size: 14.5px;
  }
  .updated-by-wrap span {
    display: none;
  }
  .content-body {
    padding: 12px 12px 76px;
  }
  .modal-backdrop {
    padding: 10px;
  }
  .costing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-right .hide-mobile {
    display: none;
  }
}

/* Print / Official Letterhead */
#printArea {
  display: none;
}

@media print {
  body {
    background: #FFFFFF !important;
    margin: 0;
    padding: 0;
  }
  .login-gate, .app-shell, .modal-backdrop, .toast-host, .mobile-bottom-bar {
    display: none !important;
  }
  #printArea {
    display: block !important;
    color: #0F172A;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 12.5px;
    line-height: 1.45;
  }
  .lh-page {
    padding: 10mm 12mm;
  }
  .lh-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2.5px solid #0F172A;
    padding-bottom: 10px;
    margin-bottom: 14px;
  }
  .lh-brand {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .lh-brand img {
    width: 54px;
    height: 54px;
    border-radius: 6px;
  }
  .lh-company {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 800;
    color: #0F172A;
  }
  .lh-meta {
    font-size: 11px;
    color: #334155;
  }
  .lh-doc-title {
    text-align: right;
  }
  .lh-doc-title h2 {
    font-size: 17px;
    color: #B91C1C;
    text-transform: uppercase;
  }
  .lh-footer {
    margin-top: 22px;
    padding-top: 10px;
    border-top: 1.5px solid #CBD5E1;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 11px;
    color: #334155;
  }
  .lh-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
  }
  .lh-table th {
    background: #0F172A !important;
    color: #FFFFFF !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6px 8px;
    font-size: 11px;
  }
  .lh-table td {
    border: 1px solid #CBD5E1;
    padding: 6px 8px;
    font-size: 11.5px;
  }
}
