/* LMS 개선보고서 — 목록 + 작성, 화면·인쇄 */

:root {
  --border: #111;
  --bg: #eef1f5;
  --paper: #fff;
  --text: #111;
  --muted: #6b7280;
  --accent: #1e3a5f;
  --primary: #1e3a5f;
  --danger: #b91c1c;
  --radius: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    "Malgun Gothic",
    "Apple SD Gothic Neo",
    "Noto Sans KR",
    system-ui,
    sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.is-hidden {
  display: none !important;
}

/* ----- 목록 ----- */
.view {
  min-height: 100vh;
}

.app-header {
  background: linear-gradient(180deg, #f8fafc 0%, #eef1f5 100%);
  border-bottom: 1px solid #d1d5db;
  padding: 1.25rem 1.5rem 1.5rem;
}

.app-header-inner {
  max-width: 1040px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.app-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.65rem;
  flex-wrap: wrap;
}

.storage-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

body.storage-local .storage-badge {
  color: #6b21a8;
  background: #f5f3ff;
  border-color: #ddd6fe;
}

.search-panel {
  max-width: 1040px;
  margin: 0 auto;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.search-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.search-label input {
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  min-width: 10rem;
  background: #fff;
}

.search-grow {
  flex: 1;
  min-width: 200px;
}

.search-grow input {
  min-width: 100%;
}

.search-actions {
  display: flex;
  gap: 0.5rem;
}

.search-actions button {
  font: inherit;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  border: 1px solid #94a3b8;
  background: #fff;
  cursor: pointer;
}

.search-actions button:hover {
  background: #f8fafc;
}

.list-main {
  padding: 1.5rem 1.5rem 3rem;
  max-width: 1080px;
  margin: 0 auto;
}

.list-wrap {
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid #e2e8f0;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
  padding: 1.25rem 1.35rem 1.5rem;
}

.list-count {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.list-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.85rem;
  padding: 0.5rem 0;
}

.list-bulk-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  user-select: none;
}

.btn-print-bulk {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #1e40af;
  background: #eff6ff;
  color: #1e3a8a;
  cursor: pointer;
}

.btn-print-bulk:hover {
  background: #dbeafe;
}

.btn-print-bulk-secondary {
  border-color: #64748b;
  background: #f8fafc;
  color: #334155;
}

.btn-print-bulk-secondary:hover {
  background: #f1f5f9;
}

.btn-print-bulk-date {
  border-color: #0d9488;
  background: #f0fdfa;
  color: #0f766e;
}

.btn-print-bulk-date:hover {
  background: #ccfbf1;
}

.report-table .col-check {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}

.report-table .col-check input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

/* 여러 건 인쇄용 (화면에서는 숨김) */
.bulk-print-root {
  display: none;
}

body.mode-bulk-print .bulk-print-root {
  display: block;
  max-width: 186mm;
  margin: 0 auto;
  padding: 4mm 2mm;
  box-sizing: border-box;
}

body.mode-bulk-print #view-list,
body.mode-bulk-print #view-form {
  display: none !important;
}

.bulk-print-sheet {
  page-break-after: always;
}

.bulk-print-sheet:last-child {
  page-break-after: auto;
}

.print-multiline {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.bulk-print-img-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.bulk-print-img-wrap img {
  max-width: 220px;
  max-height: 180px;
  object-fit: contain;
  border: 1px solid #ccc;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.report-table th,
.report-table td {
  border: 1px solid #e5e7eb;
  padding: 0.65rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.report-table thead th {
  background: #f8fafc;
  font-weight: 600;
  white-space: nowrap;
}

.report-table tbody tr:hover {
  background: #fafbfc;
}

.report-table .col-actions {
  white-space: nowrap;
  width: 1%;
}

.report-table button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  margin-right: 0.35rem;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
}

.report-table button:hover {
  background: #f1f5f9;
}

.report-table .btn-open {
  color: var(--primary);
  border-color: #93c5fd;
}

.report-table .btn-del {
  color: var(--danger);
  border-color: #fecaca;
}

.cell-empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem !important;
}

/* ----- 버튼 공통 ----- */
.btn-primary {
  font: inherit;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-danger {
  font: inherit;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: 1px solid #fecaca;
  background: #fff;
  color: var(--danger);
  cursor: pointer;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* ----- 작성 화면 툴바 ----- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 1rem 1.25rem;
  background: #e5e7eb;
  border-bottom: 1px solid #d1d5db;
  position: sticky;
  top: 0;
  z-index: 10;
}

.toolbar button {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid #9ca3af;
  background: #fff;
  cursor: pointer;
}

.toolbar button:hover {
  background: #f9fafb;
}

.toolbar .btn-muted {
  color: var(--muted);
  border-color: #d1d5db;
}

.toolbar .btn-primary {
  border: none;
  background: #2563eb;
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.45);
}

.toolbar .btn-primary:hover {
  background: #1d4ed8;
  color: #ffffff;
  filter: none;
}

.toolbar .btn-secondary {
  border: 1px solid #0f766e;
  background: #ecfdf5;
  color: #0f766e;
  font-weight: 600;
}

.toolbar .btn-secondary:hover {
  background: #d1fae5;
  color: #115e59;
}

.toolbar-status {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ----- 양식 ----- */
.sheet {
  max-width: 920px;
  margin: 2rem auto 3rem;
  padding: 2.5rem 2.5rem 3rem;
  background: var(--paper);
  border: 2px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.07);
}

.sheet-meta {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.form-code {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.head-block {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 34%);
  gap: 0;
  border: 2px solid var(--border);
  border-bottom: none;
  min-height: 9rem;
}

.title-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.35rem 1rem;
  border-right: 2px solid var(--border);
}

.doc-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
}

.head-right {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100%;
}

.head-right .mini-label {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  padding: 0.45rem 0.25rem;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.head-right .mini-label:first-of-type {
  border-right: 1px solid var(--border);
}

.head-input {
  font: inherit;
  resize: vertical;
  min-height: 5.5rem;
  padding: 0.55rem 0.6rem;
  border: none;
  margin: 0;
  width: 100%;
  line-height: 1.5;
}

.head-input:first-of-type {
  border-right: 1px solid var(--border);
}

.head-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  border: 2px solid var(--border);
  table-layout: fixed;
}

.grid th,
.grid td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.65rem;
  vertical-align: middle;
}

