/**
 * RAZ Invoice Studio - CSS
 * Mobile-friendly with fixed scrolling and print
 */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    --color-bg: #0a0a0a;
    --color-card: #141414;
    --color-input: #1a1a1a;
    --color-gold: #d4a853;
    --color-border: #27272a;
    --color-text: #ffffff;
    --color-muted: #a1a1aa;
    --color-success: #22c55e;
    --color-error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
.header {
    text-align: center;
    padding: 1rem;
    background: linear-gradient(180deg, var(--color-card), var(--color-bg));
    border-bottom: 1px solid var(--color-border);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-gold);
    text-decoration: none;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.header h1 {
    font-size: 1.5rem;
    color: var(--color-gold);
    margin-bottom: 0.25rem;
}

.header p {
    color: var(--color-muted);
    font-size: 0.8rem;
}

/* Layout */
.main-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        order: 2;
    }

    .preview-panel {
        order: 1;
    }
}

/* Panel */
.panel {
    background: var(--color-card);
    border-radius: 0.5rem;
    border: 1px solid var(--color-border);
    overflow: hidden;
}

.panel-header {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
    font-weight: 600;
}

.panel-body {
    padding: 0.75rem;
}

/* Sidebar scroll fix */
.sidebar .panel-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

@media (max-width: 900px) {
    .sidebar .panel-body {
        max-height: 60vh;
    }
}

/* Controls */
.control-group {
    margin-bottom: 0.6rem;
}

.control-group label {
    display: block;
    font-size: 0.7rem;
    color: var(--color-muted);
    margin-bottom: 0.2rem;
    font-weight: 500;
}

.control-group .hint {
    font-size: 0.6rem;
    color: #666;
    margin-top: 0.3rem;
}

.select-input,
.text-input {
    width: 100%;
    padding: 0.45rem 0.5rem;
    background: var(--color-input);
    border: 1px solid var(--color-border);
    border-radius: 0.35rem;
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.75rem;
}

.select-input:focus,
.text-input:focus {
    outline: none;
    border-color: var(--color-gold);
}

/* Custom size row */
.custom-size-row {
    display: none;
    gap: 0.4rem;
    margin-top: 0.4rem;
    align-items: center;
}

.custom-size-row input {
    flex: 1;
    padding: 0.4rem;
}

.custom-size-row span {
    color: var(--color-muted);
    font-size: 0.7rem;
}

/* Buttons */
.btn {
    padding: 0.45rem 0.6rem;
    border: none;
    border-radius: 0.35rem;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-gold), #b8923f);
    color: #000;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(212, 168, 83, 0.3);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-secondary {
    background: var(--color-input);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-group {
    display: flex;
    gap: 0.35rem;
}

.btn-group .btn {
    flex: 1;
}

/* Logo Upload */
.logo-upload-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.logo-preview-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-input);
    padding: 0.4rem;
    border-radius: 0.35rem;
    margin-top: 0.3rem;
}

.logo-preview-wrap img {
    max-height: 40px;
    max-width: 80px;
    object-fit: contain;
    border-radius: 0.25rem;
}

.logo-remove-btn {
    background: var(--color-error);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

.logo-remove-btn:hover {
    background: #dc2626;
}

/* Invoice Preview */
.invoice-preview {
    background: white;
    color: #333;
    border-radius: 0.5rem;
    overflow: auto;
    margin: 0 auto;
}

.invoice-content {
    padding: 25px;
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
}

/* Company Logo in Invoice */
.company-logo {
    max-height: 60px;
    max-width: 150px;
    object-fit: contain;
    margin-bottom: 8px;
    display: block;
}

/* Invoice Header */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 15px;
}

.company-info h1 {
    font-size: 1.3em;
    color: #333;
    margin-bottom: 3px;
}

.company-info p {
    font-size: 0.8em;
    color: #666;
    margin: 1px 0;
}

.invoice-info {
    text-align: right;
}

.invoice-info h2 {
    font-size: 1.5em;
    margin-bottom: 8px;
}

.invoice-info p {
    font-size: 0.8em;
    color: #666;
    margin: 3px 0;
}

/* Date picker */
.date-pick {
    width: 18px;
    height: 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    opacity: 0.3;
    vertical-align: middle;
}

.date-pick:hover {
    opacity: 1;
}

/* Client Section */
.client-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.client-section h3 {
    font-size: 0.75em;
    color: #999;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.client-section p {
    font-size: 0.85em;
    color: #333;
    margin: 2px 0;
}

/* Table */
.inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.inv-table th,
.inv-table td {
    padding: 8px 6px;
    font-size: 0.8em;
}

.inv-table th {
    text-align: left;
}

.inv-table td {
    border-bottom: 1px solid #eee;
}

.inv-table input {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    width: 100%;
    padding: 2px;
}

.inv-table input:focus {
    outline: none;
    background: #f5f5f5;
    border-radius: 3px;
}

