:root {
    --primary: #6366F1;
    --primary-dark: #4F46E5;
    --primary-light: #818CF8;
    --success: #10B981;
    --success-dark: #059669;
    --danger: #EF4444;
    --warning: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
}

/* Hide Live Server overlay */
body > div:last-child:not([class]):not([id]) {
    display: none !important;
}

/* Hide common development server overlays */
div[style*="position: fixed"][style*="bottom: 0"][style*="right: 0"] {
    display: none !important;
}

/* Hide any element containing localhost or IP text */
div:contains("127.0.0.1"), div:contains("localhost"), div:contains("5500") {
    display: none !important;
}

header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo svg {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

.tagline {
    font-size: 0.75rem;
    color: var(--gray-600);
    display: none;
}

.header-right {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.btn-header {
    padding: 0.4rem 0.6rem;
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-header:hover {
    background: var(--gray-200);
    border-color: var(--gray-400);
}

.btn-header.btn-clear {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-header.btn-clear:hover {
    background: #DC2626;
    border-color: #DC2626;
}

.main-container {
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.form-section, .preview-section {
    background: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.form-header h2 {
    font-size: 1.25rem;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.form-header p {
    font-size: 0.8rem;
    color: var(--gray-600);
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.template-btn, .btn-load-client {
    padding: 0.5rem 0.75rem;
    background: white;
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.template-btn:hover, .btn-load-client:hover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.template-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-load-client {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-load-client:hover {
    background: var(--success-dark);
    border-color: var(--success-dark);
}

.currency-toggle {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.currency-btn {
    padding: 0.5rem 0.75rem;
    background: white;
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.currency-btn:hover {
    border-color: var(--primary);
}

.currency-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gray-200);
}

.section-header h3 {
    font-size: 1rem;
    color: var(--gray-900);
}

.btn-save-client, .btn-save-template {
    padding: 0.375rem 0.75rem;
    background: var(--primary-light);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-save-client:hover, .btn-save-template:hover {
    background: var(--primary);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    transition: all 0.2s;
    background: white;
}

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

.helper-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    color: var(--gray-500);
}

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

.service-presets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 1rem 0;
}

.preset-chip {
    padding: 0.5rem;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    text-align: center;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.items-section {
    margin: 1rem 0;
}

.items-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.add-item-btn {
    padding: 0.5rem 1rem;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.add-item-btn:hover {
    background: var(--success-dark);
}

.item-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    margin-bottom: 0.75rem;
    position: relative;
}

.item-row .remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.7rem;
    cursor: pointer;
}

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

.tax-section {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--border-radius);
}

.tax-toggle-container {
    margin-bottom: 1rem;
}

.tax-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
}

.tax-toggle input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

#taxInputSection {
    margin-top: 1rem;
}

.totals-summary {
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--gray-50);
    border-radius: var(--border-radius);
}

.total-box {
    text-align: center;
}

.total-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.total-amount {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 2rem;
}

.btn-primary, .btn-secondary {
    width: 100%;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--gray-50);
}

.preview-section {
    position: relative;
    max-height: none;
    overflow-y: visible;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.preview-header h2 {
    font-size: 1.1rem;
    color: var(--gray-900);
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    padding: 0.4rem 0.8rem;
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: auto !important;
    z-index: 10 !important;
    position: relative;
}

.icon-btn:hover {
    background: var(--gray-200);
}

.invoice-preview {
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    background: white;
}

.invoice-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--primary);
}

.invoice-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.invoice-meta {
    text-align: left;
    font-size: 0.8rem;
}

.invoice-meta > div {
    margin-bottom: 0.25rem;
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.party-section h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.party-info {
    font-size: 0.85rem;
    line-height: 1.6;
}

.party-info .name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.work-summary {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--gray-50);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
}

.work-summary strong {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-700);
}

.work-summary p {
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.5;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    overflow-x: auto;
    display: block;
}

.invoice-table thead,
.invoice-table tbody {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.invoice-table th,
.invoice-table td {
    padding: 0.6rem 0.4rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    word-wrap: break-word;
}

.invoice-table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--gray-700);
    border-bottom: 2px solid var(--primary);
}

.invoice-table td {
    font-size: 0.75rem;
}

.invoice-table .amount {
    text-align: right;
    font-weight: 500;
}

.invoice-totals {
    display: flex;
    justify-content: flex-end;
    margin: 1.5rem 0;
}

.totals-box {
    width: 100%;
    max-width: 300px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.85rem;
}

.total-row.grand-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    border-top: 2px solid var(--primary);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.invoice-notes {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--gray-200);
}

