/* ================================================================
   見積書・請求書 PDF作成ツール
   Prefix: inv- (Invoice)
   ================================================================ */

:root {
    --inv-primary: #1565c0;
    --inv-primary-l: #42a5f5;
    --inv-accent: #2e7d32;
    --inv-bg: #f0f4f8;
    --inv-card: #ffffff;
    --inv-text: #333333;
    --inv-muted: #757575;
    --inv-border: #e0e0e0;
    --inv-danger: #d32f2f;
    --inv-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}

/* ----------------------------------------------------------------
   Single-column layout (input → preview below)
   ---------------------------------------------------------------- */
.inv-container {
    max-width: 840px;
    margin: 0 auto;
}

/* ----------------------------------------------------------------
   Panels
   ---------------------------------------------------------------- */
.inv-panel {
    background: var(--inv-card);
    border: 1px solid var(--inv-border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--inv-shadow);
    margin-bottom: 20px;
}

.inv-panel h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--inv-primary);
    margin: 0 0 16px;
}

.inv-panel h3 .material-icons {
    font-size: 22px;
}

/* ----------------------------------------------------------------
   Form elements
   ---------------------------------------------------------------- */
.inv-form-section {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #f0f0f0;
}

.inv-form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.inv-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--inv-primary);
    margin: 0 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.inv-section-title .material-icons {
    font-size: 18px;
}

.inv-form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
    align-items: flex-start;
}

.inv-form-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.inv-form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--inv-muted);
}

.inv-form-group input,
.inv-form-group select,
.inv-form-group textarea {
    padding: 8px 10px;
    border: 1px solid var(--inv-border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--inv-text);
    background: #fafafa;
    box-sizing: border-box;
    width: 100%;
}

.inv-form-group input:focus,
.inv-form-group select:focus,
.inv-form-group textarea:focus {
    outline: none;
    border-color: var(--inv-primary);
    box-shadow: 0 0 0 2px rgba(21, 101, 192, .1);
}

.inv-form-group input[type="file"] {
    padding: 5px;
    font-size: 12px;
}

/* Doc type selector */
.inv-doc-type-wrap {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.inv-doc-type-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--inv-border);
    border-radius: 8px;
    background: var(--inv-card);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    transition: all .15s;
    color: var(--inv-muted);
}

.inv-doc-type-btn:hover {
    border-color: var(--inv-primary-l);
    color: var(--inv-primary);
}

.inv-doc-type-btn.active {
    border-color: var(--inv-primary);
    background: #e3f2fd;
    color: var(--inv-primary);
}

/* ----------------------------------------------------------------
   Detail rows
   ---------------------------------------------------------------- */
.inv-detail-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.inv-detail-row input {
    padding: 7px 8px;
    border: 1px solid var(--inv-border);
    border-radius: 5px;
    font-size: 12px;
    font-family: inherit;
    box-sizing: border-box;
    background: #fafafa;
}

.inv-detail-row input:focus {
    outline: none;
    border-color: var(--inv-primary);
}

.inv-detail-name {
    flex: 1;
}

.inv-detail-qty {
    width: 55px;
    text-align: right;
}

.inv-detail-unit {
    width: 45px;
    text-align: center;
}

.inv-detail-price {
    width: 90px;
    text-align: right;
}

.inv-detail-amount {
    width: 90px;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--inv-text);
    padding: 7px 4px;
    white-space: nowrap;
}

.inv-detail-del {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #ffebee;
    color: var(--inv-danger);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
    flex-shrink: 0;
}

.inv-detail-del:hover {
    background: #ffcdd2;
}

.inv-btn-add-row {
    padding: 6px 14px;
    border: 1px dashed var(--inv-primary-l);
    border-radius: 6px;
    background: transparent;
    color: var(--inv-primary);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-top: 4px;
    transition: background .12s;
}

.inv-btn-add-row:hover {
    background: #e3f2fd;
}

/* Tax radios */
.inv-tax-radios {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.inv-tax-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
}

.inv-tax-label input {
    accent-color: var(--inv-primary);
}

/* Totals */
.inv-totals {
    text-align: right;
    font-size: 13px;
    line-height: 2;
    color: var(--inv-text);
}

.inv-totals .inv-total-grand {
    font-size: 16px;
    font-weight: 700;
    color: var(--inv-accent);
}

/* ----------------------------------------------------------------
   Preview panel (inline, scaled to fit container)
   ---------------------------------------------------------------- */
.inv-preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.inv-btn-download,
.inv-btn-lightbox {
    padding: 10px 22px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity .15s;
}

.inv-btn-download {
    background: linear-gradient(135deg, var(--inv-primary), var(--inv-primary-l));
    color: #fff;
    box-shadow: 0 2px 8px rgba(21, 101, 192, .3);
}

