/* ==========================================================================
   GLOBAL VARIABLES & BASE STYLES
   ========================================================================== */
:root {
  --ink: #1C1C1C;
  --paper: #f4f5f6;
  --panel: #FFFFFF;
  --line: #e0e3e6;
  --line-soft: #f0f2f4;
  --accent: #FFA62F;
  --accent-hover: #FFDB58;
  --accent-dark: #1C1C1C;
  --ok: #2f7a4f;
  --ok-soft: #e5f3ea;
  --warn: #b1560f;
  --warn-soft: #fbeee2;
  --muted: #686e73;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* ==========================================================================
   DESKTOP DISPLAY STYLES (Default Layout)
   ========================================================================== */




/* ---- Panels ---- */
.panel {
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #1C1C1C;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #FFA62F;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--sans);
  color: #1C1C1C;
  background: #FFFFFF;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid #FFA62F;
  outline-offset: 1px;
  border-color: #FFA62F;
}

/* ---- Checklist ---- */
.group-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #1C1C1C;
  margin: 2px 0 10px;
}

.group-label .ltr {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: #FFA62F;
  color: #1C1C1C;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.item {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #fdfdfd;
}

.item.checked {
  background: var(--ok-soft);
  border-color: #bfe0cb;
}

.item .num {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  padding-top: 2px;
  min-width: 18px;
}

.item .desc {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.45;
}

.item .check-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 1px;
}

.item input[type=checkbox] {
  width: 19px;
  height: 19px;
  accent-color: #FFA62F;
  cursor: pointer;
}

.item .remarks {
  flex: 1.1;
}

.item .remarks input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  background: #FFFFFF;
}

.item .remarks .trio {
  display: flex;
  gap: 6px;
}

.item .remarks .trio .sub {
  flex: 1;
}

.item .remarks .trio label {
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

.item .remarks .trio input {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
}

.col-heads {
  display: flex;
  gap: 12px;
  padding: 0 14px 6px;
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
}

.col-heads .c1 {
  min-width: 18px;
}

.col-heads .c2 {
  flex: 1;
}

.col-heads .c3 {
  width: 56px;
  text-align: center;
}

.col-heads .c4 {
  flex: 1.1;
}

/* ---- Sign-off ---- */
.signoff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.sign-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px;
  background: #fdfdfd;
}

.sign-card h3 {
  font-size: 11.5px;
  margin: 0 0 10px;
  color: #1C1C1C;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.sign-card .field {
  margin-bottom: 8px;
}

canvas.sigpad {
  width: 100%;
  height: 90px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #FFFFFF;
  touch-action: none;
  cursor: crosshair;
}

.sig-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.sig-actions button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 7px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: .02em;
  transition: background 0.2s, color 0.2s;
}

.btn-primary {
  background: #FFA62F;
  color: #1C1C1C;
}

.btn-primary:hover {
  background: #FFDB58;
  color: #1C1C1C;
}

.btn-ghost {
  background: transparent;
  color: #1C1C1C;
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  background: #FFDB58;
  color: #1C1C1C;
  border-color: #FFDB58;
}

.btn-danger {
  background: transparent;
  color: #a33;
  border: 1px solid #eac3c3;
}

.btn-danger:hover {
  background: #fbeaea;
}

