/* SukiBilling CSS - Premium Theme and Print Stylesheet */

:root {
    --bg-dark-deep: #0a0a0c;
    --bg-dark-panel: #111115;
    --bg-dark-input: #1b1b22;
    --border-dark: rgba(255, 255, 255, 0.08);
    --border-focus: #00f2ff;
    
    --accent-cyan: #00f2ff;
    --accent-purple: #a855f7;
    --text-white: #ffffff;
    --text-gray: #a1a1aa;
    --text-muted: #71717a;
    
    --font-main: 'Inter', 'Noto Sans JP', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Theme colors for Invoice document */
    --theme-navy: #1e3a8a;
    --theme-navy-light: #eff6ff;
    --theme-emerald: #065f46;
    --theme-emerald-light: #ecfdf5;
    --theme-charcoal: #1f2937;
    --theme-charcoal-light: #f9fafb;
    --theme-violet: #6d28d9;
    --theme-violet-light: #f5f3ff;
}

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

body {
    background-color: var(--bg-dark-deep);
    color: var(--text-white);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
}

/* App Container Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar Editor Panel */
.editor-panel {
    width: 480px;
    background-color: var(--bg-dark-panel);
    border-right: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.panel-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-dark);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
}

.brand h1 {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, #fff 40%, var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 11px;
    color: var(--text-gray);
    margin-top: 4px;
}

.panel-sections {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.panel-sections::-webkit-scrollbar {
    width: 6px;
}
.panel-sections::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(0, 242, 255, 0.15);
    padding-bottom: 6px;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Form Styles */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

label {
    font-size: 11px;
    color: var(--text-gray);
    font-weight: 500;
}

input[type="text"],
input[type="date"],
select,
textarea {
    background-color: var(--bg-dark-input);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    color: var(--text-white);
    padding: 10px 12px;
    font-size: 13px;
    font-family: var(--font-main);
    transition: all 0.2s ease;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.15);
}

textarea {
    resize: vertical;
}

/* Line Item Blocks in Editor */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.item-editor-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.02);
    padding: 12px;
    border: 1px solid var(--border-dark);
    border-radius: 6px;
}

.item-editor-row-top {
    width: 100%;
}

.item-editor-row-bottom {
    display: grid;
    grid-template-columns: 80px 1fr 1fr 32px;
    gap: 8px;
    align-items: flex-end;
    width: 100%;
}

.input-sub-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sub-label {
    font-size: 9px;
    color: var(--text-gray);
    font-weight: 700;
}

.btn-delete-item {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    width: 32px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-delete-item:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-action-small {
    background: rgba(0, 242, 255, 0.1);
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.btn-action-small:hover {
    background: var(--accent-cyan);
    color: #000;
}

/* Footer of Sidebar */
.panel-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-cyan), #00b4d8);
    border: none;
    color: #000;
    font-weight: 700;
    font-size: 14px;
    padding: 14px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 242, 255, 0.2);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 242, 255, 0.3);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary-small {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-gray);
    padding: 6px 12px;
    font-size: 11px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-secondary-small:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.footer-extra-links {
    text-align: center;
    margin-top: 4px;
}

.back-link {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--text-gray);
}

/* Preview Main Panel */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-dark-deep);
    height: 100vh;
}

.preview-toolbar {
    height: 60px;
    background-color: rgba(17, 17, 21, 0.6);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    flex-shrink: 0;
}

.preview-status {
    font-size: 12px;
    color: var(--text-gray);
    display: flex;
    align-items: center;
    gap: 6px;
}

.paper-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* A4 Sheet Canvas Styling (Light mode for rendering document) */
.a4-sheet {
    background-color: #ffffff;
    color: #1f2937;
    width: 210mm;
    height: 297mm;
    padding: 20mm;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    position: relative;
    font-family: var(--font-main);
}

/* Document Header inside A4 Sheet */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12mm;
}

.invoice-title-block h1 {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: 0.1em;
    color: #111827;
}

.theme-accent-bar {
    height: 4px;
    width: 60px;
    margin-top: 8px;
}

.invoice-meta-block table {
    border-collapse: collapse;
}

.invoice-meta-block th {
    text-align: right;
    font-size: 11px;
    color: #6b7280;
    font-weight: 500;
    padding: 3px 8px;
}

.invoice-meta-block td {
    font-size: 12px;
    font-weight: 700;
    color: #111827;
    padding: 3px 0;
    font-family: var(--font-mono);
}

/* Invoice Parties (Client & Sender info) */
.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 10mm;
}

.party-client, .party-sender {
    display: flex;
    flex-direction: column;
}

.party-client .label, .party-sender .label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    margin-bottom: 6px;
}

.client-name {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 6px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 4px;
}

.sender-name {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 6px;
}

.client-details, .sender-details {
    font-size: 11px;
    color: #4b5563;
    line-height: 1.5;
}

/* Total Amount Banner */
.total-amount-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    margin-bottom: 10mm;
}