.grid th {
  width: 18%;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  background: #fafafa;
}

.grid .th-narrow {
  width: 14%;
}

.grid td {
  background: #fff;
}

.cell-split {
  width: 30%;
  min-width: 13rem;
}

/* 날짜 입력: 인쇄 시 겹침 방지 (클래스로 단일·일괄 인쇄 공통 규격) */
input[type="date"].field-work-date {
  min-width: 11.5rem;
  width: 100%;
  max-width: 100%;
  padding: 0.35rem 0.45rem;
  font: inherit;
  border: 1px solid transparent;
  border-radius: 4px;
  box-sizing: border-box;
}

input[type="date"].field-work-date:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: #cbd5e1;
}

.input-full,
.area-full {
  width: 100%;
  font: inherit;
  border: none;
  padding: 0.45rem 0.35rem;
  margin: 0;
  background: transparent;
  line-height: 1.55;
}

.input-full:focus,
.area-full:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.row-tall th {
  vertical-align: top;
  padding-top: 0.85rem;
}

.area-full {
  resize: vertical;
  min-height: 10rem;
}

/* 작업위치 체크 */
.location-checks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.25rem 0;
}

.location-checks .chk {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
}

.location-checks input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.chk-other {
  margin-right: 0.25rem;
}

.loc-other-input {
  flex: 1;
  min-width: 140px;
  max-width: 320px;
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
}

.loc-other-input:disabled {
  background: #f3f4f6;
  color: #9ca3af;
}

.location-print {
  display: none;
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  line-height: 1.55;
}

/* 첨부 */
.attach-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 0.65rem;
}

.btn-file {
  position: relative;
  display: inline-block;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px dashed #64748b;
  background: #f8fafc;
  cursor: pointer;
  color: var(--accent);
  overflow: hidden;
}

.btn-file input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
}

.attach-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.attach-note {
  min-height: 4rem;
  margin-bottom: 0.75rem;
  border: 1px solid #e5e7eb !important;
  border-radius: 6px;
  padding: 0.5rem !important;
}

.attach-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.65rem;
}

.attach-card {
  position: relative;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #fafafa;
}

.attach-card img {
  display: block;
  width: 100%;
  height: 100px;
  object-fit: cover;
}

.attach-card .attach-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.attach-card .attach-name {
  font-size: 0.7rem;
  padding: 0.25rem 0.35rem;
  color: var(--muted);
  word-break: break-all;
}