.inv-btn-lightbox {
    background: #37474f;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}

.inv-btn-download:hover,
.inv-btn-lightbox:hover {
    opacity: .85;
}

.inv-btn-download:disabled {
    opacity: .5;
    cursor: default;
}

.inv-preview-box {
    background: #e8edf2;
    border-radius: 8px;
    padding: 16px;
    overflow: hidden;
}

.inv-scale-container {
    position: relative;
    overflow: hidden;
    margin: 0 auto;
}

/* ----------------------------------------------------------------
   A4 Document (fixed 794×1123 px)
   ---------------------------------------------------------------- */
.inv-a4-document {
    width: 794px;
    height: 1123px;
    background: #fff;
    box-shadow: 0 2px 20px rgba(0, 0, 0, .12);
    padding: 50px 55px;
    box-sizing: border-box;
    font-family: 'Noto Sans JP', sans-serif;
    color: #222;
    font-size: 12px;
    line-height: 1.6;
    transform-origin: top left;
    position: relative;
}

/* Document header */
.inv-doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.inv-doc-logo {
    max-width: 160px;
    max-height: 60px;
    object-fit: contain;
    display: none;
}

.inv-doc-issuer {
    text-align: right;
    font-size: 11px;
    line-height: 1.7;
    position: relative;
}

.inv-doc-issuer-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 2px;
}

.inv-doc-stamp {
    position: absolute;
    bottom: -10px;
    right: -5px;
    width: 70px;
    height: 70px;
    object-fit: contain;
    opacity: .85;
    display: none;
}

/* Title */
.inv-doc-title {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5em;
    margin: 10px 0 6px;
    padding-bottom: 6px;
    border-bottom: 2px solid #333;
}

/* Meta row */
.inv-doc-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
    font-size: 11px;
}

/* Recipient */
.inv-doc-to {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

.inv-doc-to-name {
    font-size: 16px;
    font-weight: 700;
    border-bottom: 2px solid #333;
    display: inline-block;
    padding-bottom: 2px;
    margin-bottom: 4px;
}

.inv-doc-to-detail {
    font-size: 11px;
    color: #555;
}

/* Greeting line */
.inv-doc-greeting {
    font-size: 11px;
    margin-bottom: 8px;
}

/* Grand total bar */
.inv-doc-grand-total {
    border: 2px solid #333;
    background: #f8f8f8;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 14px;
}

/* Detail table */
.inv-doc-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 11px;
}

.inv-doc-table thead th {
    background: #333;
    color: #fff;
    padding: 6px 8px;
    font-weight: 600;
    text-align: center;
    font-size: 10px;
}

.inv-doc-table thead th:first-child {
    text-align: left;
}

.inv-doc-table tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.inv-doc-table tbody td:nth-child(2),
.inv-doc-table tbody td:nth-child(3) {
    text-align: center;
}

.inv-doc-table tbody td:nth-child(4),
.inv-doc-table tbody td:nth-child(5) {
    text-align: right;
}

/* Subtotals */
.inv-doc-subtotals {
    text-align: right;
    font-size: 11px;
    line-height: 2;
    margin-bottom: 14px;
}

.inv-doc-subtotals strong {
    font-size: 13px;
}

/* Notes */
.inv-doc-notes {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 10px;
    line-height: 1.7;
    min-height: 60px;
    white-space: pre-wrap;
    color: #444;
}

.inv-doc-notes-label {
    font-size: 10px;
    font-weight: 700;
    color: #666;
    margin-bottom: 4px;
}

/* Helper */
.inv-helper-text {
    margin-top: 10px;
    color: #888;
    font-size: 0.8rem;
    text-align: center;
}

/* ----------------------------------------------------------------
   Lightbox overlay
   ---------------------------------------------------------------- */
.inv-lightbox-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, .7);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 40px 20px;
}

.inv-lightbox-overlay.open {
    display: flex;
}

.inv-lightbox-inner {
    position: relative;
    background: transparent;
    max-width: 794px;
    width: 100%;
}

.inv-lightbox-close {
    position: fixed;
    top: 16px;
    right: 24px;
    z-index: 100000;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .9);
    color: #333;
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .2);
    transition: background .15s;
}

.inv-lightbox-close:hover {
    background: #fff;
}

.inv-lightbox-inner .inv-a4-document {
    box-shadow: 0 4px 40px rgba(0, 0, 0, .3);
}

/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */
@media (max-width: 640px) {
    .inv-detail-row {
        flex-wrap: wrap;
    }

    .inv-detail-name {
        width: 100%;
        flex: none;
    }

    .inv-preview-actions {
        flex-direction: column;
    }
}