/* ============================================
   Local Invoice Generator — Design System
   ============================================ */
:root {
    --bg: #1A1A2E;
    --bg2: #16213E;
    --bg-card: rgba(22, 33, 62, 0.9);
    --border: rgba(255, 255, 255, 0.08);
    --text: #E2E8F0;
    --muted: #64748B;
    --primary: #0984E3;
    --dark: #2D3436;
    --accent: #0984E3;
    --success: #00B894;
    --r: 10px;
    --font: 'Inter', sans-serif;
}

[data-theme="classic"] {
    --primary: #2D3436;
    --accent: #636E72;
}

[data-theme="minimal"] {
    --primary: #0984E3;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app {
    max-width: 840px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* Header */
.header {
    padding: 12px 0 8px;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

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

.logo-icon {
    font-size: 1.3rem;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--success));
    border-radius: 8px;
}

.logo h1 {
    font-size: 1rem;
    font-weight: 700;
}

.tagline {
    font-size: .62rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.header-actions select {
    padding: 6px 10px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font: 500 .76rem var(--font);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font: 600 .8rem var(--font);
    cursor: pointer;
    transition: .2s;
}

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

.btn-secondary {
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--muted);
}

.btn-ghost {
    background: none;
    border: 1px dashed var(--border);
    color: var(--muted);
}

.btn-sm {
    padding: 6px 10px;
    font-size: .74rem;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

/* Invoice Layout */
.main {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 28px 32px;
    margin-top: 8px;
}

.top-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.company-section {
    display: flex;
    gap: 12px;
}

.logo-upload {
    width: 60px;
    height: 60px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: .6rem;
    color: var(--muted);
    overflow: hidden;
    flex-shrink: 0;
}

.logo-upload img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.company-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.company-fields input,
.bill-to input {
    border: none;
    background: transparent;
    color: var(--text);
    font: 400 .82rem var(--font);
    padding: 2px 0;
    border-bottom: 1px solid transparent;
}

.company-fields input:focus,
.bill-to input:focus {
    outline: none;
    border-bottom-color: var(--primary);
}

.input-lg {
    font-size: 1rem !important;
    font-weight: 700 !important;
}

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

.invoice-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: 0.04em;
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    margin-bottom: 4px;
}

.meta-row label {
    font-size: .66rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
}

.meta-row input {
    width: 120px;
    padding: 4px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font: .78rem var(--font);
    text-align: right;
}

.meta-row input:focus {
    outline: none;
    border-color: var(--primary);
}

.bill-to {
    margin-bottom: 20px;
}

.bill-to h3 {
    font-size: .7rem;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.bill-to input {
    display: block;
    width: 260px;
}

/* Items Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
}

.items-table th {
    font-size: .66rem;
    text-transform: uppercase;
    color: var(--muted);
    padding: 8px 6px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.items-table th.num {
    text-align: right;
}

.items-table td {
    padding: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, .03);
}

.items-table input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    font: .82rem var(--font);
    padding: 4px 0;
}

.items-table input:focus {
    outline: none;
}

.items-table .num input {
    text-align: right;
    width: 80px;
}

.items-table .amount {
    text-align: right;
    font-weight: 600;
    font-size: .82rem;
    min-width: 80px;
}

.items-table .del-btn {
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: .8rem;
    padding: 4px;
}

.items-table .del-btn:hover {
    color: #F87171;
}

/* Totals */
.totals {
    margin: 16px 0;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: .84rem;
}

.total-final {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    padding-top: 8px;
    border-top: 2px solid var(--border);
    margin-top: 8px;
}

.discount-input {
    display: flex;
    gap: 4px;
    align-items: center;
}

.discount-input input {
    width: 60px;
    padding: 4px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font: .78rem var(--font);
    text-align: right;
}

.discount-input select {
    padding: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font: .72rem var(--font);
}

/* Notes */
.notes-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.notes-section h3 {
    font-size: .7rem;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.notes-section textarea {
    width: 100%;
    padding: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font: .78rem var(--font);
    resize: vertical;
}

/* Drafts */
.drafts-section {
    margin-top: 16px;
}

.drafts-section h3 {
    font-size: .82rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.drafts-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.draft-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: .2s;
}

.draft-item:hover {
    border-color: var(--primary);
}

.draft-item .draft-name {
    font-size: .82rem;
    font-weight: 600;
}

.draft-item .draft-date {
    font-size: .66rem;
    color: var(--muted);
}

.draft-item .draft-del {
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: .7rem;
}

.empty-msg {
    font-size: .78rem;
    color: var(--muted);
    text-align: center;
    padding: 8px;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    font-size: .82rem;
    opacity: 0;
    transition: .35s;
    z-index: 100;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.hidden {
    display: none !important;
}

/* Print */
@media print {

    .no-print,
    .drafts-section,
    .toast {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .app {
        padding: 0;
    }

    .main {
        border: none;
        box-shadow: none;
        background: #fff;
        padding: 20px;
    }

    .invoice-title {
        color: #2D3436;
    }

    .total-final {
        color: #2D3436;
    }

    .items-table th,
    .items-table td {
        border-bottom-color: #ddd;
    }

    .notes-section textarea,
    .meta-row input,
    .company-fields input,
    .bill-to input,
    .items-table input,
    .discount-input input,
    .discount-input select {
        border: none;
        background: transparent;
        color: #000;
    }

    .no-print-input .discount-input {
        display: none;
    }

    .no-print-input {
        display: none;
    }
}

@media (max-width: 600px) {
    .top-row {
        flex-direction: column;
    }

    .notes-section {
        grid-template-columns: 1fr;
    }
}