.attach-print-gallery {
  display: none;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.attach-print-gallery img {
  max-width: 220px;
  max-height: 180px;
  object-fit: contain;
  border: 1px solid #ccc;
}

.print-only {
  display: none !important;
}

.company-line {
  margin-top: 0;
  border: 2px solid var(--border);
  border-top: none;
  padding: 1.1rem 1.25rem;
  text-align: center;
  background: #fafafa;
}

.company-line p {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.company-line [contenteditable="true"]:focus {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}

.row-attachments td {
  vertical-align: top;
  padding-top: 0.75rem;
  padding-bottom: 0.85rem;
}

@media (max-width: 720px) {
  .head-block {
    grid-template-columns: 1fr;
  }

  .title-area {
    border-right: none;
    border-bottom: 2px solid var(--border);
  }

  .sheet {
    margin: 1rem 0.75rem 2rem;
    padding: 1.5rem 1rem 2rem;
  }
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  /* 인쇄 기준 글자 크기(작성 화면과 비슷하게 보이도록 pt 고정, 축소 완화) */
  html {
    font-size: 12pt !important;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    background: #fff !important;
    font-size: 11pt !important;
    line-height: 1.45;
    margin: 0;
    padding: 0;
  }

  .no-print {
    display: none !important;
  }

  body.mode-form #view-list {
    display: none !important;
  }

  body.mode-list #view-form {
    display: none !important;
  }

  body.mode-form #view-form,
  body.mode-list #view-list {
    display: block !important;
  }

  .location-checks,
  .attach-toolbar,
  .attach-preview {
    display: none !important;
  }

  /* 목록 화면에서만 숨김 — 일괄 인쇄(mode-bulk-print) 시에는 편집 화면과 같이 표시 */
  body.mode-list:not(.mode-bulk-print) .location-print {
    display: none !important;
  }

  .location-print {
    display: block !important;
  }

  .print-only {
    display: flex !important;
  }

  /* A4 가로 usable 폭(약 186mm)에 맞춤 — 너비 넘침으로 인한 자동 축소 완화 */
  .sheet {
    box-sizing: border-box;
    width: 100%;
    max-width: 186mm;
    margin: 0 auto !important;
    padding: 3mm 4mm 4mm !important;
    border: 2px solid #000 !important;
    box-shadow: none !important;
    background: #fff !important;
    font-size: 11pt !important;
  }

  .sheet-meta {
    margin-bottom: 2mm;
  }

  .form-code {
    font-size: 8.5pt !important;
  }

  .head-block {
    border-width: 1.5pt;
    min-height: 0;
  }

  .title-area {
    border-right-width: 1.5pt;
    padding: 3mm 2mm !important;
  }

  .doc-title {
    font-size: 20pt !important;
    font-weight: 700;
  }

  .head-right .mini-label {
    font-size: 10pt !important;
    padding: 2mm 1mm !important;
  }

  .head-input,
  .print-multiline,
  .input-full,
  .area-full {
    font-size: 11pt !important;
    line-height: 1.45 !important;
  }

  .head-input {
    min-height: 18mm;
  }

  .grid {
    border-width: 1.5pt;
    width: 100%;
    table-layout: fixed;
  }

  .grid th,
  .grid td {
    border-width: 0.75pt;
    font-size: 11pt !important;
    padding: 2mm 2.5mm !important;
  }

  .company-line {
    border-width: 1.5pt;
    padding: 3mm !important;
  }

  .company-line p {
    font-size: 12pt !important;
  }

  .grid tr:first-child td.cell-split {
    width: 36%;
    min-width: 0;
  }

  .grid tr:first-child th.th-narrow {
    width: 11%;
  }

  input[type="date"].field-work-date,
  input[type="text"] {
    font-size: 11pt !important;
  }

  input[type="date"].field-work-date {
    min-width: 28mm;
    padding: 1mm 1.5mm !important;
    line-height: 1.35;
  }

  /* 일괄 인쇄용 readonly 필드도 편집 화면 인쇄와 동일 톤 */
  body.mode-bulk-print textarea[readonly],
  body.mode-bulk-print input[readonly] {
    color: inherit !important;
    opacity: 1 !important;
    -webkit-text-fill-color: currentColor;
  }

  .row-tall .area-full {
    min-height: 28mm;
  }

  .attach-print-gallery img {
    max-width: 70mm;
    max-height: 55mm;
  }

  .bulk-print-img-wrap img {
    max-width: 70mm;
    max-height: 55mm;
  }

  body.mode-bulk-print #bulk-print-root {
    display: block !important;
    max-width: 186mm;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
  }

  body.mode-bulk-print #view-list,
  body.mode-bulk-print #view-form {
    display: none !important;
  }

  /*
   * 일괄 인쇄: 각 장을 단일 인쇄(#report)와 동일한 박스·글자 규격으로 맞춤.
   * (page-break-inside: avoid 는 내용이 길 때 브라우저가 장마다 축소 배율을 달리하는 원인이 됨)
   */
  body.mode-bulk-print .bulk-print-sheet.sheet {
    box-sizing: border-box;
    width: 100%;
    max-width: 186mm;
    margin: 0 auto !important;
    padding: 3mm 4mm 4mm !important;
    border: 2px solid #000 !important;
    border-radius: 0;
    box-shadow: none !important;
    background: #fff !important;
    font-size: 11pt !important;
    page-break-after: always;
    page-break-inside: auto;
    break-inside: auto;
  }

  body.mode-bulk-print .bulk-print-sheet.sheet:last-child {
    page-break-after: auto;
  }
}
