/* Invoice Generator - Stylesheet */
/* Brand: Dark navy #1a2332, Accent #2563eb, Light #f8fafc */

:root {
    --primary: #1a2332;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Navbar */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 18px;
}

.logo svg { color: var(--accent); }

.nav-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); border-color: var(--text-muted); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-sm { padding: 7px 14px; font-size: 13px; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

/* Main Content */
.main-content {
    padding: 32px 0 60px;
}

.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 6px;
}

.page-header p {
    color: var(--text-muted);
    font-size: 15px;
}

/* Form Grid: 2 columns (form + preview) */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 40px;
    align-items: start;
}

.form-column { min-width: 0; }

.preview-column {
    position: relative;
}

.preview-sticky {
    position: sticky;
    top: 80px;
}

.preview-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.preview-frame {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 500px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.preview-frame iframe {
    width: 100%;
    height: 700px;
    border: none;
    transform-origin: top left;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--text-light);
    padding: 40px;
    text-align: center;
}

/* Form Sections */
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.form-row { margin-bottom: 14px; }
.form-row:last-child { margin-bottom: 0; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
    background: var(--surface);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* File Upload */
.file-upload {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.file-upload:hover, .file-upload.dragover {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.02);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 13px;
}

.upload-placeholder svg { color: var(--text-light); }

.upload-preview {
    position: relative;
    display: inline-block;
}

.upload-preview img {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
}

.btn-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Template Selector */
.template-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.template-option {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}

.template-option:hover { border-color: var(--text-light); }

.template-option.active {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.03);
}

.template-option input { display: none; }

.template-option span {
    display: block;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 500;
}

.template-preview {
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    background: #f9f9f9;
    position: relative;
}

