/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; width: 100%; }

/* === Navbar === */
.navbar {
    background: #1a1a2e;
    color: #fff;
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-container { display: flex; align-items: center; justify-content: space-between; }
.nav-brand { color: #fff; font-weight: 700; font-size: 1.2rem; }
.nav-brand:hover { text-decoration: none; }
.nav-links a { color: #cbd5e1; margin-left: 1.5rem; font-size: 0.9rem; transition: color .2s; }
.nav-links a:hover { color: #fff; text-decoration: none; }

/* === Main === */
main { flex: 1; padding: 2rem 0; }

h1 { font-size: 1.75rem; margin-bottom: 1.5rem; color: #1a1a2e; }
h2 { font-size: 1.3rem; margin-bottom: 1rem; }
h3 { font-size: 1.1rem; margin-bottom: 0.75rem; }

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
    background: #fff;
    padding: 1.5rem;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-number { font-size: 2rem; font-weight: 700; color: #2563eb; }
.stat-label { font-size: 0.85rem; color: #64748b; margin-top: 0.25rem; }

/* === Cards & Sections === */
.section { background: #fff; border-radius: 10px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 1.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.section-header h1, .section-header h2 { margin-bottom: 0; }

.card { background: #fff; border-radius: 10px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* === Tables === */
.table { width: 100%; border-collapse: collapse; }
.table th { background: #f8fafc; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; padding: 0.75rem; text-align: left; border-bottom: 2px solid #e2e8f0; }
.table td { padding: 0.75rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table tbody tr:hover { background: #f8fafc; }
.actions-cell { white-space: nowrap; }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

/* === Badges === */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

/* === Forms === */
.form { max-width: 800px; }
.form-section { margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid #f1f5f9; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; color: #374151; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color .2s;
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group small { display: block; color: #94a3b8; font-size: 0.78rem; margin-top: 0.25rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

/* === Filters === */
.filters { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1.5rem; font-size: 0.9rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.empty-state { text-align: center; padding: 3rem; color: #94a3b8; }

/* === Invoice View === */
.invoice-actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.invoice-paper {
    background: #fff;
    border-radius: 10px;
    padding: 2.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 900px;
}
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 2rem; }
.invoice-logo { max-height: 70px; margin-bottom: 0.5rem; }
.invoice-company h2 { margin-bottom: 0.25rem; }
.company-details { font-size: 0.85rem; color: #64748b; }
.invoice-meta h1 { font-size: 2rem; color: #1a1a2e; text-align: right; margin-bottom: 0.5rem; }
.meta-table td { padding: 0.15rem 0.5rem; font-size: 0.85rem; }
.meta-table td:first-child { color: #64748b; text-align: right; }

.invoice-billing { margin-bottom: 2rem; }
.invoice-billing h4 { font-size: 0.8rem; text-transform: uppercase; color: #64748b; margin-bottom: 0.3rem; }

.invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; }
.invoice-table th { background: #f8fafc; padding: 0.6rem; font-size: 0.8rem; text-transform: uppercase; color: #64748b; border-bottom: 2px solid #e2e8f0; text-align: left; }
.invoice-table td { padding: 0.6rem; border-bottom: 1px solid #f1f5f9; }
.invoice-table tfoot td { border-bottom: none; padding: 0.4rem 0.6rem; }
.total-row td { border-top: 2px solid #1a1a2e; font-size: 1.1rem; padding-top: 0.6rem; }

.invoice-notes { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #f1f5f9; }
.invoice-notes h4 { font-size: 0.85rem; color: #64748b; margin-bottom: 0.3rem; }
.invoice-notes p { font-size: 0.9rem; color: #475569; }

.invoice-banking { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #f1f5f9; }
.invoice-banking h4 { font-size: 0.8rem; text-transform: uppercase; color: #64748b; margin-bottom: 0.5rem; }
.banking-table td { padding: 0.2rem 0.75rem 0.2rem 0; font-size: 0.9rem; vertical-align: top; }
.banking-table td:first-child { font-weight: 600; color: #64748b; white-space: nowrap; width: 120px; }

/* === Items table in create form === */
#items-table input { width: 100%; padding: 0.4rem; border: 1px solid #d1d5db; border-radius: 4px; font-size: 0.875rem; }
#items-table td { padding: 0.4rem; }
.line-total { font-weight: 600; padding-top: 0.6rem !important; }

/* === Footer === */
.footer { padding: 1.5rem 0; text-align: center; color: #94a3b8; font-size: 0.8rem; margin-top: auto; }

/* === Print === */
@media print {
    .no-print, .navbar, .footer { display: none !important; }
    body { background: #fff; }
    main { padding: 0; }
    .invoice-paper { box-shadow: none; padding: 0; }
}

/* === Responsive === */
@media (max-width: 768px) {
    .invoice-header { flex-direction: column; gap: 1rem; }
    .invoice-meta h1 { text-align: left; }
    .meta-table td:first-child { text-align: left; }
    .form-row { grid-template-columns: 1fr; }
    .nav-links a { margin-left: 0.75rem; font-size: 0.8rem; }
}