.total-label {
    font-size: 12px;
    font-weight: 700;
}

.total-value {
    font-size: 24px;
    font-weight: 900;
    font-family: var(--font-mono);
}

/* Invoice Table styling */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10mm;
}

.invoice-table th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #ffffff;
    padding: 10px 12px;
}

.invoice-table td {
    font-size: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    color: #374151;
}

.invoice-table tbody tr:last-child td {
    border-bottom: 2px solid #374151;
}

/* Document Summary Section */
.invoice-summary-block {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 30px;
    margin-top: auto; /* Push summary to bottom if height allows */
}

.bank-info, .notes-block {
    margin-bottom: 6mm;
}

.label-small {
    font-size: 10px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.bank-info div:nth-child(2),
.notes-block div:nth-child(2) {
    font-size: 11px;
    color: #4b5563;
    line-height: 1.5;
}

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

.summary-table th, .summary-table td {
    padding: 6px 8px;
    font-size: 12px;
}

.summary-table th {
    text-align: right;
    font-weight: 500;
    color: #6b7280;
}

.summary-table td {
    text-align: right;
    font-weight: 700;
    color: #111827;
    font-family: var(--font-mono);
}

.summary-table tr.grand-total th {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
}

.summary-table tr.grand-total td {
    font-size: 18px;
    font-weight: 900;
}

/* カラーテーマごとのスタイル適用 */

/* 1. Classic Navy */
.theme-navy .theme-accent-bar {
    background-color: var(--theme-navy);
}
.theme-navy .total-amount-banner {
    background-color: var(--theme-navy-light);
    border-left: 4px solid var(--theme-navy);
    color: var(--theme-navy);
}
.theme-navy .invoice-table th {
    background-color: var(--theme-navy);
}
.theme-navy .summary-table tr.grand-total td {
    color: var(--theme-navy);
}

/* 2. Forest Emerald */
.theme-emerald .theme-accent-bar {
    background-color: var(--theme-emerald);
}
.theme-emerald .total-amount-banner {
    background-color: var(--theme-emerald-light);
    border-left: 4px solid var(--theme-emerald);
    color: var(--theme-emerald);
}
.theme-emerald .invoice-table th {
    background-color: var(--theme-emerald);
}
.theme-emerald .summary-table tr.grand-total td {
    color: var(--theme-emerald);
}

/* 3. Smart Charcoal */
.theme-charcoal .theme-accent-bar {
    background-color: var(--theme-charcoal);
}
.theme-charcoal .total-amount-banner {
    background-color: var(--theme-charcoal-light);
    border-left: 4px solid var(--theme-charcoal);
    color: var(--theme-charcoal);
}
.theme-charcoal .invoice-table th {
    background-color: var(--theme-charcoal);
}
.theme-charcoal .summary-table tr.grand-total td {
    color: var(--theme-charcoal);
}

/* 4. Elegant Violet */
.theme-violet .theme-accent-bar {
    background-color: var(--theme-violet);
}
.theme-violet .total-amount-banner {
    background-color: var(--theme-violet-light);
    border-left: 4px solid var(--theme-violet);
    color: var(--theme-violet);
}
.theme-violet .invoice-table th {
    background-color: var(--theme-violet);
}
.theme-violet .summary-table tr.grand-total td {
    color: var(--theme-violet);
}

/* ==========================================
   PRINT STYLESHEET (PDF & Printing Mode)
   ========================================== */
@media print {
    /* Hide editor controls and status indicators */
    .editor-panel,
    .preview-toolbar,
    aside,
    footer,
    button {
        display: none !important;
    }

    body, html {
        background-color: #ffffff !important;
        color: #000000 !important;
        height: auto !important;
        overflow: visible !important;
    }

    .app-container {
        display: block !important;
        height: auto !important;
    }

    .preview-panel {
        background-color: #ffffff !important;
        height: auto !important;
        display: block !important;
    }

    .paper-container {
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
        overflow: visible !important;
    }

    .a4-sheet {
        box-shadow: none !important;
        padding: 0 !important;
        width: 100% !important;
        min-height: 0 !important;
        margin: 0 !important;
        border: none !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Keep CSS background colors visible in PDF */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    @page {
        size: A4;
        margin: 15mm 15mm 15mm 15mm;
    }
}

/* Saved History Styles */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-dark);
    padding: 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.2);
}

.history-list::-webkit-scrollbar {
    width: 4px;
}
.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    gap: 8px;
}

.history-item-info {
    flex: 1;
    min-width: 0;
}

.history-item-title {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 9px;
    color: var(--text-gray);
    margin-top: 2px;
}

.history-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-history-load {
    background: rgba(0, 242, 255, 0.1);
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 700;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-history-load:hover {
    background: var(--accent-cyan);
    color: #000;
}

.btn-history-delete {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    transition: background 0.2s;
}

.btn-history-delete:hover {
    background: rgba(239, 68, 68, 0.15);
}

.empty-history {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    padding: 12px 0;
}