.branded-preview {
    border: 1px solid #e8d9c8;
}
.branded-preview .preview-bar {
    height: 4px;
    background: linear-gradient(to right, #6a441d, #d39445);
}
.branded-preview .preview-lines {
    padding: 8px;
}
.branded-preview .preview-lines::before {
    content: '';
    display: block;
    height: 4px;
    width: 40%;
    background: #6a441d;
    border-radius: 2px;
    margin-bottom: 6px;
}
.branded-preview .preview-lines::after {
    content: '';
    display: block;
    height: 3px;
    width: 80%;
    background: #e8d9c8;
    border-radius: 2px;
}

.traditional-preview {
    border: 2px solid #000;
}
.traditional-preview .preview-border {
    height: 8px;
    border-bottom: 1px solid #000;
}
.traditional-preview .preview-lines {
    padding: 8px;
}
.traditional-preview .preview-lines::before {
    content: '';
    display: block;
    height: 4px;
    width: 50%;
    margin: 0 auto;
    background: #333;
    border-radius: 2px;
    margin-bottom: 6px;
}
.traditional-preview .preview-lines::after {
    content: '';
    display: block;
    height: 3px;
    width: 70%;
    background: #ddd;
    border-radius: 2px;
}

/* Line Items */
.line-items-table { margin-bottom: 16px; }

.line-items-header {
    display: grid;
    grid-template-columns: 1fr 70px 100px 100px 36px;
    gap: 8px;
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.line-item-row {
    display: grid;
    grid-template-columns: 1fr 70px 100px 100px 36px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.line-item-row input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.line-item-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.line-item-row .item-amount {
    background: var(--bg);
    color: var(--text-muted);
}

.btn-remove-row {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-light);
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-remove-row:hover { background: #fee2e2; color: var(--danger); }

/* Totals */
.totals-summary {
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
}

.total-row .vat-input {
    display: flex;
    align-items: center;
    gap: 4px;
}

.total-row .vat-input input {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

.total-final {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    border-top: 2px solid var(--accent);
    padding-top: 10px;
    margin-top: 6px;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
}

.form-actions .btn { padding: 12px 28px; font-size: 15px; }

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0;
    color: var(--text-light);
    font-size: 13px;
    border-top: 1px solid var(--border);
}

/* Auth Pages */
.auth-container {
    max-width: 420px;
    margin: 60px auto;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-card h2 {
    font-size: 22px;
    margin-bottom: 6px;
}

.auth-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.auth-card .form-group { margin-bottom: 16px; }

.auth-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 12px;
    margin-top: 8px;
}

.auth-card .auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-card .auth-footer a { color: var(--accent); text-decoration: none; }

.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.invoice-table {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.invoice-table th,
.invoice-table td {
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.invoice-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
}

.invoice-table tr:last-child td { border-bottom: none; }
.invoice-table tr:hover td { background: var(--bg); }

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-branded { background: #f8f2ed; color: #6a441d; }
.badge-traditional { background: #f0f0f0; color: #333; }

/* Responsive */
@media (max-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .preview-column { display: none; }
    .container { padding: 0 16px; }
}

@media (max-width: 640px) {
    .navbar { padding: 10px 0; }
    .logo span { font-size: 15px; }
    .logo svg { width: 22px; height: 22px; }
    
    .nav-actions .btn-ghost { display: none; }
    .nav-actions .btn-sm { padding: 6px 12px; font-size: 12px; }

    .main-content { padding: 20px 0 40px; }
    
    .page-header { margin-bottom: 20px; }
    .page-header h1 { font-size: 22px; }
    .page-header p { font-size: 13px; }

    .form-section { padding: 16px; margin-bottom: 14px; }
    .section-title { font-size: 14px; margin-bottom: 12px; padding-bottom: 8px; }

    .form-row-2, .form-row-3 { grid-template-columns: 1fr; gap: 10px; }

    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .form-group label { font-size: 12px; }

    /* Template selector stacked */
    .template-selector { grid-template-columns: 1fr 1fr; gap: 10px; }
    .template-option { padding: 12px 8px; }
    .template-option span { font-size: 11px; margin-top: 6px; }
    .template-preview { height: 45px; }

    /* Line items - card layout */
    .line-items-header { display: none; }
    .line-item-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 14px;
        background: var(--bg);
        border-radius: 8px;
        margin-bottom: 10px;
        position: relative;
    }
    .line-item-row input[name*="description"] {
        grid-column: 1 / -1;
    }
    .line-item-row .item-amount {
        grid-column: 1 / -1;
        font-weight: 600;
        text-align: right;
    }
    .btn-remove-row {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 24px;
        height: 24px;
        font-size: 16px;
    }

    /* Totals */
    .totals-summary { padding-top: 12px; }
    .total-row { font-size: 13px; flex-wrap: wrap; gap: 4px; }
    .total-row .vat-input input { width: 50px; }
    .total-final { font-size: 16px; }

    /* File upload */
    .file-upload { padding: 16px; }
    .upload-placeholder { font-size: 12px; }
    .upload-placeholder svg { width: 20px; height: 20px; }

    /* Actions */
    .form-actions {
        flex-direction: column;
        gap: 10px;
        padding-top: 16px;
    }
    .form-actions .btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
        font-size: 15px;
    }

    /* Footer */
    .footer { padding: 16px 0; font-size: 11px; }

    /* Auth pages */
    .auth-container { margin: 30px auto; }
    .auth-card { padding: 24px 20px; }
    .auth-card h2 { font-size: 20px; }

    /* Dashboard */
    .dashboard-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .dashboard-header .btn { width: 100%; justify-content: center; }
    
    .invoice-table { overflow-x: auto; }
    .invoice-table table { min-width: 500px; }
    .invoice-table th,
    .invoice-table td { padding: 10px 12px; font-size: 12px; }
}

@media (max-width: 380px) {
    .template-selector { grid-template-columns: 1fr; }
    .container { padding: 0 12px; }
    .form-section { padding: 14px 12px; }
    .line-item-row { padding: 12px 10px; }
}