.inv-table input[type="number"] {
    text-align: right;
    width: 70px;
}

.row-num {
    color: #999;
    text-align: center !important;
    width: 30px;
}

.item-total {
    text-align: right !important;
    font-weight: 600;
}

/* Unit cell */
.unit-cell {
    position: relative;
}

.unit-select {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    width: 70px;
    cursor: pointer;
    padding: 2px;
}

.unit-select:focus {
    outline: none;
    background: #f5f5f5;
}

.unit-custom {
    border: none;
    background: #f5f5f5;
    font-family: inherit;
    font-size: inherit;
    width: 60px;
    padding: 2px;
    border-radius: 3px;
    margin-left: 3px;
}

.unit-custom.hidden {
    display: none;
}

/* Print-only elements - hidden on screen */
.print-only {
    display: none !important;
}

.unit-text {
    display: none !important;
}

/* Remove/Add buttons */
.rm-btn {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 1em;
    padding: 2px 5px;
}

.rm-btn:hover {
    color: #e74c3c;
}

.add-btn {
    width: 100%;
    padding: 8px;
    border: 2px dashed #ddd;
    background: transparent;
    cursor: pointer;
    color: #999;
    font-family: inherit;
    font-size: 0.85em;
    margin-bottom: 15px;
    border-radius: 5px;
}

.add-btn:hover {
    border-color: #999;
    color: #666;
}

/* Totals */
.totals-wrap {
    display: flex;
    justify-content: flex-end;
}

.totals-box {
    width: 250px;
}

.tot-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 0.85em;
}

.tot-row.total {
    font-weight: bold;
    font-size: 1em;
    border-top: 2px solid;
    padding-top: 10px;
    margin-top: 8px;
}

/* Notes */
.notes-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.notes-section h4 {
    font-size: 0.75em;
    color: #999;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.notes-section pre {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.8em;
    color: #666;
    line-height: 1.5;
}

/* Thank you */
.thank-you {
    text-align: center;
    margin-top: 20px;
    font-weight: 500;
    font-size: 0.9em;
}

/* Editable */
[contenteditable="true"] {
    outline: none;
    border-radius: 2px;
    padding: 1px 3px;
    margin: -1px -3px;
    transition: background 0.2s;
}

[contenteditable="true"]:hover {
    background: rgba(212, 168, 83, 0.1);
}

[contenteditable="true"]:focus {
    background: rgba(212, 168, 83, 0.15);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1rem;
    color: var(--color-muted);
    font-size: 0.7rem;
    border-top: 1px solid var(--color-border);
    margin-top: 1rem;
}

.footer a {
    color: var(--color-gold);
    text-decoration: none;
}

/* Message */
.message-box {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 0.35rem;
    font-weight: 500;
    font-size: 0.75rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.message-box.show {
    transform: translateY(0);
    opacity: 1;
}

.message-box.success {
    background: var(--color-success);
    color: white;
}

.message-box.error {
    background: var(--color-error);
    color: white;
}

/* Mobile */
@media (max-width: 600px) {
    .invoice-content {
        padding: 15px;
        font-size: 11px;
    }

    .inv-header {
        flex-direction: column;
        gap: 15px;
    }

    .invoice-info {
        text-align: left;
    }

    .client-section {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    .inv-table th,
    .inv-table td {
        padding: 5px 3px;
        font-size: 0.7em;
    }

    .inv-table input[type="number"] {
        width: 50px;
    }

    .unit-select {
        width: 55px;
    }

    .totals-box {
        width: 100%;
    }
}

/* ========== PRINT ========== */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
    }

    /* Hide UI elements */
    .header,
    .sidebar,
    .footer,
    .message-box,
    .panel-header,
    .no-print,
    .add-btn,
    .rm-btn,
    .date-pick,
    .unit-custom,
    .unit-select {
        display: none !important;
    }

    /* Show print-only elements */
    .print-only,
    .unit-text {
        display: inline !important;
    }

    .main-layout {
        display: block !important;
    }

    .panel {
        border: none !important;
        background: white !important;
    }

    .invoice-preview {
        box-shadow: none !important;
        border: none !important;
        max-width: none !important;
        width: 100% !important;
    }

    .invoice-content {
        padding: 10mm !important;
    }

    [contenteditable="true"] {
        background: transparent !important;
    }

    /* Hide all inputs in table */
    .inv-table input {
        display: none !important;
    }

    .inv-table th {
        color: white !important;
    }

    /* Company logo on print */
    .company-logo {
        max-height: 60px !important;
    }

    /* Dark layout print fix */
    .layout-dark {
        background: white !important;
        color: #333 !important;
    }

    .layout-dark * {
        color: #333 !important;
    }

    .layout-dark h1,
    .layout-dark h2 {
        color: var(--c) !important;
    }
}

@page {
    margin: 10mm;
}