:root {
  --navy: #10243e;
  --navy-2: #16324f;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-900: #0f172a;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- topbar --- */
.topbar { background: var(--navy); color: #fff; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: 28px; }
.brand { color: #fff; font-weight: 700; font-size: 18px; flex-shrink: 0; }
.brand span { font-weight: 400; opacity: .8; }
.nav-panel { display: flex; align-items: center; gap: 28px; flex: 1; min-width: 0; }
.nav { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.nav a { color: #cbd5e1; font-size: 14px; padding: 10px 2px; border-bottom: 2px solid transparent; }
.nav a:hover, .nav a.active { color: #fff; border-bottom-color: var(--blue); text-decoration: none; }
.user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #cbd5e1; flex-wrap: wrap; }
.user-menu em { font-style: normal; opacity: .7; }
.user-menu a { color: #fff; padding: 6px 0; }

/* hamburger button: hidden on desktop, shown under the mobile breakpoint */
.nav-toggle { display: none; flex-direction: column; justify-content: center; gap: 5px; width: 40px; height: 40px; background: transparent; border: none; cursor: pointer; margin-left: auto; padding: 8px; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

.container { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; }

/* --- login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--navy), var(--navy-2)); }
.login-card { background: #fff; border-radius: var(--radius); padding: 40px 36px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin: 0 0 2px; }
.login-sub { color: var(--gray-600); margin: 0 0 20px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--gray-600); display: flex; flex-direction: column; gap: 6px; }
.login-card input { padding: 10px 12px; min-height: 42px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 16px; }
.login-footer { margin-top: 18px; font-size: 13px; color: var(--gray-600); text-align: center; }

/* --- flash --- */
.flash-wrap { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 8px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* --- page head / buttons --- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head-actions { display: flex; gap: 8px; }
.subtitle { color: var(--gray-600); margin: 0; font-size: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--gray-200); background: #fff; color: var(--gray-900); font-size: 14px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--gray-100); text-decoration: none; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--gray-600); }
.link-btn { background: none; border: none; color: var(--red); font-size: 12px; cursor: pointer; padding: 8px 0; text-decoration: underline; }

/* --- stat cards --- */
.stat-cards { display: flex; gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px 22px; display: flex; flex-direction: column; min-width: 150px; }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--gray-600); }
.stat-danger .stat-num { color: var(--red); }

/* --- filter bar --- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 10px 12px; min-height: 40px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 14px; background: #fff; }
.filter-bar input[type=text] { min-width: 220px; }

/* --- table --- */
.table-wrap { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 24px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { text-align: left; background: var(--gray-100); color: var(--gray-600); font-weight: 600; padding: 10px 14px; white-space: nowrap; border-bottom: 1px solid var(--gray-200); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .empty { text-align: center; color: var(--gray-400); padding: 30px; }

/* --- pills / badges --- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-100); color: var(--gray-600); }
.pill-sent { background: #dcfce7; color: #166534; }
.pill-wip { background: #fef3c7; color: #92400e; }
.pill-pending { background: #f1f5f9; color: #64748b; }
.pill-status-not-started { background: #f1f5f9; color: #64748b; }
.pill-status-started, .pill-status-in-progress { background: #dbeafe; color: #1e40af; }
.pill-status-on-hold { background: #fef3c7; color: #92400e; }
.pill-status-delayed { background: #fee2e2; color: #991b1b; }
.pill-status-completed { background: #dcfce7; color: #166534; }

.countdown { display: inline-block; margin-left: 6px; font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--gray-100); color: var(--gray-600); }
.countdown-soon { background: #fef3c7; color: #92400e; }
.countdown-over { background: #fee2e2; color: #991b1b; }

/* --- cards / forms --- */
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 22px; margin-bottom: 22px; }
.card h2 { margin: 0 0 14px; font-size: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid fieldset { grid-column: 1 / -1; border: none; padding: 0; margin: 0 0 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid legend { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--gray-600); padding: 0 0 8px; grid-column: 1 / -1; border-bottom: 1px solid var(--gray-200); margin-bottom: 6px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--gray-600); }
.form-grid input, .form-grid select, .form-grid textarea { padding: 10px 12px; min-height: 42px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 16px; font-family: inherit; font-weight: 400; color: var(--gray-900); }
.form-grid textarea { min-height: 70px; }
.span-2 { grid-column: span 2; }
.form-actions { grid-column: 1 / -1; margin-top: 8px; }
.hint { font-size: 12.5px; color: var(--gray-400); }

.def-list { display: grid; grid-template-columns: 130px 1fr; gap: 10px 12px; margin: 0; font-size: 14px; }
.def-list dt { color: var(--gray-600); font-weight: 600; }
.def-list dd { margin: 0; }

/* --- milestone timeline --- */
.milestone-list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 10px; }
.milestone-list li { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.milestone-list .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gray-200); flex-shrink: 0; }
.milestone-list li.done .dot { background: var(--green); }
.milestone-list .ms-label { flex: 1; }
.milestone-list li.todo .ms-label { color: var(--gray-400); }
.milestone-list .ms-date { color: var(--gray-600); font-size: 13px; }
.progress-bar { height: 8px; background: var(--gray-100); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--blue); }

/* --- deadline cards --- */
.deadline-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px; }
.deadline-card { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; }
.deadline-label { font-size: 12.5px; opacity: .75; }
.deadline-date { font-size: 20px; font-weight: 700; }
.deadline-countdown { font-size: 13px; font-weight: 600; padding: 3px 0; }
.deadline-countdown.countdown-soon { color: #fbbf24; }
.deadline-countdown.countdown-over { color: #f87171; }

/* --- file upload --- */
.upload-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.upload-form select { padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: 8px; }
.upload-form input[type=file] { flex: 1; min-width: 180px; font-size: 13px; }
.file-group-label { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--gray-400); margin: 14px 0 6px; }
.file-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--gray-100); }
.file-meta { color: var(--gray-400); font-size: 12px; margin-left: auto; }

/* --- gantt --- */
.gantt-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.gantt-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--gray-400); margin-bottom: 6px; padding-left: 160px; }
.gantt-chart { display: flex; flex-direction: column; gap: 4px; min-width: 700px; }
.gantt-row { display: flex; align-items: center; gap: 10px; height: 26px; }
.gantt-label { width: 150px; flex-shrink: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-track { position: relative; flex: 1; height: 16px; background: var(--gray-100); border-radius: 4px; }
.gantt-bar { position: absolute; top: 0; height: 100%; border-radius: 3px; min-width: 3px; }
.gantt-today { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--red); }
.stage-commence { background: #94a3b8; }
.stage-sitevisit { background: #60a5fa; }
.stage-layout { background: #a78bfa; }
.stage-approved { background: #34d399; }
.stage-boq { background: #fbbf24; }
.stage-po { background: #f472b6; }
.task-bar-not-started { background: var(--gray-400); }
.task-bar-started { background: var(--blue); }
.task-bar-completed { background: var(--green); }
.task-bar-delayed { background: var(--red); }
.gantt-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; font-size: 12px; color: var(--gray-600); }
.gantt-legend span { display: flex; align-items: center; gap: 6px; }
.gantt-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.gantt-today-swatch { background: var(--red); }

.print-header { display: none; }
.print-footer { color: var(--gray-400); font-size: 12px; margin-top: 20px; }

/* --- print --- */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-header { display: block; margin-bottom: 18px; }
  .print-header h1 { margin: 0 0 4px; font-size: 20px; }
  .container { padding: 0; max-width: 100%; }
  .card, .table-wrap { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  .data-table { font-size: 11px; }
  .gantt-chart { min-width: 0; }
  a { color: inherit; text-decoration: none; }
}

/* --- tablet (iPad portrait and similar) --- */
@media (max-width: 900px) {
  .two-col, .form-grid, .form-grid fieldset { grid-template-columns: 1fr; }
  .deadline-cards { grid-template-columns: 1fr; }
  .container { padding: 20px 18px 50px; }
}

/* --- phone-width nav: collapse into a hamburger-triggered dropdown --- */
@media (max-width: 800px) {
  .nav-toggle { display: flex; }
  .nav-panel {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: var(--navy-2);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 20px 16px;
    box-shadow: 0 12px 24px rgba(0,0,0,.25);
  }
  .nav-panel.open { display: flex; }
  .topbar-inner { position: relative; flex-wrap: wrap; row-gap: 10px; }
  .nav { flex-direction: column; gap: 2px; }
  .nav a { padding: 12px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
  /* client-portal header (no hamburger) has its own user-menu directly in topbar-inner */
  .topbar-inner > .user-menu { flex-direction: row; flex-wrap: wrap; }
  .nav-panel .user-menu { flex-direction: column; align-items: flex-start; gap: 8px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.15); margin-top: 6px; }
}

/* --- phone width: general layout tightening --- */
@media (max-width: 560px) {
  .container { padding: 16px 14px 50px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head-actions { justify-content: flex-start; }
  .page-head h1 { font-size: 20px; }
  .stat-cards { flex-wrap: wrap; }
  .stat-card { flex: 1 1 45%; min-width: 0; padding: 14px 16px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select, .filter-bar .btn { width: 100%; }
  .form-grid, .form-grid fieldset { grid-template-columns: 1fr; gap: 12px; }
  .span-2 { grid-column: 1; }
  .upload-form { flex-direction: column; align-items: stretch; }
  .upload-form select, .upload-form input[type=file] { width: 100%; }
  .card { padding: 16px; }
  .def-list { grid-template-columns: 100px 1fr; font-size: 13px; }
  .login-card { width: 90vw; max-width: 360px; padding: 32px 24px; }
  .gantt-axis { padding-left: 0; }
  .gantt-label { width: 100px; font-size: 11.5px; }
  .brand { font-size: 16px; }
}
