:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --indigo: #4338ca;
  --indigo-soft: #eef2ff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3, h4, p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.muted {
  color: var(--muted);
}

.text-right {
  text-align: right;
}

.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* LOGIN */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #1d4ed8 100%);
}

.login-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 22px 0 14px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.divider span {
  padding: 0 10px;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 8px;
}

.demo-btn {
  text-align: left;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  cursor: pointer;
  transition: all 0.15s ease;
}
.demo-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.demo-btn .demo-role {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
}
.demo-btn .demo-org {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}
.brand-sub {
  font-size: 11px;
  color: #94a3b8;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.roadmap-box {
  margin-top: auto;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 12px;
}
.roadmap-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 8px;
}
.roadmap-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0;
  color: #64748b;
}
.roadmap-item span {
  width: 18px;
  height: 18px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: #94a3b8;
}
.roadmap-item.active {
  color: #fff;
  font-weight: 600;
}
.roadmap-item.active span {
  background: var(--emerald);
  color: #fff;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 99px;
  background: #334155;
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.user-role {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h2 {
  font-size: 19px;
  font-weight: 700;
}

.content-wrap {
  padding: 22px 26px;
  max-width: 1380px;
  width: 100%;
}

/* CARDS & GRIDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

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

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 18px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-val {
  font-size: 23px;
  font-weight: 800;
  margin-top: 6px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

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

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* FORMS & BUTTONS */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; }

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

.btn-success { background: var(--emerald); color: #fff; }
.btn-success:hover { background: #047857; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost { background: rgba(255, 255, 255, 0.08); color: #e2e8f0; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.15); }

.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

/* TABLES */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-alt);
  font-weight: 700;
}
tr:hover td {
  background: #fafcff;
}

/* BADGES & ALERTS */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-green { background: var(--emerald-soft); color: var(--emerald); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-indigo { background: var(--indigo-soft); color: var(--indigo); }
.badge-slate { background: #e2e8f0; color: #334155; }

.alert {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid transparent;
}
.alert-info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e3a8a; }
.alert-warn { background: var(--amber-soft); border-color: #fde68a; color: #92400e; }
.alert-success { background: var(--emerald-soft); border-color: #a7f3d0; color: #065f46; }
.alert-danger { background: var(--red-soft); border-color: #fecaca; color: #991b1b; }

/* MILESTONES */
.milestone-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.milestone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 8px;
}
.milestone-step {
  flex: 1;
  min-width: 140px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
}
.milestone-step.done {
  border-color: #a7f3d0;
  background: var(--emerald-soft);
  color: #065f46;
}
.milestone-step.partial {
  border-color: #fcd34d;
  background: var(--amber-soft);
  color: #92400e;
}
.milestone-step.current {
  border-color: #93c5fd;
  background: var(--primary-soft);
  color: #1e3a8a;
  font-weight: 700;
}
.milestone-step.future {
  opacity: 0.68;
}

/* COMMUNICATIONS */
.comm-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.comm-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-dialog {
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
}
.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  z-index: 200;
}

/* A4 PROFORMA INVOICE PRINT SHEET */
.pi-sheet {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 20px 24px;
  max-width: 820px;
  margin: 0 auto;
  color: #111827;
  font-size: 12px;
  line-height: 1.35;
}

.pi-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 8px;
  margin-bottom: 10px;
  gap: 14px;
}

.pi-sheet-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #0f172a;
  text-align: right;
}

.pi-box-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid #cbd5e1;
  margin-bottom: 9px;
}
.pi-box {
  padding: 6px 9px;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  font-size: 11.5px;
  line-height: 1.35;
}
.pi-box:nth-child(2n) { border-right: none; }
.pi-box-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: #475569;
  margin-bottom: 3px;
}

.pi-section-box {
  border: 1px solid #cbd5e1;
  padding: 7px 10px;
  margin-bottom: 9px;
  font-size: 11.5px;
  line-height: 1.35;
}

.pi-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 9px;
  font-size: 11.5px;
}
.pi-table th, .pi-table td {
  border: 1px solid #cbd5e1;
  padding: 5px 7px;
}
.pi-table th {
  background: #f1f5f9;
  color: #0f172a;
  font-size: 10px;
}

.pi-sign-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 18px;
  padding-top: 4px;
}
.pi-sign-space {
  height: 85px;
}

/* DD/MM/YYYY UNIFIED DATE PICKER FIELD */
.date-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.date-input-wrap input.date-dmy {
  width: 100%;
  padding-right: 30px;
  font-variant-numeric: tabular-nums;
}
.date-input-wrap input.date-native-picker {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  opacity: 0;
  pointer-events: none;
  padding: 0;
  border: 0;
}
.date-input-wrap .date-picker-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  font-size: 13px;
  color: var(--muted);
  border-radius: 4px;
}
.date-input-wrap .date-picker-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

@page {
  size: A4 portrait;
  margin: 8mm 10mm;
}

@media print {
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 11px !important;
  }
  .no-print {
    display: none !important;
  }
  .app-shell {
    display: block !important;
    min-height: auto !important;
  }
  .main-area, .content-wrap {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  .pi-sheet {
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    box-shadow: none !important;
    font-size: 10.5px !important;
    line-height: 1.28 !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .pi-box, .pi-section-box, .pi-table {
    font-size: 10.5px !important;
  }
  .pi-box { padding: 5px 8px !important; }
  .pi-section-box { padding: 6px 8px !important; margin-bottom: 7px !important; }
  .pi-box-grid, .pi-table { margin-bottom: 7px !important; }
  .pi-table th, .pi-table td { padding: 4px 6px !important; }
  .pi-sign-row { margin-top: 14px !important; }
  .pi-sign-space { height: 78px !important; }
}
