:root {
  --text: #222;
  --muted: #666;
  --accent: #0b79d0;
  --bg: #fff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #f6f7f9; color: var(--text); }
body { font: 14px/1.6 system-ui, -apple-system, Segoe UI, Roboto, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif; }

.app-header { position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid #e6e8eb; padding: 8px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.app-header h1 { margin: 0 12px 0 0; font-size: 18px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
label { font-size: 12px; color: var(--muted); }
button { cursor: pointer; padding: 6px 10px; border: 1px solid #d0d7de; border-radius: 6px; background: #fff; }
button:hover { border-color: var(--accent); }
.export button { font-size: 12px; }

.app-main { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 16px; }
.editor, .preview { background: #fff; border: 1px solid #e6e8eb; border-radius: 8px; padding: 12px; }
.editor h2, .preview h2 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
#jsonEditor { width: 100%; height: 320px; font: 12px/1.4 var(--mono); color: #111; background: #fafbfc; border: 1px solid #e6e8eb; border-radius: 6px; padding: 10px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

/* Resume preview */
.page { background: var(--bg); color: #111; }
.A4 { width: 210mm; min-height: 297mm; margin: 0 auto; padding: 14mm; box-shadow: 0 4px 24px rgba(0,0,0,.06); }

.resume-header { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: start; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 10px; }
.resume-header.no-photo { grid-template-columns: 1fr; }
.resume-header .name { font-size: 24px; font-weight: 700; }
.resume-header .meta { color: var(--muted); font-size: 12px; }
.resume-header .doc-title { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.resume-header .photo { justify-self: end; width: 120px; height: 160px; border: 1px solid #ccc; display: flex; align-items: center; justify-content: center; background: #f9fafb; }
.resume-header .photo img { width: 100%; height: 100%; object-fit: cover; }

.section { margin: 14px 0; }
.section h3 { margin: 0 0 6px; font-size: 14px; border-left: 4px solid #000; padding-left: 6px; }
.section .item { margin: 6px 0; }
.row { display: grid; grid-template-columns: 140px 1fr; gap: 10px; }
.muted { color: var(--muted); }
ul { margin: 6px 0 6px 18px; }
code { background: #f2f4f7; padding: 1px 4px; border-radius: 4px; }

/* Section tables */
.section-table { width: 100%; border-collapse: collapse; border: 1px solid #e1e5ea; margin: 12px 0 16px; background: #fff; table-layout: fixed; }
.section-table caption { caption-side: top; text-align: left; font-weight: 700; font-size: 14px; padding: 8px 10px; background: #f5f7fb; border-bottom: 1px solid #e1e5ea; border-left: 4px solid #0b79d0; }
.section-table th, .section-table td { padding: 8px 10px; border-bottom: 1px solid #eef1f4; vertical-align: top; word-wrap: break-word; }
.section-table thead th { background: #f9fbfd; font-weight: 600; color: #333; border-bottom: 1px solid #e1e5ea; }
.section-table tbody tr:last-child td, .section-table tbody tr:last-child th { border-bottom: none; }
.section-table .col-narrow { width: 22%; }
.section-table .col-mid { width: 28%; }
.section-table .col-date { width: 26%; white-space: nowrap; }
.section-table .col-content { width: 74%; }
.kv th { background: #f9fbfd; width: 22%; }
.kv td { width: 78%; }
.bullet { margin: 0; padding-left: 18px; }
.bullet li { margin: 4px 0; }

.section-wrap { page-break-inside: avoid; break-inside: avoid; }

/* Photo in table */
.section-table .photo-cell { text-align: center; padding-right: 0; padding-left: 0%; }
.section-table .photo-cell img { width: 120px; height: 160px; object-fit: cover; border: 1px solid #ccc; background: #f9fafb; display: block; margin: 0 auto; }

/* Profile extras */
.name-lg { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.inline-fields { display: inline-flex; gap: 8px; margin-left: 8px; vertical-align: middle; }
.inline-fields .mini { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d0d7de; border-radius: 4px; padding: 2px 6px; font-size: 12px; color: #333; background: #fbfcfe; }
.inline-fields .mini label { color: var(--muted); font-size: 11px; }
.profile-table col.col-label { width: 18%; }
.profile-table col.col-value { width: 42%; }
.profile-table col.col-mini-label { width: 12%; }
.profile-table col.col-mini-value { width: 18%; }
.profile-table col.col-photo { width: 120px; }

@media print {
  body { background: white; }
  .app-header, .editor h2, .preview h2 { display: none; }
  .A4 { box-shadow: none; margin: 0; padding: 12mm; }
  .editor, .preview { border: none; }
}
/* Tabs */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs .tab { padding: 6px 10px; border: 1px solid #d0d7de; background: #fff; border-radius: 6px; font-size: 12px; }
.tabs .tab.active { background: #eef6ff; border-color: var(--accent); }
.tabpanels { border-top: 1px dashed #e6e8eb; padding-top: 8px; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* Form */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.form-grid.sm { grid-template-columns: repeat(2, 1fr); }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea { padding: 6px 8px; border: 1px solid #d0d7de; border-radius: 6px; font-size: 13px; }
.item-card { border: 1px solid #e6e8eb; border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.item-head h4 { margin: 0; font-size: 13px; }
.row-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
button.icon { padding: 4px 8px; font-size: 12px; }
.showbox { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 6px; border: 1px dashed #e6e8eb; border-radius: 6px; padding: 8px; }

/* Simple form rows for clarity */
.field { margin: 8px 0; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field > label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.field textarea { width: 100%; }

/* Employment/Project Editor UI */
.emp-details { border: 1px solid #d0d7de; border-radius: 8px; margin-bottom: 20px; background: #fff; }
.emp-details[open] { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.emp-summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; background: #f5f7fa; border-radius: 8px; font-weight: 600; }
.emp-details[open] > .emp-summary { border-radius: 8px 8px 0 0; border-bottom: 1px solid #e6e8eb; }
.emp-summary::-webkit-details-marker { display: none; }
.emp-summary::before { content: "▶"; font-size: 10px; color: #888; transition: transform .15s; }
.emp-details[open] > .emp-summary::before { transform: rotate(90deg); }
.emp-title { flex: 1; font-size: 14px; }
.emp-period { font-size: 12px; color: var(--muted); font-weight: normal; }
.emp-body { padding: 12px; }

.proj-section { margin-top: 12px; border-top: 1px dashed #e6e8eb; padding-top: 10px; }
.proj-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.proj-details { border: 1px solid #e0e4e8; border-radius: 6px; margin-bottom: 4px; background: #fafbfc; }
.proj-details[open] { background: #fff; }
.proj-summary { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px; }
.proj-summary::-webkit-details-marker { display: none; }
.proj-summary::before { content: "▶"; font-size: 9px; color: #999; transition: transform .15s; }
.proj-details[open] > .proj-summary::before { transform: rotate(90deg); }
.proj-title { flex: 1; font-weight: 500; }
.proj-period { font-size: 11px; color: var(--muted); }
.proj-body { padding: 10px; border-top: 1px solid #e6e8eb; }

.sub-details { margin-top: 8px; }
.sub-details > summary { font-size: 12px; color: var(--muted); cursor: pointer; padding: 4px 0; }
.sub-details[open] > summary { margin-bottom: 8px; }

.form-row { display: flex; gap: 10px; margin-bottom: 10px; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row label.flex-1 { flex: 1; }
.form-row label.flex-2 { flex: 2; }
.form-row input, .form-row textarea { padding: 8px 10px; border: 1px solid #d0d7de; border-radius: 6px; font-size: 14px; }
.form-row textarea { resize: vertical; min-height: 60px; }
label.full { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label.full input, label.full textarea { padding: 8px 10px; border: 1px solid #d0d7de; border-radius: 6px; font-size: 14px; width: 100%; }
label.full textarea { resize: vertical; min-height: 60px; }

.del-btn { margin-left: auto; background: #fee; border-color: #fcc; color: #c33; }
.del-btn:hover { background: #fdd; border-color: #e99; }

/* Toast */
.toast { position: fixed; right: 16px; bottom: 16px; background: rgba(30, 41, 59, 0.92); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; font-size: 13px; z-index: 1000; }
.toast.show { opacity: 1; transform: translateY(0); }

/* Modal */
.modal { position: fixed; inset: 0; display: none; z-index: 999; }
.modal.show { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-content { position: relative; background: #fff; width: min(900px, 90vw); max-height: 90vh; margin: 5vh auto; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: flex; flex-direction: column; }
.modal-header, .modal-footer { padding: 10px 12px; border-bottom: 1px solid #e6e8eb; display: flex; align-items: center; justify-content: space-between; }
.modal-footer { border-top: 1px solid #e6e8eb; border-bottom: none; }
.modal-body { padding: 10px 12px; overflow: auto; }
.crop-area { display: grid; place-items: center; background: #f6f7f9; border: 1px solid #e6e8eb; border-radius: 8px; padding: 8px; }
.crop-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.modal-content button.icon { border: 1px solid #d0d7de; border-radius: 6px; padding: 6px 10px; background: #fff; }
.crop-controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.crop-controls label { display: flex; align-items: center; gap: 8px; }
.crop-controls input[type=range] { width: 160px; }

/* Details/Summary for collapsible sections */
details { margin: 8px 0; }
details summary { cursor: pointer; font-size: 12px; color: var(--accent); padding: 4px 0; }
details[open] summary { margin-bottom: 6px; }
.company-info-details, .env-details { background: #f9fbfd; border: 1px dashed #e6e8eb; border-radius: 6px; padding: 8px; margin: 8px 0; }
.proj-card { border-left: 3px solid var(--accent); }

/* Career document (doda形式) */
.career-doc { font-size: 12px; line-height: 1.5; }
.career-doc h3 { font-size: 16px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.career-doc .career-meta { text-align: right; font-size: 11px; margin-bottom: 12px; }
.career-doc .career-section { margin: 12px 0; }
.career-doc .career-section-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.career-doc .career-summary-text { margin: 8px 0 16px; text-align: justify; }
.career-doc .applicable-list { margin: 0 0 16px 0; }
.career-doc .applicable-list li { margin: 3px 0; }

/* Company header table */
.career-doc .company-header-table { width: 100%; border-collapse: collapse; margin-bottom: 0; margin-top: 24px; }
.career-doc .company-header-table:first-child { margin-top: 0; }
.career-doc .company-header-table th { background: #f0f4f8; font-weight: 700; padding: 6px 10px; border: 1px solid #ccc; text-align: left; }
.career-doc .company-header-table td { padding: 6px 10px; border: 1px solid #ccc; vertical-align: top; }
.career-doc .company-header-table .emp-type { width: 120px; text-align: center; }

/* Project table (3-column doda style) */
.career-doc .project-table { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
.career-doc .project-table th { background: #f0f4f8; font-weight: 600; padding: 6px 8px; border: 1px solid #ccc; font-size: 11px; }
.career-doc .project-table td { padding: 8px; border: 1px solid #ccc; vertical-align: top; font-size: 11px; }
.career-doc .project-table .col-main { width: 55%; }
.career-doc .project-table th.col-main { justify-content: space-between; align-items: center; }
.career-doc .project-table th.col-main .proj-name { text-align: right; }
.career-doc .project-table .col-env { width: 28%; }
.career-doc .project-table .col-scale { width: 17%; text-align: center; }
.career-doc .project-table .proj-label { font-weight: 700; margin-top: 8px; }
.career-doc .project-table .proj-label:first-child { margin-top: 0; }
.career-doc .project-table .proj-list { margin: 2px 0 0 14px; padding: 0; }
.career-doc .project-table .proj-list li { margin: 2px 0; }
.career-doc .project-table .env-label { font-weight: 600; margin-top: 6px; }
.career-doc .project-table .env-label:first-child { margin-top: 0; }

/* Technical skills matrix */
.career-doc .tech-skill-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.career-doc .tech-skill-table th, .career-doc .tech-skill-table td { padding: 5px 8px; border: 1px solid #ccc; font-size: 11px; }
.career-doc .tech-skill-table th { background: #f0f4f8; font-weight: 600; }
.career-doc .tech-skill-table .cat-cell { background: #f9fbfd; font-weight: 600; width: 20%; vertical-align: middle; text-align: center; }
.career-doc .tech-skill-table .name-cell { width: 60%; }
.career-doc .tech-skill-table .period-cell { width: 20%; text-align: center; }

/* Certifications list */
.career-doc .cert-list { margin: 0 0 12px 0; padding: 0; list-style: none; }
.career-doc .cert-list li { margin: 3px 0; padding-left: 8px; }

/* Self PR */
.career-doc .pr-title { font-weight: 700; margin: 10px 0 4px; }
.career-doc .pr-text { margin: 0 0 10px; text-align: justify; }

/* Footer */
.career-doc .career-footer { text-align: right; margin-top: 16px; font-size: 12px; }

/* Print: only preview page */
@media print {
  @page { size: A4; margin: 6mm 0 6mm 0; }
  /* Hide non-preview content entirely to remove gaps */
  .app-header { display: none !important; }
  .print-header { display: none !important; }
  .app-main { display: block !important; margin: 0 !important; padding: 0 !important; }
  .app-main > :not(.preview) { display: none !important; }

  /* Place preview at top-left for print */
  .preview { margin: 0 !important; padding: 0 !important; position: static !important; }
  .preview .A4 { box-shadow: none !important; margin: 0 !important; padding: 12mm 12mm 12mm 12mm !important; }
  .preview .A4:not(:first-child) { padding-top: 18mm !important; }

  .page-head { display: flex; justify-content: flex-end; align-items: center; height: 10mm; color: #555; font-size: 11px; margin-bottom: 4mm; }

  /* Running header with page numbers */
  .print-header { position: fixed; top: 0; left: 0; right: 0; height: 12mm; padding: 2mm 12mm; display: flex; align-items: center; justify-content: flex-end; color: #555; font-size: 11px; }
  .print-header::after { content: counter(page) " / " counter(pages); }

  /* Avoid page breaks inside tables/sections */
  .section-wrap { break-inside: avoid !important; page-break-inside: avoid !important; }
  .section-table, .section-table * { break-inside: avoid !important; page-break-inside: avoid !important; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  tr, td, th { page-break-inside: avoid !important; }
  .kv { break-inside: avoid !important; page-break-inside: avoid !important; }

  /* Reduce top whitespace that some browsers add */
  html, body { margin: 0 !important; padding: 0 !important; }
}