.invoice-notes strong {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-700);
}

.invoice-notes p {
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.6;
    white-space: pre-line;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.25rem;
    color: var(--gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    text-align: center;
}

.success-icon {
    color: var(--success);
}

.modal-title {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--gray-900);
}

.modal-message {
    text-align: center;
    color: var(--gray-600);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.modal-btn {
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
}

.modal-btn-primary {
    background: var(--primary);
    color: white;
}

.modal-btn-primary:hover {
    background: var(--primary-dark);
}

.modal-btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.modal-btn-secondary:hover {
    background: var(--gray-300);
}

.share-link-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}

.share-link-container input {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.85rem;
}

.btn-copy {
    padding: 0.625rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.btn-copy:hover {
    background: var(--primary-dark);
}

.share-link-note {
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-top: 0.5rem;
}

#savedClientsList, #savedTemplatesList {
    max-height: 400px;
    overflow-y: auto;
}

.saved-item {
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.saved-item:hover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.saved-item-name {
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.saved-item-details {
    font-size: 0.8rem;
    color: var(--gray-600);
}

.saved-item-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.saved-item-actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
}

.btn-load {
    background: var(--primary);
    color: white;
}

.btn-delete {
    background: var(--danger);
    color: white;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
    font-size: 0.9rem;
}

.alert {
    display: none;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}

.alert.show {
    display: block;
}

.alert-success {
    background: #D1FAE5;
    border: 1px solid #10B981;
    color: #065F46;
}

/* Tablet breakpoint (640px - 1023px) */
@media (min-width: 640px) {
    .header-content {
        padding: 0 1.5rem;
        grid-template-columns: 1fr auto;
        align-items: center;
    }

    .header-right {
        justify-content: flex-end;
    }

    .logo svg {
        width: 32px;
        height: 32px;
    }

    .logo-text {
        font-size: 1.5rem;
    }

    .btn-header {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .form-section, .preview-section {
        padding: 1.5rem;
    }

    .form-header h2 {
        font-size: 1.5rem;
    }

    .form-header p {
        font-size: 0.875rem;
    }

    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }

    .currency-toggle {
        grid-template-columns: repeat(4, 1fr);
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .service-presets {
        grid-template-columns: repeat(3, 1fr);
    }

    .action-buttons {
        flex-direction: row;
    }

    .btn-primary, .btn-secondary {
        width: auto;
        flex: 1;
    }

    .invoice-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }

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

    .invoice-title {
        font-size: 2.25rem;
    }

    .invoice-meta {
        font-size: 0.875rem;
    }

    .invoice-parties {
        grid-template-columns: 1fr 1fr;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    .total-row {
        font-size: 0.875rem;
    }

    .total-row.grand-total {
        font-size: 1.5rem;
    }

    .share-link-container {
        flex-direction: row;
    }

    .share-link-container input {
        flex: 1;
    }
}

/* Desktop breakpoint (1024px+) */
@media (min-width: 1024px) {
    .tagline {
        display: block;
    }

    .main-container {
        margin: 2rem auto;
        padding: 0 1.5rem;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }

    .form-section, .preview-section {
        padding: 2rem;
    }

    .preview-section {
        position: sticky;
        top: 5.5rem;
        max-height: calc(100vh - 6.5rem);
        overflow-y: auto;
    }

    .invoice-preview {
        padding: 2rem;
    }

    .total-amount {
        font-size: 2rem;
    }

    .item-row {
        grid-template-columns: 2fr 1fr 1fr 1fr auto;
    }

    .item-row .remove-btn {
        position: static;
        align-self: end;
        margin-bottom: 0.5rem;
    }
}

@media print {
    @page {
        margin: 0.5in;
        size: auto;
    }

    body {
        background: white;
    }

    body * {
        visibility: hidden;
    }

    .invoice-preview,
    .invoice-preview * {
        visibility: visible;
    }

    .invoice-preview {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        border: none;
        padding: 0;
        box-shadow: none;
    }

    .form-section,
    .preview-header,
    header,
    .preview-actions {
        display: none !important;
    }
    
    .main-container {
        display: block;
        margin: 0;
        padding: 0;
    }

    .preview-section {
        position: static;
    }
}
