@charset "UTF-8";

/* ==========================================================================
   Base Styles & Reset
   ========================================================================== */
:root {
    --text-color: #000000;
    --table-header-bg: #EFEFEF;
    --border-color: #000000;
    --logo-orange: #F37021;
    --hanko-red: #D32F2F;
    --page-width: 210mm;
    --page-height: 297mm;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #f0f0f0;
    color: var(--text-color);
    font-family: 'Noto Sans JP', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    font-size: 11pt;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   UI Controls (Screen Only)
   ========================================================================== */
.app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.controls {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.controls h2 {
    font-size: 1.1rem;
    margin: 0;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s, opacity 0.2s;
}

.control-buttons {
    display: flex;
    gap: 10px;
}

.secondary-btn {
    background-color: #10b981;
    color: white;
}

.secondary-btn:hover {
    background-color: #059669;
}

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

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

.help-text {
    font-size: 0.85rem;
    color: #666;
    margin: 0;
}

[contenteditable="true"] {
    outline: none;
    transition: background-color 0.2s;
}

[contenteditable="true"]:hover, [contenteditable="true"]:focus {
    background-color: rgba(37, 99, 235, 0.05);
}

/* ==========================================================================
   A4 Page Layout (Invoice Design)
   ========================================================================== */
.invoice-container {
    width: var(--page-width);
    min-height: var(--page-height);
    margin: 0 auto 50px auto;
    background-color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    padding: 25mm 20mm; /* A4 margins */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.invoice-title {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.8em;
    margin-bottom: 30px;
    padding-left: 0.8em; /* Offset for center alignment with letter-spacing */
}

.header-top-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

/* Client */
.client-section {
    width: 50%;
    margin-top: 10px;
}

.client-name {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 5px;
    padding-bottom: 2px;
    white-space: nowrap;
}

.client-name .honorific {
    font-size: 1.15rem;
}

.client-underline {
    border-bottom: 1px solid var(--border-color);
    width: 100%;
}

/* Meta info (Right) */
.meta-section {
    width: 40%;
}

.meta-table {
    width: 100%;
    border-collapse: collapse;
}

.meta-table th, .meta-table td {
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: 0.95rem;
}

.meta-table th {
    background-color: var(--table-header-bg);
    text-align: left;
    white-space: nowrap;
    width: 40%;
    font-weight: normal;
}

.meta-table td {
    text-align: center;
}

/* --------------------------------------------------------------------------
   Header Bottom Grid
   -------------------------------------------------------------------------- */
.header-bottom-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 30px;
}

/* Amount Box */
.amount-section {
    width: 45%;
}

.amount-box {
    display: flex;
    border: 2px solid var(--border-color); /* 太枠 */
    align-items: stretch;
}

.amount-label {
    background-color: var(--table-header-bg);
    padding: 10px 15px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
}

.amount-value {
    padding: 10px 20px;
    font-size: 1.5rem;
    font-weight: 700;
    flex-grow: 1;
    text-align: center;
}

/* Biller Info */
.biller-section {
    width: auto;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    white-space: nowrap;
}

.biller-logo {
    margin-bottom: 5px;
}

.biller-logo img {
    height: 40px;
    width: auto;
    display: block;
}

.biller-company {
    font-weight: bold;
    margin-bottom: 5px;
}

.biller-name-wrapper {
    position: relative;
    margin-bottom: 5px;
}

.biller-name {
    display: inline-block;
}

/* 判子（画像による再現） */
.hankou-img {
    position: absolute;
    top: -5px;
    left: 0; /* 氏名の上に配置 */
    width: 55px;
    height: auto;
    opacity: 0.9;
    mix-blend-mode: multiply; /* 背景透過と自然な重なりのため */
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Items Table
   -------------------------------------------------------------------------- */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
}

.items-table th, .items-table td {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
}

.items-table th {
    background-color: var(--table-header-bg);
    font-weight: normal;
    text-align: center;
}

.items-table td {
    height: 32px; /* 空行の高さを確保 */
}

.items-table .col-desc { width: 55%; text-align: left; }
.items-table .col-qty { width: 10%; text-align: center; }
.items-table .col-price { width: 17.5%; text-align: right; }
.items-table .col-amount { width: 17.5%; text-align: right; }

/* --------------------------------------------------------------------------
   Totals
   -------------------------------------------------------------------------- */
.totals-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 40px;
}

.totals-table {
    width: auto;
    min-width: 35%;
    border-collapse: collapse;
}

.totals-table th, .totals-table td {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
}

.totals-table th {
    background-color: var(--table-header-bg);
    font-weight: normal;
    text-align: center;
    width: 60%;
    white-space: nowrap;
}

.totals-table td {
    text-align: right;
    width: 50%;
}

/* --------------------------------------------------------------------------
   Footer / Notes
   -------------------------------------------------------------------------- */
.invoice-footer {
    margin-top: auto;
}

.footer-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 15px;
}

.payment-info {
    width: 50%;
}

.footer-heading {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.payment-details {
    font-size: 0.95rem;
    white-space: pre-wrap;
    line-height: 1.6;
}

.payment-notes {
    font-size: 0.9rem;
    text-align: right;
}

/* Remarks Box */
.remarks-section {
    margin-top: 10px;
}

.remarks-label {
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.remarks-box {
    width: 100%;
    height: 120px;
    border: 1px solid var(--border-color);
    padding: 10px;
}

/* ==========================================================================
   Password Overlay
   ========================================================================== */
.password-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85); /* ダークな背景 */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.password-modal {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.password-modal h2 {
    margin-bottom: 10px;
    color: #333;
}

.password-modal p {
    margin-bottom: 20px;
    color: #666;
    font-size: 0.95rem;
}

#password-input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

#password-submit {
    width: 100%;
    margin-top: 10px;
}

.password-error {
    color: #dc2626 !important;
    font-size: 0.85rem !important;
    margin-bottom: 10px !important;
    font-weight: bold;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    body {
        background-color: transparent;
        margin: 0;
    }

    .app-container, .no-print {
        display: none !important;
    }

    .invoice-container {
        box-shadow: none;
        margin: 0;
        padding: 10mm 15mm 25mm 15mm; /* 上側の余白を減らし、下側に余裕を持たせる */
        width: 210mm;
        height: 296mm; /* Exactly A4 height minus 1mm to avoid blank 2nd page */
        box-sizing: border-box;
        overflow: hidden; /* Prevent spilling to second page */
        page-break-after: avoid;
        page-break-inside: avoid;
    }
    
    /* Compress paddings and margins to allow content to fit within A4 */
    .items-table th, .items-table td {
        padding: 3px 8px; /* さらに少しだけ行間を詰める */
    }
    
    .invoice-header {
        margin-bottom: 10px;
    }
    
    .totals-section {
        margin-bottom: 5px;
    }
    
    .remarks-box {
        height: 75px; 
    }

    [contenteditable="true"]:hover {
        background-color: transparent;
    }
}
