:root {
    --primary: #1d4ed8;
    --primary-hover: #1e3a8a;
    --bg-main: #f3f4f6;
    --bg-panel: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;

    --radius: 8px;
    --font: 'Inter', system-ui, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-main);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.text-sm {
    font-size: 0.875rem;
}

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

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

.font-bold {
    font-weight: 600;
}

.pre-line {
    white-space: pre-line;
}

.hidden {
    display: none !important;
}

.mt-1 {
    margin-top: 1rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-secondary {
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-main);
}

.btn-text {
    background: transparent;
    color: var(--primary);
    padding: 0;
    font-weight: 600;
}

.btn-text:hover {
    text-decoration: underline;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 4px;
}

.btn-icon:hover {
    color: var(--danger);
    background: #fee2e2;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.btn-close:hover {
    color: var(--text-main);
}

/* Nav */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.nav-actions {
    display: flex;
    gap: 0.75rem;
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left Editor Pane */
.editor-pane {
    width: 400px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.editor-pane::-webkit-scrollbar {
    width: 6px;
}

.editor-pane::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.editor-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.f-full {
    grid-column: 1 / -1;
}

.form-grid label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="url"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    transition: border-color 0.2s;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
}

textarea {
    resize: vertical;
}

.item-row {
    display: grid;
    grid-template-columns: 1fr 60px 80px 30px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: start;
}

.item-row input {
    margin-bottom: 0;
}

.items-list {
    display: flex;
    flex-direction: column;
}

/* Right Preview Pane */
.preview-pane {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.invoice-box {
    background: white;
    width: 100%;
    max-width: 800px;
    min-height: 1056px;
    /* Approx 8.5x11 aspect */
    padding: 3rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    color: #1a1a1a;
    position: relative;
    /* Print transitions */
    transition: transform 0.3s ease;
}

/* Invoice Inner Styles */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 3rem;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 2rem;
}

.inv-biz img {
    max-height: 60px;
    max-width: 150px;
    margin-bottom: 0.5rem;
    object-fit: contain;
}

.inv-biz h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.inv-title-area h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    color: #cbd5e1;
    text-align: right;
    margin-bottom: 1rem;
}

.meta-row {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.meta-row span {
    color: var(--text-muted);
}

.inv-client {
    margin-bottom: 3rem;
}

.inv-client h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.inv-table th {
    border-bottom: 2px solid var(--border);
    padding: 0.75rem 0.5rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
}

.inv-table td {
    border-bottom: 1px solid var(--border);
    padding: 1rem 0.5rem;
    font-size: 0.95rem;
}

.width-sm {
    width: 15%;
}

.width-md {
    width: 20%;
}

.inv-totals-wrap {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 3rem;
}

.inv-notes {
    flex: 1;
}

.inv-notes h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.inv-totals {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    padding: 0.25rem 0.5rem;
}

.grand-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    border-top: 2px solid var(--border);
    padding-top: 0.75rem;
    margin-top: 0.25rem;
}

.inv-footer {
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hist-card {
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
}

.hist-card:hover {
    border-color: var(--primary);
}

.hist-info span {
    display: block;
}

.hist-info .h-inv {
    font-weight: 600;
}

.hist-info .h-cli {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Print Media Query */
@media print {
    body {
        background: white;
        height: auto;
    }

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

    .preview-pane {
        padding: 0;
        display: block;
        background: white;
    }

    .invoice-box {
        box-shadow: none;
        padding: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
        min-height: 0;
        border: none;
    }

    /* Ensure colors print correctly */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Animations */
.fade-update {
    animation: flashTotal 0.5s ease;
}

@keyframes flashTotal {
    0% {
        color: var(--accent);
    }

    100% {
        color: var(--primary);
    }
}