:root {
  --bg: #f6f7f2;
  --panel: #ffffff;
  --ink: #1c2220;
  --muted: #66716d;
  --line: #dfe5dd;
  --brand: #0f6f64;
  --brand-2: #214e8a;
  --warn: #b26a00;
  --danger: #b33d35;
  --ok: #257a42;
  --soft: #edf5f2;
  --shadow: 0 14px 36px rgba(21, 31, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(21, 32, 30, 0.96), rgba(15, 111, 100, 0.86)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 42px);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  position: relative;
  z-index: 10;
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel p,
.login-panel small {
  color: var(--muted);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-logo {
  width: 160px;
  margin: 0 auto 12px;
}

.pdf-logo {
  width: 100%;
  height: 90px;
  border: none;
  object-fit: contain;
}

.report-logo-img {
  width: 160px;
  height: 100px;
  object-fit: contain;
  flex: 0 0 auto;
}

/* Ensure login and sidebar logos render as block images and scale nicely */
.login-logo img,
.brand-mark img,
.page-logo img {
  display: block;
  width: 160px;
  height: 100px;
  object-fit: contain;
  flex: 0 0 auto;
}

/* ensure top login logo is spaced from the panel */
#loginLogoTop { margin-bottom: 8px; }
/* keep logo above panel */
#loginLogoTop { position: relative; z-index: 20; }

.print-header {
  display: none;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 2px solid #111;
  margin-bottom: 12px;
}
.print-header svg,
.print-header img { width: 160px; height: 100px; }
.print-header-text h1 { margin: 0; font-size: 20px; }
.print-header-text p { margin: 0; color: #333; }

.page-logo,
.report-logo {
  width: 160px;
  height: 100px;
  margin-left: 4px;
}

.report-logo,
.report-logo svg,
.report-logo-svg {
  width: 160px;
  height: 100px;
  display: block;
}

.page-logo {
  display: block;
}

@media print {
  body * {
    visibility: hidden;
  }
  .print-sheet,
  .print-sheet *,
  .modal,
  .modal .print-sheet,
  .modal .print-sheet * {
    visibility: visible;
  }
  .modal {
    position: static;
    overflow: visible;
  }
  .topbar,
  .sidebar,
  .app-shell > :not(.modal) {
    display: none !important;
  }
  .print-sheet {
    width: 100%;
    background: #fff;
    color: #000;
    box-shadow: none;
    padding: 0;
  }
  .print-sheet .print-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
  }
  .print-sheet .print-head .report-logo {
    width: 160px;
    height: 100px;
    margin: 0;
  }
  .print-sheet .print-head .report-logo object {
    width: 100%;
    height: 100%;
  }
  .print-sheet .table-wrap table {
    width: 100%;
    border-collapse: collapse;
  }
  .print-sheet .table-wrap th,
  .print-sheet .table-wrap td {
    border: 1px solid #000;
    padding: 6px;
  }
}

.sidebar {
  min-height: 100vh;
  background: #15201e;
  color: #f7fbf9;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: transparent;
  overflow: hidden;
}

.brand-mark .pdf-logo {
  width: 100%;
  height: 100%;
  border: none;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.sidebar-footer small {
  color: #a9b6b2;
}

#nav {
  display: grid;
  gap: 6px;
}

.nav-btn {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 12px;
  color: #dbe7e3;
  background: transparent;
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: right;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.user-box {
  padding: 14px;
  border-radius: 8px;
  background: rgba(240, 200, 91, 0.12);
  border: 1px solid rgba(240, 200, 91, 0.22);
}

.user-box small,
.user-box strong,
.user-box span {
  display: block;
}

.user-box small,
.user-box span {
  color: #c4d0cc;
}

.user-box strong {
  margin: 4px 0;
}

.sidebar-footer strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}

.app-shell {
  min-width: 0;
}

.topbar {
  min-height: 84px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 242, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.topbar p,
.topbar h1 {
  margin: 0;
}

.topbar p {
  color: var(--muted);
  font-size: 14px;
}

.topbar h1 {
  margin-top: 4px;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar-actions,
.actions,
.form-row,
.filters,
.inline {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.view {
  padding: 24px 28px 36px;
  display: grid;
  gap: 18px;
}

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

.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 118px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

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

.metric strong {
  font-size: 28px;
}

.metric span {
  color: var(--brand);
  font-size: 13px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.panel h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.panel h2 {
  font-size: 20px;
}

.panel h3 {
  font-size: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

th,
td {
  padding: 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f9faf7;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--soft);
  color: var(--brand);
}

.badge.warn {
  background: #fff5e3;
  color: var(--warn);
}

.badge.danger {
  background: #fdecea;
  color: var(--danger);
}

.badge.ok {
  background: #eaf6ee;
  color: var(--ok);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.icon-btn {
  border-radius: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  padding: 0 14px;
}

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

.secondary-btn {
  color: var(--brand-2);
  background: #eef4fb;
  border-color: #d4e2f3;
}

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

.ghost-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.icon-btn,
.close-btn {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #fff;
  border-color: var(--line);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 111, 100, 0.12);
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.filters {
  margin-bottom: 12px;
}

.filters input,
.filters select {
  max-width: 260px;
}

.card-list {
  display: grid;
  gap: 10px;
}

.card {
  padding: 14px;
  box-shadow: none;
}

.card strong,
.card small {
  display: block;
}

.card small {
  color: var(--muted);
  margin-top: 4px;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: #e7ece8;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--brand);
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(9, 15, 14, 0.54);
  z-index: 20;
}

.modal.open {
  display: grid;
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(86vh, 920px);
  overflow: auto;
  position: relative;
  background: #fff;
  border-radius: 8px;
  padding: 22px;
}

.close-btn {
  position: absolute;
  left: 16px;
  top: 16px;
  border: 1px solid var(--line);
  font-size: 24px;
}

.print-sheet {
  color: #111;
  background: #fff;
}

.print-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 2px solid #111;
  margin-bottom: 18px;
}

.print-head h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.print-head small {
  color: #444;
}

.print-meta,
.print-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 18px;
}

.print-meta p,
.print-summary div {
  margin: 0;
  padding: 10px;
  border: 1px solid #cfd6d2;
  border-radius: 6px;
  background: #fafafa;
}

.print-summary small,
.print-summary strong {
  display: block;
}

.print-summary small {
  color: #555;
}

.print-summary strong {
  margin-top: 4px;
  font-size: 20px;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 34px;
}

.signature-grid.two-signatures {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.signature {
  border-top: 1px solid #111;
  padding-top: 8px;
  text-align: center;
}

.printed-by {
  margin: 18px 0 0;
  padding: 10px;
  border: 1px solid #cfd6d2;
  border-radius: 6px;
  background: #fafafa;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  #nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cols-2,
  .cols-3,
  .cols-4,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .filters input,
  .filters select {
    max-width: none;
  }
}

@media print {
  .print-header { display: flex !important; }
  #pageLogo, .brand-mark { display: none !important; }
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html,
  body {
    width: 210mm;
    height: 297mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  body {
    display: block;
    background: #fff;
  }

  .sidebar,
  .topbar,
  .modal .close-btn,
  .modal .actions {
    display: none !important;
  }

  body.modal-open .app-shell,
  .modal:not(.open) {
    display: none !important;
  }

  .modal.open {
    display: block !important;
    position: static;
    padding: 0;
    background: #fff;
  }

  .modal-panel,
  .panel,
  .table-wrap {
    box-shadow: none;
    border: 0;
    padding: 0;
    max-height: none;
  }

  .print-sheet {
    width: 100%;
    max-width: 210mm;
    min-height: 277mm;
    margin: 0 auto;
    padding: 10mm;
    box-shadow: none;
    background: #fff;
  }

  .print-sheet,
  .print-head,
  .print-meta,
  .print-summary,
  .signature-grid {
    page-break-inside: avoid;
  }

  .print-meta,
  .print-summary {
    grid-template-columns: repeat(4, 1fr);
    break-inside: avoid;
  }

  table {
    min-width: 0;
    font-size: 11px;
  }

  th,
  td {
    padding: 7px 6px;
    white-space: normal;
  }

  th {
    background: #f1f1f1 !important;
    color: #111;
  }

  .badge {
    border: 1px solid #999;
    background: transparent !important;
    color: #111 !important;
  }
}
