/* ============================================================
   履歴書メーカー (Rirekisho Maker) — Pure Static Stylesheet
   ============================================================ */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---------- Design Tokens & Themes ---------- */
:root {
    color-scheme: light;
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-input: #ffffff;
    --bg-subitems: #f8fafc;
    --bg-viewport: #e5e7eb;
    --border-color: #e5e7eb;
    --border-input: #d1d5db;
    --border-subitems: #e2e8f0;
    --text-main: #1a1a1a;
    --text-title: #111827;
    --text-label: #374151;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --btn-sec-bg: #ffffff;
    --btn-sec-text: #374151;
    --btn-sec-border: #d1d5db;
    --btn-sec-hover: #f9fafb;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg-main: #0b0f19;
    --bg-card: #151c2c;
    --bg-secondary: #1e293b;
    --bg-input: #0f172a;
    --bg-subitems: #0c1220;
    --bg-viewport: #07090e;
    --border-color: #27354f;
    --border-input: #334155;
    --border-subitems: #26334d;
    --text-main: #f1f5f9;
    --text-title: #f8fafc;
    --text-label: #cbd5e1;
    --text-secondary: #94a3b8;
    --text-muted: #8090a8;
    --btn-sec-bg: #1e293b;
    --btn-sec-text: #e2e8f0;
    --btn-sec-border: #3b4b66;
    --btn-sec-hover: #263348;
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    color-scheme: dark;
}