.action-bar {
  position: sticky;
  bottom: 0;
  background: linear-gradient(0deg, var(--paper) 60%, transparent);
  padding: 14px 0 4px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.status-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.status-draft {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-complete {
  background: var(--ok-soft);
  color: var(--ok);
}

/* ---- Records list ---- */
.rec-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.rec-toolbar input {
  flex: 1;
  min-width: 180px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  background: #FFFFFF;
}

table.rec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.rec-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 2px solid #FFA62F;
  padding: 8px 10px;
}

table.rec-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

table.rec-table tr:hover td {
  background: #fffdf9;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  padding: 5px 10px;
  font-size: 11.5px;
  border-radius: 5px;
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}

.empty-state .big {
  font-size: 34px;
  margin-bottom: 8px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1C1C1C;
  color: #FFFFFF;
  border-left: 4px solid #FFA62F;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: -4px;
  margin-bottom: 14px;
}


/* ==========================================================================
   PRINT / PDF STYLES
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 5mm 8mm;
  }

  html, body {
    background: #ffffff !important;
    font-size: 7.5pt !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide navigation, action bars, and UI hints */
  .topbar, .action-bar, .rec-toolbar, .tabs, #recordsView, .hint, #statusChip, .sig-actions, .toast {
    display: none !important;
  }

  #formView {
    display: block !important;
  }

  /* Column Headers */
  .col-heads {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 0 6px 2px !important;
    font-size: 6pt !important;
    font-weight: bold !important;
    color: #5c6b78 !important;
    text-transform: uppercase !important;
  }

  .col-heads .c1 { width: 16px !important; text-align: center !important; }
  .col-heads .c2 { flex: 2 !important; }
  .col-heads .c3 { width: 36px !important; text-align: center !important; }
  .col-heads .c4 { flex: 2 !important; }

  /* Enforce horizontal side-by-side alignment */
  .item {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 8px !important;
    border: 0.5pt solid #ccd4da !important;
    border-radius: 3px !important;
    padding: 3pt 6pt !important;
    margin-bottom: 2pt !important;
    background: #ffffff !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .item.checked {
    background: #eef6f0 !important;
  }

  /* Number column */
  .item .num {
    width: 16px !important;
    font-size: 7pt !important;
    font-weight: bold !important;
    color: #5c6b78 !important;
    text-align: center !important;
    flex-shrink: 0 !important;
  }

  /* Description column (Side-by-Side Left) */
  .item .desc {
    flex: 2 !important;
    font-size: 7.5pt !important;
    line-height: 1.15 !important;
    color: #16232f !important;
    margin: 0 !important;
    width: auto !important;
  }

  /* Checkbox column */
  .item .check-wrap {
    width: 36px !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    padding: 0 !important;
  }

  .item .check-wrap::before {
    content: "" !important; /* Removes "Mark Completed:" text on mobile view */
    display: none !important;
  }

  .item input[type="checkbox"] {
    width: 11pt !important;
    height: 11pt !important;
    margin: 0 !important;
  }

  /* Remarks column (Side-by-Side Right) */
  .item .remarks {
    flex: 2 !important;
    margin: 0 !important;
    width: auto !important;
  }

  .item .remarks input {
    width: 100% !important;
    border: none !important;
    border-bottom: 0.5pt solid #999999 !important;
    border-radius: 0 !important;
    background: transparent !important;
    font-size: 7pt !important;
    height: 12pt !important;
    padding: 0 2px !important;
  }

  /* Trio inputs (L1, L2, L3) and (Hi, Lo) */
  .item .remarks .trio {
    display: flex !important;
    flex-direction: row !important;
    gap: 6px !important;
    width: 100% !important;
  }

  .item .remarks .trio .sub {
    flex: 1 !important;
    display: flex !important;
    align-items: center !important;
    gap: 3px !important;
  }

  .item .remarks .trio label {
    font-size: 5.5pt !important;
    font-weight: bold !important;
    color: #5c6b78 !important;
    margin: 0 !important;
  }
}

/* ==========================================================================
   MOBILE DISPLAY STYLES (max-width: 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {
  .app {
    padding: 12px 10px 100px;
  }

  .panel { 
    padding: 14px 12px; 
  }
  
  .meta-grid { 
    grid-template-columns: 1fr; 
    gap: 10px; 
  }
  
  .signoff-grid { 
    grid-template-columns: 1fr; 
  }

  .field input, 
  .field textarea, 
  .field select, 
  .item .remarks input {
    font-size: 16px;
  }

  .col-heads { 
    display: none; 
  }

  .item {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding-top: 12px;
  }

  .item .desc { 
    font-size: 14px; 
    width: 100%; 
  }

  .item .check-wrap {
    width: 100%;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: #f0f2f4;
    border-radius: 6px;
  }

  .item .check-wrap::before {
    content: "Mark Completed:";
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
  }

  .item input[type=checkbox] { 
    width: 22px; 
    height: 22px; 
  }
  
  .item .remarks { 
    width: 100%; 
  }
}