/* ========== CSS Variables ========== */
:root {
    --bg-primary: #f0f2f5;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #888;
    --border-color: #e0e0e0;
    --accent: #4361ee;
    --accent-dark: #3730a3;
    --success: #10b981;
    --info: #06b6d4;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
}

/* Dark Mode */
body.dark-mode {
    --bg-primary: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #b0b0b0;
    --text-muted: #777;
    --border-color: #2a2a4a;
    --shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

/* ========== Base Styles ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* ========== App Container ========== */
.app-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* ========== Form Section ========== */
.form-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.form-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-header h1 i {
    color: var(--accent);
}

.btn-icon {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--accent);
    color: #fff;
}

/* ========== Form Cards ========== */
.form-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.form-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.form-card h2 i {
    color: var(--accent);
}

/* ========== Form Elements ========== */
.form-group {
    margin-bottom: 12px;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 12px;
}

label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

label i {
    color: var(--accent);
    margin-right: 4px;
    width: 14px;
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: 'Inter', sans-serif;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

input[readonly] {
    background: var(--bg-primary);
    color: var(--text-muted);
}

input[type="file"] {
    padding: 8px;
    font-size: 0.8rem;
}

textarea {
    resize: vertical;
    min-height: 60px;
}

.logo-preview {
    max-width: 100px;
    max-height: 50px;
    margin-top: 8px;
    border-radius: 4px;
}


/* ========== Checkbox Groups ========== */
.checkbox-group {
    margin-bottom: 15px;
}

.checkbox-group h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.checkbox-group h4 i {
    color: var(--accent);
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.checkbox-label:hover {
    background: var(--bg-primary);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

/* ========== Cost Table ========== */
.cost-table-wrapper {
    overflow-x: auto;
    margin-bottom: 12px;
}

.cost-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.cost-table th,
.cost-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.cost-table th {
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.cost-table th:first-child { border-radius: 6px 0 0 0; }
.cost-table th:last-child { border-radius: 0 6px 0 0; }

.cost-table input {
    padding: 6px 8px;
    font-size: 0.8rem;
}

.cost-table .qty-input { width: 50px; text-align: center; }
.cost-table .price-input { width: 80px; text-align: right; }
.cost-table .total-cell { font-weight: 600; color: var(--accent); }

.btn-remove-row {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.75rem;
}

.btn-remove-row:hover {
    opacity: 0.8;
}

.btn-outline {
    background: transparent;
    border: 1px dashed var(--accent);
    color: var(--accent);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: var(--accent);
    color: #fff;
}

/* ========== Buttons ========== */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    transition: transform 0.1s, opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-dark { background: #1f2937; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }


/* ========== Preview Section ========== */
.preview-section {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow: hidden;
}

.preview-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.preview-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-header h2 i {
    color: var(--accent);
}

.invoice-preview {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
    background: #fff;
}

body.dark-mode .invoice-preview {
    background: #fff;
    color: #333;
}

/* ========== Invoice Preview Styles ========== */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--accent);
}

.inv-issuer {
    flex: 1;
}

.inv-logo {
    max-width: 80px;
    max-height: 60px;
    margin-bottom: 8px;
}

.inv-issuer h3 {
    font-size: 1.2rem;
    color: #1a1a2e;
    margin-bottom: 3px;
}

.inv-issuer .business-type {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 500;
    margin-bottom: 5px;
}

.inv-issuer p {
    font-size: 0.75rem;
    color: #666;
    margin: 1px 0;
}

.inv-meta {
    text-align: right;
}

.inv-meta .inv-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
}

.inv-meta p {
    font-size: 0.75rem;
    color: #555;
    margin: 2px 0;
}

.inv-meta .status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 5px;
}

.inv-meta .status.pending { background: #fef3c7; color: #92400e; }
.inv-meta .status.paid { background: #d1fae5; color: #065f46; }
.inv-meta .status.partial { background: #dbeafe; color: #1e40af; }

.inv-client {
    background: #f8f9fa;
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid var(--accent);
}

.inv-client h4 {
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    margin-bottom: 5px;
}

.inv-client .client-name {
    font-size: 1rem;
    font-weight: 600;
    color: #1a1a2e;
}

.inv-client p {
    font-size: 0.75rem;
    color: #666;
    margin: 1px 0;
}

.inv-billing {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    font-size: 0.75rem;
}

.inv-billing div {
    background: #f0f2f5;
    padding: 8px 12px;
    border-radius: 6px;
    flex: 1;
}

.inv-billing strong {
    display: block;
    color: #888;
    font-size: 0.65rem;
    text-transform: uppercase;
}

.inv-platforms {
    margin-bottom: 15px;
}

.inv-platforms h4 {
    font-size: 0.7rem;
    color: var(--accent);
    margin-bottom: 6px;
}

.inv-platforms .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.inv-platforms .tag {
    background: #e0e7ff;
    color: #3730a3;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 0.8rem;
}

.inv-table th,
.inv-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
}

.inv-table th {
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.inv-table th:first-child { border-radius: 6px 0 0 0; }
.inv-table th:last-child { border-radius: 0 6px 0 0; }

.inv-table .text-right { text-align: right; }
.inv-table .text-center { text-align: center; }

.inv-totals {
    margin-left: auto;
    width: 220px;
}

.inv-totals .row {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.8rem;
}

.inv-totals .row.grand-total {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    margin-top: 8px;
}

.inv-notes {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.inv-notes h4 {
    font-size: 0.7rem;
    color: var(--accent);
    margin-bottom: 5px;
}

.inv-notes p {
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 10px;
}

.inv-signature {
    margin-top: 30px;
    text-align: right;
}

.inv-signature .sig-line {
    border-top: 1px solid #333;
    width: 150px;
    margin-left: auto;
    padding-top: 5px;
    font-size: 0.75rem;
    color: #666;
}

.inv-footer {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
    text-align: center;
    font-size: 0.75rem;
    color: #888;
}

.empty-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #aaa;
}

.empty-preview i {
    font-size: 3rem;
    margin-bottom: 15px;
    color: #ddd;
}

/* ========== Responsive ========== */
@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 1fr;
    }
    .preview-section {
        position: static;
        max-height: none;
        min-height: 600px;
    }
}

@media (max-width: 600px) {
    .app-container { padding: 10px; }
    .form-row { flex-direction: column; gap: 0; }
    .checkbox-grid { grid-template-columns: 1fr 1fr; }
    .action-buttons { flex-direction: column; }
    .btn { width: 100%; justify-content: center; }
    .inv-header { flex-direction: column; }
    .inv-meta { text-align: left; margin-top: 15px; }
    .inv-totals { width: 100%; }
    .inv-billing { flex-direction: column; }
}

/* ========== Print Styles ========== */
@media print {
    body { background: #fff; }
    .app-container { display: block; }
    .form-section, .preview-header { display: none !important; }
    .preview-section { box-shadow: none; max-height: none; }
    .invoice-preview { padding: 0; }
}
