:root {
  --color-bg: #f4f3fb;
  --color-surface: #ffffff;
  --color-border: #e7e4f4;
  --color-text: #241a3d;
  --color-muted: #746e94;
  --color-primary: #6c4ce0;
  --color-primary-dark: #5636b8;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --radius: 14px;
  --sidebar-bg: #241a52;
  --sidebar-bg-active: #ffffff;
  --sidebar-text: rgba(255, 255, 255, 0.78);
  --sidebar-text-active: #241a52;
  --sidebar-width: 240px;
}

* { box-sizing: border-box; }

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

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  text-decoration: none;
  padding: 6px 10px 22px;
}

.sidebar-brand .brand-icon {
  display: block;
  height: 26px;
  width: auto;
  border-radius: 6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

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

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

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text);
  padding: 4px 8px;
}

.topbar-title {
  font-size: 1.3rem;
  margin: 0;
}

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

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.topbar-user-info { text-align: right; }
.topbar-user-name { font-size: 0.85rem; font-weight: 600; }

.role-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #eef2ff;
  color: var(--color-primary-dark);
}

.role-badge.role-supervisor { background: #fef3c7; color: #92400e; }
.role-badge.role-manager { background: #dcfce7; color: #166534; }
.role-badge.role-technical { background: #fce7f3; color: #9d174d; }
.role-badge.role-marketing { background: #ffe4e6; color: #9f1239; }
.role-badge.role-director { background: #ede9fe; color: #5b21b6; }
.role-badge.role-intern { background: #e0f2fe; color: #0369a1; }

main.container {
  padding-top: 24px;
  padding-bottom: 60px;
}

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h1.doc-number { font-size: 1.15rem; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p.subtitle { color: var(--color-muted); margin-top: 0; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  overflow-x: auto;
  box-shadow: 0 4px 16px rgba(36, 26, 82, 0.05);
}

.card + .card { margin-top: 0; }

.grid {
  display: grid;
  gap: 20px;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 4px 16px rgba(36, 26, 82, 0.05);
}

.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--color-text); }
.stat .label { color: var(--color-muted); font-size: 0.82rem; margin-top: 4px; }

.chart-wrap { position: relative; height: 260px; }
.chart-wrap.chart-wrap-sm { height: 220px; }

.label-strong {
  font-weight: 800;
  color: var(--color-text);
}

.field-label-strong {
  color: var(--color-text) !important;
  font-weight: 800 !important;
  font-size: 0.85rem !important;
}

.bullet-list {
  margin: 0;
  padding-left: 20px;
}

.bullet-list li {
  margin-bottom: 4px;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 6px;
  margin-top: 14px;
}

label:first-child { margin-top: 0; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=month], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(108, 76, 224, 0.15);
}

/* Tighter spacing for high-frequency creation forms (Quick Sale, Quotations, Invoices, Job Cards)
   so the whole form is visible with much less scrolling. */
.form-compact { padding: 14px; }
.form-compact label { margin-top: 8px; margin-bottom: 3px; font-size: 0.8rem; }
.form-compact label:first-child { margin-top: 0; }
.form-compact input[type=text],
.form-compact input[type=email],
.form-compact input[type=date],
.form-compact input[type=month],
.form-compact select,
.form-compact textarea {
  padding: 6px 9px;
  font-size: 0.86rem;
}
.form-compact textarea { min-height: 54px; }
.form-compact .pos-item-row { margin-bottom: 6px !important; gap: 8px !important; }
.form-compact .btn { margin-top: 10px; padding: 8px 16px; font-size: 0.88rem; }
.form-compact .btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.form-compact h2 { margin-bottom: 8px; font-size: 1.05rem; }
.form-compact .two-col { display: flex; gap: 10px; }
.form-compact .two-col > div { flex: 1; }

.btn {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin-top: 16px;
}

.btn:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; margin-top: 0; }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
}

th { color: var(--color-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-submitted { background: #dcfce7; color: #166534; }
.badge-missing { background: #fee2e2; color: #991b1b; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-important { background: #fef3c7; color: #92400e; }
.badge-leave { background: #e0f2fe; color: #0369a1; }

details summary { cursor: pointer; color: var(--color-primary); font-size: 0.85rem; }
details[open] summary { margin-bottom: 6px; }

.inline-form { display: inline; }
.btn-link-danger { background: none; border: none; color: var(--color-danger); cursor: pointer; padding: 0; font-size: inherit; font-family: inherit; text-decoration: underline; }

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.92rem;
}

.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.82rem;
  padding: 18px 0;
  text-align: center;
}

body.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #8b6bf0 0%, #6c4ce0 45%, #241a52 100%);
}

body.auth-body main.container {
  padding: 20px;
}

.login-wrap {
  max-width: 380px;
  width: 100%;
  margin: 0;
}

.login-wrap .card {
  margin-bottom: 0;
  border: none;
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  animation: auth-card-in 0.35s ease;
}

.login-wrap h1 {
  text-align: center;
}

.login-wrap p.subtitle {
  text-align: center;
  margin-bottom: 24px;
}

.login-wrap .btn {
  width: 100%;
  text-align: center;
  padding: 12px 18px;
  font-size: 0.98rem;
}

.login-logo {
  display: block;
  width: 170px;
  max-width: 60%;
  height: auto;
  margin: 0 auto 20px;
}

@keyframes auth-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.text-muted { color: var(--color-muted); }
.text-sm { font-size: 0.85rem; }
.mt-0 { margin-top: 0; }

.comment {
  border-top: 1px solid var(--color-border);
  padding: 12px 0;
}

.comment:first-child { border-top: none; }

.comment .meta { font-size: 0.8rem; color: var(--color-muted); margin-bottom: 4px; }

.report-field { margin-bottom: 14px; }
.report-field .field-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-muted); font-weight: 600; margin-bottom: 4px; }
.report-field .field-value { white-space: pre-wrap; }

/* Classic bordered ledger style for quotation/invoice/receipt line-item tables — a full grid
   with Sub Total / Grand Total rows built into the table itself, rather than separate summary
   text below it. */
.pricing-table { border-collapse: collapse; width: 100%; font-family: Georgia, 'Times New Roman', serif; font-size: 0.8rem; }
.pricing-table th, .pricing-table td { border: 1px solid #999; padding: 5px 10px; }
.pricing-table th { font-weight: 700; text-align: left; background: var(--color-bg); }
.pricing-table th.num, .pricing-table td.num { text-align: right; }
.pricing-table .summary-label { font-weight: 700; }
.pricing-table .grand-total td { font-weight: 700; padding-bottom: 14px; }
.pricing-table .grand-total .num { text-decoration: underline; text-underline-offset: 3px; padding-right: 20px; }

.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.print-header, .print-footer { display: none; }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .mobile-menu-toggle { display: inline-flex; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 14px 12px;
    display: none;
  }
  .sidebar.mobile-open { display: block; }
  .sidebar-brand { padding-bottom: 10px; }
  .topbar { padding: 14px 16px; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@media print {
  .no-print, .sidebar, .topbar, .site-footer { display: none !important; }

  body { background: #fff; }
  .app-shell { display: block; }
  .main-content { display: block; }

  .print-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid #000;
  }

  .print-header-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; }
  .print-logo { height: 54px; width: auto; }

  .print-doc-type { font-family: Garamond, 'EB Garamond', 'Times New Roman', serif; font-size: 1.3rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
  .print-meta { color: #555; font-size: 0.8rem; margin-top: 4px; }

  .print-address-text { font-family: Garamond, 'EB Garamond', 'Times New Roman', serif; font-size: 0.78rem; line-height: 1.5; color: #000; text-align: left; }
  .print-address-text strong { font-size: 0.92rem; }

  .print-footer {
    display: block;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
  }
  .print-footer img { width: 100%; height: auto; display: block; }

  .container { max-width: 100%; padding: 0; }
  main.container { padding: 0 0 130px 0; }

  .card {
    border: 1px solid #ccc;
    box-shadow: none;
    break-inside: avoid;
  }
}

/* Screen-media twin of the @media print rules above, scoped to a class instead of a media query —
   html2canvas renders the live screen DOM and can't see @media print styles, so downloadPdf() in
   header.php toggles this class on <body> instead. The footer banner is hidden from the captured
   content entirely — downloadPdf() stamps it onto every generated PDF page afterward, since a
   single flowing screenshot has no way to repeat a footer on each physical page. */
body.pdf-export-mode .no-print,
body.pdf-export-mode .sidebar,
body.pdf-export-mode .topbar,
body.pdf-export-mode .site-footer { display: none !important; }

body.pdf-export-mode { background: #fff; }
body.pdf-export-mode .app-shell { display: block; min-height: 0; }
body.pdf-export-mode .main-content { display: block; }

body.pdf-export-mode .print-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid #000;
}

body.pdf-export-mode .print-header-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; }
body.pdf-export-mode .print-logo { height: 54px; width: auto; }

body.pdf-export-mode .print-doc-type { font-family: Garamond, 'EB Garamond', 'Times New Roman', serif; font-size: 1.3rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
body.pdf-export-mode .print-meta { color: #555; font-size: 0.8rem; margin-top: 4px; }

body.pdf-export-mode .print-address-text { font-family: Garamond, 'EB Garamond', 'Times New Roman', serif; font-size: 0.78rem; line-height: 1.5; color: #000; text-align: left; }
body.pdf-export-mode .print-address-text strong { font-size: 0.92rem; }

body.pdf-export-mode .print-footer { display: none; }

body.pdf-export-mode .container { max-width: 100%; padding: 0; }
body.pdf-export-mode main.container { padding: 0; }

body.pdf-export-mode .card {
  border: 1px solid #ccc;
  box-shadow: none;
}