body {
    font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Meiryo", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- Header ---------- */
.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.header-inner {
    max-width: 1560px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.header-brand-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.return-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.return-link:hover {
    color: var(--text-title);
    border-color: var(--border-input);
    background: var(--bg-card);
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-title h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-title);
    line-height: 1.2;
}

.header-title .subtitle {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Style format selector */
.style-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.style-selector label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.style-selector select {
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    cursor: pointer;
}

/* Bilingual subtitle */
.sub-en {
    font-size: 0.88em;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 2px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 13px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 8px;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.btn small {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-icon {
    font-size: 13px;
}

.btn-primary {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.btn-print {
    background: #059669;
    color: #ffffff;
    border-color: #059669;
}

.btn-print:hover:not(:disabled) {
    background: #047857;
    border-color: #047857;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.35);
}

.btn-secondary {
    background: var(--btn-sec-bg);
    color: var(--btn-sec-text);
    border-color: var(--btn-sec-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--btn-sec-hover);
    border-color: var(--border-input);
}

.btn-theme {
    gap: 5px;
}

/* ---------- Main Layout ---------- */
.app-main {
    max-width: 1560px;
    margin: 0 auto;
    padding: 20px 24px;
    display: grid;
    grid-template-columns: 1fr 1.05fr;
    gap: 24px;
    align-items: start;
}

/* ---------- Form Column ---------- */
.form-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: var(--shadow-card);
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-title);
    padding-left: 10px;
    border-left: 4px solid #2563eb;
    margin-bottom: 16px;
    line-height: 1.4;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-label);
    margin-bottom: 4px;
}

.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.flex-1 {
    flex: 1;
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 7px 11px;
    font-size: 13.5px;
    font-family: inherit;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
    resize: vertical;
}

.input-short {
    max-width: 180px;
}

.helper-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Radio Pills */
.radio-pills {
    display: inline-flex;
    margin-top: 4px;
}

.radio-pills input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-pills .pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1.5px solid var(--border-input);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.radio-pills .pill:first-of-type {
    border-radius: 6px 0 0 6px;
}

.radio-pills .pill:last-of-type {
    border-radius: 0 6px 6px 0;
    border-left: none;
}

.radio-pills input[type="radio"]:checked + .pill {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

/* Photo Upload */
.photo-upload-area {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.photo-preview {
    width: 75px;
    height: 100px;
    border: 2px dashed var(--border-input);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-placeholder {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.photo-preview.has-photo {
    border-style: solid;
    border-color: var(--border-input);
}

.photo-controls {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.photo-controls input[type="file"] {
    font-size: 12.5px;
    border: none;
    padding: 0;
    color: var(--text-muted);
}

/* Collapsible Section */
.section-title-collapsible {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    list-style: none;
    border-left: 4px solid #2563eb;
    padding-left: 10px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-title);
}

.section-title-collapsible::-webkit-details-marker {
    display: none;
}

.collapse-indicator {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

details[open] .collapse-indicator {
    transform: rotate(180deg);
}

/* Dynamic Lists */
.dynamic-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dynamic-list-header {
    display: flex;
    gap: 8px;
    padding: 0 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: #6b7280;
}

.col-year { width: 80px; flex-shrink: 0; }
.col-month { width: 70px; flex-shrink: 0; }
.col-detail { flex: 1; }
.col-action { width: 28px; flex-shrink: 0; }

.dynamic-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dynamic-row .input-year { width: 80px; flex-shrink: 0; }
.dynamic-row .input-month { width: 70px; flex-shrink: 0; }
.dynamic-row .input-detail { flex: 1; }

.btn-remove {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid #fca5a5;
    background: #ffffff;
    color: #dc2626;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
}

.btn-remove:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

.btn-add-row {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: #2563eb;
    background: #ffffff;
    border: 1.5px dashed #bfdbfe;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-add-row:hover {
    background: #eff6ff;
    border-color: #2563eb;
}

/* Section Title Wrap & Badge */
.section-title-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.section-title-wrap .section-title {
    margin-bottom: 0;
}

.section-badge-hint {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    color: #4f46e5;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: 2px 10px;
}

/* Work History Groups & Sub-items */
.work-item-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
    border-radius: 8px;
}

.work-item-group .main-row {
    margin-bottom: 0;
}

.btn-add-subitem {
    padding: 6px 10px;
    font-size: 11.5px;
    font-weight: 600;
    color: #4f46e5;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    line-height: 1;
    flex-shrink: 0;
    font-family: inherit;
}

.btn-add-subitem:hover {
    background: #e0e7ff;
    border-color: #a5b4fc;
}

.btn-add-subitem.active {
    background: #4f46e5;
    color: #ffffff;
    border-color: #4f46e5;
}

.subitems-container {
    margin: 6px 0 6px 28px;
    padding: 10px 12px;
    background: var(--bg-subitems);
    border: 1px solid var(--border-subitems);
    border-left: 3px solid #6366f1;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.subitems-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #cbd5e1;
}

.subitems-title {
    font-size: 11px;
    font-weight: 700;
    color: #4338ca;
}

.subitems-quick-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.btn-quick-tag {
    font-size: 10.5px;
    padding: 2px 7px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-quick-tag:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

.btn-add-subitem-row {
    font-size: 11px;
    padding: 2px 8px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 4px;
    color: #4338ca;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-add-subitem-row:hover {
    background: #e0e7ff;
}

.subitems-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.subitem-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.subitem-bullet {
    font-size: 13px;
    color: #6366f1;
    font-weight: bold;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
}

.subitem-row .input-year-sub {
    width: 75px !important;
    flex-shrink: 0;
    font-size: 12px;
    padding: 5px 6px;
    border: 1px solid var(--border-input);
    border-radius: 5px;
    background: var(--bg-input);
    color: var(--text-main);
    font-family: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.subitem-row .input-month-sub {
    width: 65px !important;
    flex-shrink: 0;
    font-size: 12px;
    padding: 5px 6px;
    border: 1px solid var(--border-input);
    border-radius: 5px;
    background: var(--bg-input);
    color: var(--text-main);
    font-family: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.subitem-row .input-detail-sub {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    padding: 5px 8px;
    border: 1px solid var(--border-input);
    border-radius: 5px;
    background: var(--bg-input);
    color: var(--text-main);
    font-family: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.subitem-row .input-year-sub:focus,
.subitem-row .input-month-sub:focus,
.subitem-row .input-detail-sub:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.btn-remove-sub {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid #fca5a5;
    background: #ffffff;
    color: #ef4444;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    transition: all 0.15s ease;
}

.btn-remove-sub:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

/* Checkboxes */
.checkbox-row {
    flex-wrap: wrap;
}

.checkbox-label {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 500 !important;
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}

.checkbox-label input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: #2563eb;
    cursor: pointer;
}

.checkbox-status {
    font-size: 12px;
    color: #6b7280;
}

/* ============================================================
   Right Column: Preview Panel & A4 Sheet Canvas
   ============================================================ */
.preview-column {
    position: sticky;
    top: 70px;
}

.preview-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: var(--shadow-card);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.preview-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.preview-header-bar .section-title {
    margin-bottom: 0;
}

.preview-scale-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.preview-scale-controls button {
    background: var(--bg-secondary);
    border: 1px solid var(--border-input);
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-main);
    transition: all 0.15s ease;
}

.preview-viewport {
    width: 100%;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    overflow-x: auto;
    background: var(--bg-viewport);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    justify-content: center;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* Wrapper that handles CSS transform scale */
.a4-sheet-wrapper {
    transform-origin: top center;
    transition: transform 0.2s ease;
}

/* ============================================================
   The A4 Sheet (JIS Standard 210mm × 297mm)
   ============================================================ */
.a4-sheet {
    width: 210mm;
    min-height: 297mm;
    padding: 12mm 14mm;
    background: #ffffff;
    color: #111111;
    font-family: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "MS Mincho", serif;
    font-size: 10pt;
    line-height: 1.35;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Sub-labels */
.a4-sheet .en-sub {
    font-size: 7.5pt;
    font-family: system-ui, -apple-system, sans-serif;
    color: #4b5563;
    font-weight: normal;
}

/* Header */
.sheet-top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 4mm;
    padding-bottom: 1mm;
}

.sheet-title-wrap {
    flex: 1;
    text-align: center;
}

.sheet-main-title {
    font-size: 18pt;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: #111111;
}

.sheet-sub-title {
    display: block;
    font-size: 7.5pt;
    letter-spacing: 0.1em;
    font-family: system-ui, sans-serif;
    color: #4b5563;
    margin-top: -2px;
}

.sheet-date-line {
    font-size: 9pt;
    white-space: nowrap;
    text-align: right;
}

/* Profile Grid (Top section) */
.sheet-profile-table {
    display: flex;
    border: 1px solid #000000;
    margin-bottom: 0;
}

.sheet-profile-left {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sheet-photo-box {
    width: 30mm;
    min-height: 40mm;
    border-left: 1px solid #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fafafa;
    flex-shrink: 0;
}

.sheet-photo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sheet-photo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 8pt;
    color: #666666;
    padding: 4px;
}

.sheet-photo-placeholder .jp {
    font-size: 11pt;
    font-weight: 600;
    margin-bottom: 2px;
}

.sheet-photo-placeholder .en {
    font-size: 6.5pt;
    font-family: system-ui, sans-serif;
    margin-bottom: 3px;
}

.sheet-photo-placeholder .sub {
    font-size: 6.5pt;
}

/* Table rows & cells */
.sheet-row {
    display: flex;
    border-bottom: 1px solid #000000;
    min-height: 7mm;
}

.sheet-row:last-child {
    border-bottom: none;
}

.sheet-cell {
    padding: 2mm 2.5mm;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.cell-label {
    width: 22mm;
    border-right: 1px solid #000000;
    font-size: 8pt;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: 1.2;
    background: #ffffff;
    flex-shrink: 0;
}

.cell-label .jp {
    font-weight: 600;
}

.cell-label .en {
    font-size: 6pt;
    font-family: system-ui, sans-serif;
    color: #4b5563;
}

.cell-value {
    flex: 1;
    font-size: 9.5pt;
    word-break: break-all;
}

/* Name row */
.row-name {
    min-height: 24mm;
}

.value-name {
    font-size: 16pt;
    font-weight: 700;
    padding-left: 4mm;
}

/* Birth date & Gender */
.row-birth {
    min-height: 9mm;
}

.value-birth {
    flex: 1;
    font-size: 9pt;
}

.cell-gender {
    width: 26mm;
    border-left: 1px solid #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9pt;
    text-align: center;
}

/* Address Table */
.sheet-address-table {
    border: 1px solid #000000;
    border-top: none;
}

.row-addr {
    min-height: 15mm;
}

.value-address {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1mm;
}

.addr-postal {
    font-size: 9pt;
    font-weight: 600;
}

.addr-body {
    font-size: 9.5pt;
    line-height: 1.3;
}

.addr-note {
    font-size: 7.5pt;
    color: #666666;
}

.row-contact {
    min-height: 7.5mm;
}

.cell-email-label {
    width: 18mm;
    border-left: 1px solid #000000;
}

.cell-email-val {
    flex: 1;
}

.sheet-alt-contact {
    margin-top: 0;
}

/* History & Licenses Tables */
.sheet-history-table {
    border: 1px solid #000000;
    margin-top: 3.5mm;
}

.sheet-history-header {
    display: flex;
    background: #ffffff;
    border-bottom: 1px solid #000000;
    font-weight: 600;
    min-height: 6.8mm;
}

.col-yr {
    width: 18mm;
    border-right: 1px solid #000000;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 8pt;
    flex-shrink: 0;
    line-height: 1.2;
}

.col-mo {
    width: 12mm;
    border-right: 1px solid #000000;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 8pt;
    flex-shrink: 0;
    line-height: 1.2;
}

.col-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1.5mm 3mm;
    font-size: 9pt;
    line-height: 1.2;
}

.sheet-history-header .col-detail {
    text-align: center;
    align-items: center;
    font-size: 9pt;
}

.col-detail.text-center {
    align-items: center;
    text-align: center;
    font-weight: 600;
}

.col-detail.text-right {
    align-items: flex-end;
    text-align: right;
    padding-right: 6mm;
    font-weight: 600;
}

.col-yr .en, .col-mo .en, .col-detail .en {
    font-size: 6pt;
    font-family: system-ui, sans-serif;
    color: #4b5563;
    font-weight: normal;
}

.sheet-history-row {
    display: flex;
    border-bottom: 1px solid #000000;
    min-height: 6.6mm;
}

.sheet-history-row:last-child {
    border-bottom: none;
}

.row-category-header {
    background: #ffffff;
}

/* Sub-item Row on A4 Sheet (Haken / Dispatched Worker) */
.sheet-history-row.row-subitem {
    background: #ffffff;
}

.sheet-history-row.row-subitem .col-detail {
    padding-left: 6.5mm;
    font-size: 8.8pt;
}

.haken-indent {
    display: inline-block;
    width: 1.2em;
}

.sheet-history-row.row-subitem .col-yr,
.sheet-history-row.row-subitem .col-mo {
    font-size: 7.5pt;
    color: #222222;
}

/* Compact History Rules (Auto-activated when rows > 11 to keep within single A4 page) */
.sheet-compact-history .sheet-history-row {
    min-height: 5.4mm;
}

.sheet-compact-history .sheet-history-header {
    min-height: 5.6mm;
}

.sheet-compact-history .col-detail {
    padding: 0.7mm 3mm;
    font-size: 8.5pt;
}

.sheet-compact-history .sheet-history-row.row-subitem .col-detail {
    padding-left: 5.8mm;
    font-size: 8.2pt;
}

.sheet-compact-history .sheet-bottom-grid {
    min-height: 42mm;
}

/* Bottom Grid */
.sheet-bottom-grid {
    display: grid;
    grid-template-columns: 56% 44%;
    border: 1px solid #000000;
    margin-top: 3.5mm;
    flex: 1;
    min-height: 52mm;
}

.sheet-bottom-left {
    border-right: 1px solid #000000;
    display: flex;
    flex-direction: column;
}

.bottom-box-label {
    padding: 1.5mm 2.5mm;
    font-size: 7.5pt;
    font-weight: 600;
    border-bottom: 1px solid #eeeeee;
    line-height: 1.2;
}

.bottom-box-content {
    padding: 2.5mm 3mm;
    font-size: 8.5pt;
    line-height: 1.4;
    flex: 1;
}

.content-hobbies {
    margin-top: 3mm;
}

.sheet-bottom-right {
    display: flex;
    flex-direction: column;
}

.bottom-right-row {
    border-bottom: 1px solid #000000;
    display: flex;
    align-items: center;
    min-height: 8.5mm;
    padding: 1.5mm 2.5mm;
}

.bottom-right-row:last-child {
    border-bottom: none;
    flex: 1;
}

.row-commute .sub-label,
.row-dependents .sub-label {
    width: 44mm;
    font-size: 7.5pt;
    font-weight: 600;
    line-height: 1.2;
}

.row-commute .sub-val,
.row-dependents .sub-val {
    flex: 1;
    text-align: center;
    font-size: 8.5pt;
}

.row-spouse-split {
    padding: 0;
}

.half-box {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 1.5mm 2.5mm;
    min-height: 8.5mm;
}

.half-box:first-child {
    border-right: 1px solid #000000;
}

.half-box .sub-label {
    width: 22mm;
    font-size: 7.5pt;
    font-weight: 600;
    line-height: 1.2;
}

.half-box .sub-val {
    flex: 1;
    text-align: center;
    font-size: 8.5pt;
}

.row-requests {
    flex-direction: column;
    align-items: flex-start;
    padding: 2mm 2.5mm;
}

.row-requests .sub-label {
    font-size: 7.5pt;
    font-weight: 600;
    margin-bottom: 2mm;
    line-height: 1.2;
}

.sub-val-req {
    font-size: 8.5pt;
    line-height: 1.35;
    flex: 1;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    background: #ffffff;
    border-radius: 16px;
    padding: 32px 48px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast */
.toast-container {
    position: fixed;
    top: 75px;
    right: 24px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    animation: toastIn 0.3s ease forwards;
    max-width: 380px;
}

.toast-info { background: #eff6ff; color: #1e40af; border-left: 4px solid #2563eb; }
.toast-success { background: #ecfdf5; color: #065f46; border-left: 4px solid #059669; }
.toast-error { background: #fef2f2; color: #991b1b; border-left: 4px solid #dc2626; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   Dark Mode Component Overrides
   ============================================================ */
[data-theme="dark"] .btn-add-row {
    background: #151c2c;
    border-color: #2563eb;
    color: #60a5fa;
}

[data-theme="dark"] .btn-add-row:hover {
    background: #1c263c;
    border-color: #3b82f6;
}

[data-theme="dark"] .btn-add-subitem {
    background: #1e2442;
    border-color: #4338ca;
    color: #a5b4fc;
}

[data-theme="dark"] .btn-add-subitem:hover {
    background: #283159;
}

[data-theme="dark"] .btn-add-subitem.active {
    background: #4f46e5;
    color: #ffffff;
}

[data-theme="dark"] .section-badge-hint {
    background: #1e2442;
    border-color: #3730a3;
    color: #a5b4fc;
}

[data-theme="dark"] .subitems-title {
    color: #a5b4fc;
}

[data-theme="dark"] .subitems-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .btn-quick-tag {
    background: #151c2c;
    border-color: #334155;
    color: #cbd5e1;
}

[data-theme="dark"] .btn-quick-tag:hover {
    background: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
}

[data-theme="dark"] .btn-add-subitem-row {
    background: #1e2442;
    border-color: #3730a3;
    color: #a5b4fc;
}

[data-theme="dark"] .btn-add-subitem-row:hover {
    background: #283159;
}

[data-theme="dark"] .btn-remove {
    background: #1e293b;
    border-color: #7f1d1d;
    color: #f87171;
}

[data-theme="dark"] .btn-remove:hover {
    background: #2d1820;
    border-color: #dc2626;
}

[data-theme="dark"] .btn-remove-sub {
    background: #1e293b;
    border-color: #7f1d1d;
    color: #f87171;
}

[data-theme="dark"] .btn-remove-sub:hover {
    background: #2d1820;
    border-color: #dc2626;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(11, 15, 25, 0.85);
}

[data-theme="dark"] .loading-spinner {
    background: #151c2c;
    border: 1px solid #27354f;
    color: #f8fafc;
}

[data-theme="dark"] .spinner {
    border-color: #27354f;
    border-top-color: #38bdf8;
}

[data-theme="dark"] .toast {
    background: #1e293b;
    color: #f8fafc;
    border: 1px solid #334155;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .toast-info {
    border-left: 4px solid #38bdf8;
    background: #111c30;
    color: #bae6fd;
}

[data-theme="dark"] .toast-success {
    border-left: 4px solid #34d399;
    background: #0d241d;
    color: #a7f3d0;
}

[data-theme="dark"] .toast-error {
    border-left: 4px solid #f87171;
    background: #281519;
    color: #fecaca;
}

/* ============================================================
   Print Media Query (@media print)
   ============================================================ */
@page {
    size: A4 portrait;
    margin: 0;
}

@media print {
    body {
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .app-header,
    .form-column,
    .preview-header-bar,
    .toast-container,
    .loading-overlay {
        display: none !important;
    }

    .app-main {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
    }

    .preview-column {
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .preview-panel {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
    }

    .preview-viewport {
        border: none !important;
        padding: 0 !important;
        background: transparent !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .a4-sheet-wrapper {
        transform: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .a4-sheet {
        box-shadow: none !important;
        margin: 0 auto !important;
        page-break-after: avoid;
        page-break-inside: avoid;
    }
}

/* Responsive */
@media (max-width: 1180px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .preview-column {
        position: static;
    }
}
