﻿/* =========================================
   CSS Variables (テーマカラーと設定)
   ========================================= */
:root {
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;
    
    --blue-50: #eff6ff;
    --blue-200: #bfdbfe;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-800: #1e40af;
    
    --red-50: #fef2f2;
    --red-100: #fee2e2;
    --red-200: #fecaca;
    --red-400: #f87171;
    --red-500: #ef4444;
    --red-600: #dc2626;
    
    --green-400: #4ade80;

    --font-main: 'Noto Sans JP', "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Meiryo", sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--slate-50);
    color: var(--slate-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

input, textarea, button {
    font-family: inherit;
    font-size: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

a, button {
    transition: all 0.2s ease-in-out;
}

svg {
    display: inline-block;
    vertical-align: middle;
}

/* =========================================
   Layout & Components
   ========================================= */
.app-wrapper {
    padding: 1rem;
}

.container {
    max-width: 64rem;
    margin: 0 auto;
}

/* Header */
.app-header {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.logo-title {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    color: var(--slate-800);
}

.logo-title svg {
    width: 2rem;
    height: 2rem;
    margin-right: 0.5rem;
    color: var(--blue-600);
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.btn svg {
    width: 1rem;
    height: 1rem;
    margin-right: 0.25rem;
}

.btn-outline {
    background-color: #fff;
    border: 1px solid var(--slate-300);
    color: var(--slate-700);
}

.btn-outline:hover {
    background-color: var(--slate-50);
}

.btn-primary {
    background-color: var(--blue-600);
    color: #fff;
    border: 1px solid transparent;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-primary:hover {
    background-color: var(--blue-700);
}

.btn-danger-outline {
    background-color: var(--red-50);
    border: 1px solid var(--red-200);
    color: var(--red-600);
}

.btn-danger-outline:hover {
    background-color: var(--red-100);
}

.btn-text-blue {
    color: var(--blue-600);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    margin-bottom: 2.5rem;
}

.btn-text-blue:hover {
    color: var(--blue-700);
}

.btn-text-blue svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.25rem;
}

.btn-icon-danger {
    color: var(--slate-300);
}

.btn-icon-danger:hover {
    color: var(--red-500);
}

/* Main Paper */
.invoice-paper {
    background-color: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
                0 4px 6px -2px rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
}

/* Info Section */
.info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--slate-200);
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--slate-500);
    margin-bottom: 0.25rem;
}

.label-sm {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--slate-400);
    margin-bottom: 0;
}

.required {
    color: var(--red-500);
}

.input-underline {
    width: 100%;
    border: none;
    border-bottom: 1px solid transparent;
    padding: 0.25rem 0.25rem;
    outline: none;
    border-radius: 0.125rem;
    transition: border-color 0.2s;
}

.input-underline:focus {
    border-bottom-color: var(--blue-500);
}

.input-underline.with-border {
    border-bottom-color: var(--slate-200);
}

.input-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--slate-800);
}

.input-small {
    font-size: 0.75rem;
    color: var(--slate-500);
    font-weight: 500;
}

.input-medium {
    font-weight: 500;
}

.input-bold {
    font-weight: 700;
    color: var(--slate-800);
}

.input-meta {
    font-size: 0.875rem;
    color: var(--slate-500);
}

.input-right-align {
    text-align: left;
}

.company-fields {
    gap: 0.25rem;
}

/* Error state */
.error {
    box-shadow: 0 0 0 2px var(--red-400) !important;
    background-color: var(--red-50) !important;
    border-radius: 0.25rem;
}

/* Items Table */
.table-responsive {
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.items-table th {
    text-align: left;
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--slate-600);
    border-bottom: 2px solid var(--slate-100);
}

.items-table th.col-price {
    width: 8rem;
}

.items-table th.col-qty {
    width: 6rem;
}

.items-table th.col-subtotal {
    width: 8rem;
    text-align: right;
}

.items-table th.col-action {
    width: 3rem;
}

.item-row {
    border-bottom: 1px solid var(--slate-50);
    transition: background-color 0.2s;
}

.item-row:hover {
    background-color: var(--slate-50);
}

.item-cell {
    padding: 1rem 0.5rem;
}

.item-input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    outline: none;
    color: var(--slate-700);
    padding: 0.25rem 0.5rem;
    border-radius: 0.125rem;
    transition: box-shadow 0.2s;
}

.item-input:focus {
    box-shadow: 0 0 0 1px var(--blue-500);
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.row-subtotal {
    font-weight: 500;
    color: var(--slate-700);
}

/* Notes & Totals */
.notes-totals-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: flex-start;
}

.notes-area {
    width: 100%;
}

