/* eClinic Medical Report Generator
   The report page intentionally uses Letter dimensions because the supplied
   reference PDF is 612 x 792 pt (8.5 x 11 in). */

:root {
  --ui-bg: #eef1f4;
  --ui-card: #ffffff;
  --ui-border: #d7dde4;
  --ui-text: #17202a;
  --ui-muted: #64707d;
  --ui-accent: #1769aa;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: Arial, Helvetica, sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 470px) 1fr;
}

.control-panel {
  padding: 28px;
  background: #fff;
  border-right: 1px solid var(--ui-border);
  overflow-y: auto;
}

.app-header { margin-bottom: 22px; }
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--ui-accent);
}
h1 { margin: 5px 0 7px; font-size: 27px; }
.app-header p { margin: 0; color: var(--ui-muted); line-height: 1.5; font-size: 13px; }

fieldset {
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  padding: 15px;
  margin: 0 0 14px;
}
legend {
  padding: 0 7px;
  font-weight: 700;
  font-size: 12px;
}
.grid { display: grid; gap: 11px; }
.grid.four { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr; }
.grid.two { grid-template-columns: 1fr; }

label {
  display: grid;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: #48525d;
}
input {
  width: 100%;
  height: 39px;
  border: 1px solid #cbd3db;
  border-radius: 7px;
  padding: 0 10px;
  font: 13px Arial, Helvetica, sans-serif;
  color: #111;
  background: #fff;
}
input:focus {
  outline: 2px solid rgba(23, 105, 170, .16);
  border-color: var(--ui-accent);
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
button {
  border: 0;
  border-radius: 7px;
  padding: 11px 15px;
  font-weight: 700;
  cursor: pointer;
}
button.primary { background: #17202a; color: #fff; }
button.secondary { background: #e9edf1; color: #17202a; }

.tip {
  color: var(--ui-muted);
  font-size: 11px;
  line-height: 1.5;
  margin: 12px 0 0;
}

.preview-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.preview-toolbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #fff;
  border-bottom: 1px solid var(--ui-border);
  font-size: 13px;
  font-weight: 700;
}
.status { color: #5d6874; font-weight: 500; }
.paper-wrap {
  flex: 1;
  overflow: auto;
  padding: 35px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ===== FIXED REPORT TEMPLATE ===== */
.report-page {
  position: relative;
  width: 612pt;
  height: 792pt;
  flex: 0 0 612pt;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.14);
  color: #111;
  font-family: Calibri, Carlito, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.15;
  overflow: hidden;
}

.logo {
  position: absolute;
  top: 25pt;
  right: 37pt;
  width: 135pt;
  height: auto;
}

.report-date {
  position: absolute;
  top: 101pt;
  right: 37pt;
  width: 174pt;
  text-align: center;
  font-weight: 700;
  font-size: 11pt;
  white-space: nowrap;
}

.report-title {
  position: absolute;
  top: 124pt;
  left: 0;
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 11pt;
}

.patient-ref {
  position: absolute;
  top: 150pt;
  left: 0;
  width: 100%;
  text-align: center;
  font-weight: 700;
  text-decoration: underline;
  font-size: 11pt;
  white-space: nowrap;
}

.intro {
  position: absolute;
  top: 194pt;
  left: 45pt;
  width: 520pt;
  font-weight: 400;
  font-size: 11pt;
  line-height: 1.35;
}

.report-section h2 {
  margin: 0;
  font-size: 11pt;
  font-weight: 700;
}

.report-section {
  position: absolute;
  left: 63pt;
  width: 500pt;
}

.vitals { top: 239pt; }
.labs { top: 355pt; }
.radiology { top: 455pt; }

.report-row {
  display: grid;
  grid-template-columns: 17pt 140pt 1fr;
  align-items: baseline;
  margin-top: 9pt;
  font-size: 11pt;
  line-height: 1.15;
}
.report-row > span:first-child { text-align: center; }
.report-row strong { font-weight: 400; }
.report-row > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.report-section h2 + .report-row { margin-top: 13pt; }

.signature {
  position: absolute;
  left: 45pt;
  top: 553pt;
  width: 190pt;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 11pt;
}
.signature img {
  width: 105pt;
  height: auto;
  margin-bottom: 12pt;
  margin-left: 2pt;
}
.signature strong {
  font-size: 11pt;
  font-weight: 700;
  line-height: 1.15;
}
.signature span {
  font-size: 11pt;
  margin-top: 3pt;
}

.report-footer {
  position: absolute;
  left: 20pt;
  right: 19pt;
  bottom: 15pt;
  height: 30pt;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.socials {
  display: flex;
  align-items: center;
  gap: 7pt;
}
.socials img {
  width: 29pt;
  height: 29pt;
}
.socials span {
  margin-left: 2pt;
  font-size: 8.5pt;
  font-weight: 700;
  color: #333;
}
.footer-mark {
  width: 45pt;
  height: 38pt;
  position: relative;
}
.footer-mark i {
  position: absolute;
  width: 18pt;
  height: 18pt;
  background: #e87c2b;
}
.footer-mark i:nth-child(1) { left: 0; top: 0; }
.footer-mark i:nth-child(2) { left: 20pt; top: 0; background: #cfcfcf; }
.footer-mark i:nth-child(3) { left: 0; top: 20pt; background: #d9d9d9; }
.footer-mark i:nth-child(4) { left: 20pt; top: 20pt; background: #f1f1f1; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--ui-border); }
  .preview-panel { min-height: 850px; }
}

@media print {
  @page {
    size: Letter portrait;
    margin: 0;
  }
  html, body {
    width: 8.5in;
    height: 11in;
    background: #fff;
  }
  .app-shell { display: block; }
  .control-panel, .preview-toolbar { display: none !important; }
  .preview-panel { display: block; }
  .paper-wrap {
    padding: 0;
    display: block;
    overflow: visible;
  }
  .report-page {
    box-shadow: none;
    margin: 0;
  }
}


.signature-upload {
  display: grid;
  gap: 9px;
}
.upload-label {
  cursor: pointer;
}
.upload-label input[type="file"] {
  height: auto;
  padding: 9px;
  cursor: pointer;
  background: #fafbfc;
}
.upload-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
button.small {
  padding: 8px 11px;
  font-size: 11px;
}
#stampStatus {
  color: #5d6874;
  font-size: 11px;
}
.upload-help {
  margin: 0;
  color: #64707d;
  font-size: 10.5px;
  line-height: 1.45;
}

/* HTML stamp library */
.stamp-library-control {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid #d9e2ec;
  border-radius: 12px;
  background: #f8fafc;
}
.stamp-library-control label {
  display: block;
  margin-bottom: 7px;
}
.stamp-library-control select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font: inherit;
}
.stamp-library-preview {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.stamp-library-preview span {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stamp-library-preview img {
  width: 180px;
  max-width: 100%;
  max-height: 110px;
  object-fit: contain;
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 5px;
}



/* V5 access / credit polish */
.app-credit {
  margin: 18px 0 4px;
  padding-top: 14px;
  border-top: 1px solid #e5e9ee;
  text-align: center;
  color: #7a8590;
  font-size: 10px;
  letter-spacing: .01em;
}
.app-credit strong { color: #4c5661; }
.session-lock {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.session-lock button {
  border: 1px solid #d8dee5;
  background: #fff;
  color: #56616d;
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.session-lock button:hover { border-color: #ef2b2d; color: #ef2b2d; }
