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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8fafc;
}

/* Utility */
.hidden { display: none !important; }

/* Modal */
.modal-root {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-root.active { display: flex; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
}
.modal-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    width: 92%;
    max-width: 460px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    padding: 24px;
    z-index: 1001;
}
.modal-card h3 {
    margin-bottom: 8px;
    font-size: 1.25rem;
    color: #1f2937;
}
.modal-card p {
    color: #6b7280;
    margin-bottom: 16px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Toasts */
#toastContainer {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1100;
}
.toast {
    min-width: 260px;
    max-width: 360px;
    background: #111827;
    color: #fff;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    opacity: 0.98;
}
.toast.success { background: #065f46; }
.toast.error { background: #b91c1c; }
.toast.info { background: #111827; }

/* Authentication Styles */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.logo {
    font-size: 2rem;
    font-weight: 700;
    color: #4f46e5;
    margin-bottom: 10px;
}

.auth-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
}

.auth-header p {
    color: #6b7280;
    font-size: 0.9rem;
}

.auth-form {
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-primary {
    background-color: #4f46e5;
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: #4338ca;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background-color: #e5e7eb;
}

.auth-footer {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.auth-footer p {
    color: #6b7280;
    font-size: 0.9rem;
}

.auth-footer a {
    color: #4f46e5;
    text-decoration: none;
    font-weight: 500;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Dashboard Styles */
.dashboard-container {
    min-height: 100vh;
    background-color: #f8fafc;
}

.dashboard-header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.dashboard-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 10px;
}

.invoice-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

/* Ensure breadcrumbs don't occupy a single grid column and push preview down */
.invoice-container > .breadcrumbs {
    grid-column: 1 / -1;
}

.invoice-form {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.invoice-form h2 {
    margin-bottom: 30px;
    color: #1f2937;
    font-size: 1.5rem;
    font-weight: 600;
}

.form-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.form-section:last-child {
    border-bottom: none;
}

.form-section h3 {
    margin-bottom: 20px;
    color: #374151;
    font-size: 1.1rem;
    font-weight: 600;
}

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

.item-row {
    margin-bottom: 15px;
    padding: 15px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.item-fields {
    display: grid;
    grid-template-columns: 2fr 80px 120px 100px 30px;
    gap: 10px;
    align-items: center;
}

.item-fields input {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}

.item-total {
    font-weight: 600;
    color: #059669;
    text-align: right;
}

.btn-remove-item {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-remove-item:hover {
    background: #dc2626;
}

.form-actions {
    margin-top: 30px;
    text-align: center;
}

/* Invoice Preview */
.invoice-preview {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 100px;
}

.preview-header {
    padding: 20px 30px;
    border-bottom: 1px solid #e5e7eb;
}

.preview-header h3 {
    color: #374151;
    font-size: 1.1rem;
    font-weight: 600;
}

.invoice-document {
    padding: 30px;
    background: white;
    position: relative;
}

/* Breadcrumbs */
.breadcrumbs {
    font-size: 0.9rem;
    color: #6b7280;
}

.breadcrumb-link {
    color: #2563eb;
    text-decoration: none;
}

.breadcrumb-link:hover {
    text-decoration: underline;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #4f46e5;
}

.invoice-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #4f46e5;
}

.invoice-meta p {
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.invoice-parties h4 {
    margin-bottom: 10px;
    color: #374151;
    font-weight: 600;
}

.invoice-parties p {
    margin-bottom: 5px;
    color: #6b7280;
}

.invoice-items table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

/* Allow horizontal scroll on small screens for tables */
.invoice-items {
    overflow-x: auto;
}

.invoice-items th,
.invoice-items td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.invoice-items th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
}

.invoice-items td:last-child,
.invoice-items th:last-child {
    text-align: right;
}

.invoice-payment {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-left: 4px solid #4f46e5;
    border-radius: 8px;
    padding: 16px;
    margin: 10px 0 24px 0;
}

.invoice-payment h4 {
    margin-bottom: 8px;
    color: #374151;
    font-weight: 600;
}

.invoice-payment p {
    margin: 4px 0;
    color: #4b5563;
}

.invoice-payment a.payment-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #2563eb;
    text-decoration: none;
    border-bottom: 1px dashed rgba(37, 99, 235, 0.5);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.invoice-payment a.payment-link:hover {
    color: #1d4ed8;
    border-bottom-color: rgba(29, 78, 216, 0.7);
}

.invoice-payment a.payment-link::before {
    content: "🔗";
}

.invoice-totals {
    margin-left: auto;
    width: 300px;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e5e7eb;
}

.totals-row.total {
    border-top: 2px solid #374151;
    border-bottom: none;
    padding-top: 15px;
    margin-top: 10px;
    font-size: 1.1rem;
}

/* Invoice Notes Section */
.invoice-notes {
    margin: 20px 0;
    padding: 15px;
    border-top: 1px solid #e5e7eb;
}

.invoice-notes h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.invoice-notes p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #6b7280;
    white-space: pre-wrap;
}

/* Currency Selector Styling */
#currency {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background-color: white;
    color: #374151;
    transition: border-color 0.2s ease;
}

#currency:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Notes Textarea Styling */
#notes {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease;
}

#notes:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#notes::placeholder {
    color: #9ca3af;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .invoice-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .invoice-preview {
        position: static;
    }
    
    .header-content {
        padding: 0 15px;
        gap: 10px;
    }

    .header-actions {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .header-actions .btn {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
    
    .item-fields {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .item-fields input {
        width: 100%;
    }
    
    .item-total {
        text-align: left;
        font-size: 1rem;
        padding: 8px 0;
    }
    
    .btn-remove-item {
        width: 100%;
        height: 32px;
        margin-top: 8px;
    }
    
    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }

    .invoice-header h1 {
        font-size: 1.5rem;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .invoice-totals {
        width: 100%;
    }
    
    .auth-card {
        padding: 30px 20px;
    }
    
    .dashboard-main {
        padding: 20px 15px;
    }
    
    .invoice-form,
    .invoice-document {
        padding: 20px;
    }

    /* Stack action buttons */
    .form-actions .btn {
        display: block;
        width: 100%;
        margin-bottom: 10px;
    }
    .form-actions .btn:last-child {
        margin-bottom: 0;
    }

    /* Smaller QR on mobile */
    #qrcode canvas, #qrcode img {
        width: 100px !important;
        height: 100px !important;
    }
}

/* Watermarks */
.watermark-diagonal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-28deg);
    font-size: 96px;
    font-weight: 700;
    color: #111827;
    opacity: 0.05;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
    z-index: 0;
}

.watermark-side {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%) rotate(90deg);
    transform-origin: right center;
    font-size: 14px;
    letter-spacing: 2px;
    color: #4b5563;
    opacity: 0.25;
    pointer-events: none;
    user-select: none;
    z-index: 0;
}

/* Ensure main content sits above faint watermarks */
.invoice-document > *:not(.watermark-diagonal):not(.watermark-side) {
    position: relative;
    z-index: 1;
}

@media (max-width: 480px) {
    .header-content {
        padding: 0 15px;
    }
    
    .logo {
        font-size: 1.5rem;
    }
    
    .invoice-items table {
        font-size: 0.9rem;
    }
    
    .invoice-items th,
    .invoice-items td {
        padding: 8px 6px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.95rem;
    }
}

@media print {
  .invoice-parties {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0;
  }

  .invoice-parties .from-section,
  .invoice-parties .to-section {
    width: 48%;
  }

  /* Optional: remove any page-breaking issues */
  .invoice-parties, 
  .invoice-parties * {
    page-break-inside: avoid;
  }
}