.textarea-box {
    width: 100%;
    border: 1px solid var(--slate-200);
    border-radius: 0.375rem;
    padding: 0.75rem;
    outline: none;
    color: var(--slate-800);
    line-height: 1.5;
    transition: border-color 0.2s;
    resize: vertical;
}

.textarea-box:focus {
    border-color: var(--blue-500);
}

.totals-area {
    width: 100%;
}

.total-row {
    display: flex;
    justify-content: space-between;
    color: var(--slate-600);
    margin-bottom: 0.75rem;
}

.total-row.grand-total {
    padding-top: 0.75rem;
    border-top: 2px solid var(--slate-100);
    align-items: center;
}

.grand-total-label {
    font-weight: 700;
    color: var(--slate-800);
}

.grand-total-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--blue-600);
}

/* Bank Info & Footer */
.bank-section {
    margin-top: 2.5rem;
}

.bank-textarea {
    width: 100%;
}

.footer-notes {
    margin-top: 4rem;
    font-size: 0.75rem;
    color: var(--slate-400);
}

.app-footer {
    margin-top: 2rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--slate-400);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 56rem;
    max-height: 85vh;
    margin: 1rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--slate-100);
    background-color: var(--slate-50);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--slate-800);
    display: flex;
    align-items: center;
}

.modal-title svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    color: var(--blue-600);
}

.modal-close {
    color: var(--slate-400);
    padding: 0.25rem;
    border-radius: 0.375rem;
}

.modal-close:hover {
    color: var(--slate-600);
    background-color: var(--slate-200);
}

.modal-body {
    padding: 0;
    overflow-y: auto;
    flex: 1;
    background-color: #fff;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.history-table th {
    position: sticky;
    top: 0;
    background-color: #fff;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--slate-200);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.history-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--slate-100);
    font-size: 0.875rem;
}

.history-row:hover {
    background-color: var(--slate-50);
}

.history-empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 0;
    color: var(--slate-500);
}

.history-empty.show {
    display: flex;
}

.history-empty svg {
    width: 3rem;
    height: 3rem;
    color: var(--slate-300);
    margin-bottom: 0.75rem;
}

.action-btns {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.btn-sm-action {
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.btn-sm-load {
    color: var(--blue-600);
}

.btn-sm-load:hover {
    color: var(--blue-800);
    background-color: var(--blue-50);
    border-color: var(--blue-200);
}

.btn-sm-delete {
    color: var(--red-500);
}

.btn-sm-delete:hover {
    color: var(--red-700);
    background-color: var(--red-50);
    border-color: var(--red-200);
}

.history-action-col {
    width: 8rem;
}

/* Hide scrollbar */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background-color: var(--slate-800);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 50;
    display: flex;
    align-items: center;
    transform: translateY(5rem);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.toast svg {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--green-400);
    margin-right: 0.5rem;
}

.toast span {
    font-weight: 500;
    font-size: 0.875rem;
}

/* Responsive */
@media (min-width: 768px) {
    .app-wrapper {
        padding: 2rem;
    }

    .invoice-paper {
        padding: 2.5rem;
    }
    
    .app-header {
        flex-direction: row;
    }

    .header-actions {
        margin-top: 0;
        justify-content: flex-end;
    }
    
    .info-grid {
        grid-template-columns: 1fr 1fr;
    }

    .input-right-align {
        text-align: right;
    }

    .info-right-group {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }

    .input-w-md {
        width: 12rem;
    }

    .input-w-lg {
        width: 16rem;
    }

    .notes-totals-section {
        flex-direction: row;
        justify-content: space-between;
    }

    .notes-area {
        width: 50%;
    }

    .totals-area {
        width: 16rem;
        flex-shrink: 0;
        margin-left: auto;
    }

    .bank-textarea {
        width: 50%;
    }
}

/* Print */
@media print {
    @page {
        size: A4;
        margin: 15mm;
    }

    body {
        background-color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

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

    .app-wrapper {
        padding: 0 !important;
    }

    .invoice-paper {
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }

    .input-underline {
        border-color: transparent !important;
    }

    .textarea-box {
        border: none !important;
        padding: 0 !important;
        resize: none !important;
    }

    tr, .avoid-page-break {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .info-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
    }

    .input-right-align {
        text-align: right !important;
    }

    .info-right-group {
        align-items: flex-end !important;
    }

    .input-w-md {
        width: 12rem !important;
    }

    .input-w-lg {
        width: 16rem !important;
    }

    .notes-totals-section {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
    }

    .notes-area {
        width: 50% !important;
    }

    .totals-area {
        width: 16rem !important;
        margin-left: auto !important;
    }
}