:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --primary-50: #f5f3ff;
    --secondary: #0f172a;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --input-color: #0f172a;
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-subtle: #f1f5f9;
    --border: #e2e8f0;
    --border-focus: #6366f1;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: #312e81;
    --secondary: #e2e8f0;
    --success: #34d399;
    --success-hover: #10b981;
    --danger: #f87171;
    --danger-hover: #ef4444;
    --warning: #fbbf24;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #7c8ba1;
    --input-color: #f1f5f9;
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --bg-subtle: #334155;
    --border: #334155;
    --border-focus: #818cf8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.3);
}

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-page);
    background-image: linear-gradient(180deg, var(--bg-page) 0%, var(--bg-subtle) 100%);
    min-height: 100vh;
}

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

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    z-index: 120;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform var(--transition-normal);
    transform: translateX(-100%);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
}

.sidebar-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-close-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sidebar-close-btn:hover {
    background: var(--bg-surface);
}

.sidebar-close-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.sidebar-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.sidebar-subtitle {
    font-size: 0.625rem;
    color: var(--text-muted);
}

.sidebar-search {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-search input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--bg-subtle);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.sidebar-search input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
}

.sidebar-search input::placeholder {
    color: var(--text-muted);
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    text-align: center;
    color: var(--text-muted);
}

.sidebar-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.sidebar-empty p {
    font-size: 0.875rem;
    line-height: 1.5;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
}

.sidebar-item:hover {
    background: var(--bg-subtle);
}

.sidebar-item.active {
    background: var(--primary-light);
}

.sidebar-item-icon {
    width: 36px;
    height: 48px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.sidebar-item.active .sidebar-item-icon {
    background: var(--primary);
    color: white;
}

.sidebar-item-icon svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.sidebar-item-content {
    flex: 1;
    min-width: 0;
}

.sidebar-item-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.sidebar-item-meta {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.sidebar-item-amount {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-item-delete {
    opacity: 0;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-item:hover .sidebar-item-delete {
    opacity: 1;
}

.sidebar-item-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.sidebar-item-delete svg {
    width: 16px;
    height: 16px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-clear-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sidebar-clear-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

.sidebar-clear-btn svg {
    width: 16px;
    height: 16px;
}

/* Hamburger Toggle - inside navbar */
.hamburger-toggle {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    margin-right: 8px;
}

.hamburger-toggle:hover {
    background: var(--bg-subtle);
}

.hamburger-toggle svg {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
}

/* Main Wrapper */
.main-wrapper {
    min-height: 100vh;
    transition: padding-left var(--transition-normal);
}

@media (min-width: 769px) {
    .main-wrapper {
        padding-left: 280px;
    }
    .main-wrapper.sidebar-closed {
        padding-left: 0;
    }
}

@media (max-width: 768px) {
    .sidebar {
        z-index: 250;
    }
    .sidebar::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-normal);
        z-index: -1;
    }
    .sidebar.open::before {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    z-index: 200;
    border-radius: 0 0 var(--radius-sm) 0;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.15s ease;
}

.skip-link:focus {
    top: 0;
}

/* Navbar */
.navbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .navbar {
    background: rgba(30, 41, 59, 0.85);
}

.navbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    gap: 16px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    transition: opacity var(--transition-fast);
}

.navbar-brand:hover {
    opacity: 0.8;
}

.navbar-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.navbar-title {
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: -0.025em;
}

.navbar-badge {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    letter-spacing: 0.02em;
    box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}

.navbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-status {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity var(--transition-slow);
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
}
.save-status.visible {
    opacity: 1;
}
.save-status.saved {
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

.language-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.language-select:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.language-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.history-select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.history-select:hover {
    border-color: var(--primary);
}

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

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
    border-color: var(--primary);
    transform: rotate(15deg);
}

.theme-toggle:focus-visible {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-normal);
}

.theme-toggle:hover svg {
    transform: scale(1.1);
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
[data-theme="dark"] .theme-toggle .moon-icon { display: none; }

/* Hero Section */
.hero {
    text-align: center;
    padding: 56px 0 40px;
}

.hero h1 {
    font-size: 2.75rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.15;
}

.hero h1 span {
    background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 50%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    max-width: 540px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Template Section */
.template-section {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    padding: 24px 32px;
    margin-bottom: 24px;
}

.template-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.template-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.template-options {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding-top: 4px;
}

.template-option {
    position: relative;
}

.template-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.template-option label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    border: 2px solid var(--border);
    background: var(--bg-surface);
    min-width: 140px;
}

.template-option label:hover {
    border-color: var(--primary);
    background: var(--bg-subtle);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.template-option input[type="radio"]:checked + label {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.template-icon {
    width: 48px;
    height: 64px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    box-shadow: var(--shadow-sm);
}

.template-modern1 .template-icon {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
}

.template-classic .template-icon {
    background: linear-gradient(135deg, #1f2937, #374151);
}

.template-business .template-icon {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
}

.template-option span {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.template-option input[type="radio"]:checked + label span {
    color: var(--primary);
}

/* Invoice Card */
.invoice-card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border);
    padding: 32px 40px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.invoice-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), #8b5cf6, #a855f7);
}

.card-section {
    margin-bottom: 36px;
    padding-bottom: 36px;
    border-bottom: 1px solid var(--border);
}

.card-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.card-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--bg-subtle);
}

.card-section-title svg {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.form-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group label .required {
    color: var(--danger);
    font-size: 0.75rem;
}

.due-date-row {
    display: flex;
    gap: 8px;
}
.due-date-row input[type="date"] {
    flex: 1;
    color: var(--input-color);
}
.due-date-preset {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    cursor: pointer;
    white-space: nowrap;
}
.due-date-preset:hover {
    border-color: var(--primary);
    background: var(--bg-surface);
}
.due-date-preset:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.due-date-preset option[value=""] {
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--input-color);
    background: var(--bg-surface);
    transition: all var(--transition-fast);
}

.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover {
    border-color: var(--text-muted);
}

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

.form-group select {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-group select.status-select option[value="paid"] { color: #10b981; }
.form-group select.status-select option[value="overdue"] { color: #ef4444; }

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-group input.invalid,
.form-group textarea.invalid {
    border-color: var(--danger);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.line-items input.zero-hint {
    color: var(--text-muted);
    font-style: italic;
}

.form-group input.invalid:focus,
.form-group textarea.invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
    word-break: break-word;
    overflow-wrap: break-word;
}

.form-group input[type="number"] {
    -moz-appearance: textfield;
}

.form-group input[type="number"]::-webkit-outer-spin-button,
.form-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.error {
    color: var(--danger);
    font-size: 0.8125rem;
    font-weight: 500;
    min-height: 1em;
}

/* Line Items Table */
.table-wrapper {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-surface);
}

.line-items {
    width: 100%;
    border-collapse: collapse;
}

.line-items thead tr {
    background: linear-gradient(135deg, var(--bg-subtle) 0%, var(--bg-surface) 100%);
}

.line-items th {
    text-align: left;
    padding: 14px 16px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.line-items th:last-child {
    width: 50px;
    text-align: center;
}

.line-items td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    transition: background var(--transition-fast);
}

.line-items tbody tr:last-child td {
    border-bottom: none;
}

.line-items tbody tr {
    transition: all var(--transition-fast);
}

.line-items tbody tr:hover {
    background: var(--bg-subtle);
}

.line-items tbody tr.row-focus {
    background: rgba(99, 102, 241, 0.05);
    box-shadow: inset 3px 0 0 var(--primary);
}

.line-items tbody tr.row-focus td {
    border-color: var(--primary);
}

/* De-emphasize empty rows */
.line-items tbody tr.empty-row {
    opacity: 0.5;
}
.line-items tbody tr.empty-row:hover {
    opacity: 0.7;
}
.line-items tbody tr.empty-row td {
    border-bottom-style: dashed;
}

.line-items textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    background: var(--bg-subtle);
    box-sizing: border-box;
    resize: vertical;
    min-height: 40px;
    max-height: 120px;
    transition: all var(--transition-fast);
    color: var(--input-color);
}

.line-items textarea:hover {
    border-color: var(--border);
}

.line-items textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.line-items input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    background: var(--bg-subtle);
    box-sizing: border-box;
    -moz-appearance: textfield;
    text-align: right;
    transition: all var(--transition-fast);
    color: var(--input-color);
}

.line-items input:hover {
    border-color: var(--border);
}

.line-items input[type="text"] {
    text-align: left;
}

.line-items input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.line-items input::-webkit-outer-spin-button,
.line-items input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.line-items input.invalid {
    color: var(--danger);
    border-color: var(--danger);
}

.line-items .item-amount {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9375rem;
    text-align: right;
    padding-right: 16px;
}

td.tax-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 100px;
}

.tax-amount {
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
}

/* Add Item Button */
.add-item-btn {
    margin-top: 20px;
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.add-item-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    border-style: solid;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.add-item-btn svg {
    width: 20px;
    height: 20px;
}

.bulk-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.bulk-action-btn {
    padding: 8px 14px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.bulk-action-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: translateY(-1px);
}

/* Action Toolbar */
.action-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 32px;
    padding-top: 32px;
    border-top: 2px solid var(--border);
    margin-bottom: 32px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.action-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn svg {
    width: 18px;
    height: 18px;
}

.action-btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

.action-btn-secondary:hover {
    background: var(--bg-surface);
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.action-btn-danger {
    background: var(--danger);
}

.action-btn-danger:hover {
    background: var(--danger-hover);
}

.action-btn-primary {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
}

.action-btn-primary:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

/* Totals Section */
.totals-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-top: 28px;
}

.totals {
    width: 100%;
    max-width: 360px;
    background: linear-gradient(135deg, var(--bg-subtle) 0%, var(--bg-surface) 100%);
    border-radius: var(--radius-xl);
    padding: 24px;
    border: 1.5px solid var(--border);
}

.totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.totals-row span:first-child {
    font-weight: 500;
}

.totals-row span:last-child {
    font-weight: 600;
}

.totals-row input[type="number"] {
    width: 120px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    background: var(--bg-surface);
    color: var(--input-color);
    text-align: right;
    transition: all 0.15s ease;
}

.totals-row input[type="number"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.totals-row.total {
    border-top: 2px solid var(--border);
    margin-top: 12px;
    padding-top: 16px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    background: linear-gradient(90deg, transparent 0%, var(--bg-subtle) 50%, transparent 100%);
}

.totals-row.total span:first-child {
    font-weight: 700;
}

.totals-row.total span:last-child {
    color: var(--primary);
    font-size: 1.375rem;
}

/* Delete Row Button */
.delete-row-btn {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-row-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    transform: scale(1.1);
}

.delete-row-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.delete-row-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.delete-row-btn svg {
    width: 16px;
    height: 16px;
}

.actions-col {
    width: 60px;
    padding: 8px 12px !important;
    text-align: center;
}

/* Logo Upload */
.logo-upload {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-subtle);
    border-radius: var(--radius-lg);
    border: 1.5px dashed var(--border);
}

.logo-upload-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.logo-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all var(--transition-fast);
    background: var(--bg-surface);
}

.logo-upload-area:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

#logo-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.logo-upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    pointer-events: none;
}

.logo-upload-placeholder span {
    font-size: 0.875rem;
    text-align: center;
}

.logo-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.logo-preview img {
    max-width: 140px;
    max-height: 70px;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.logo-remove-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.logo-remove-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Payment Details */
.payment-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-subtle);
    border-radius: var(--radius-lg);
}

.payment-details-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.payment-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.payment-grid .full-width {
    grid-column: 1 / -1;
}

/* Preview Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 20px;
}

.modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    overflow: hidden;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 12px;
    line-height: 1;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

.modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.modal-body {
    flex: 1;
    padding: 24px;
    overflow: auto;
}

#preview-embed {
    width: 100%;
    height: 60vh;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 0.9375rem;
    z-index: 1100;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-xl);
    max-width: 90%;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.toast-error {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    color: #991b1b;
    border: 1px solid #fecaca;
}

.toast-success {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    color: #166534;
    border: 1px solid #bbf7d0;
}

[data-theme="dark"] .toast-error {
    background: linear-gradient(135deg, #450a0a 0%, #7f1d1d 100%);
    color: #fca5a5;
    border-color: #fca5a5;
}

[data-theme="dark"] .toast-success {
    background: linear-gradient(135deg, #052e16 0%, #166534 100%);
    color: #86efac;
    border-color: #86efac;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: inherit;
    opacity: 0.6;
    font-size: 1.2rem;
    line-height: 1;
}

.toast-close:hover {
    opacity: 1;
}

/* Action Bar */
.action-bar {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 24px 32px;
    margin-bottom: 48px;
}

.action-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.template-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.template-selector-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.template-options {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}

.template-option {
    flex-shrink: 0;
    scroll-snap-align: start;
}

.template-option input[type="radio"] {
    display: none;
}

.template-option label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.template-option label:hover {
    background: var(--bg-subtle);
}

.template-option input[type="radio"]:checked + label {
    background: var(--primary-light);
    border-color: var(--primary);
}

.template-option svg {
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.template-option span {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.template-option input[type="radio"]:checked + label span {
    color: var(--primary);
    font-weight: 600;
}

/* Buttons */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#download-btn {
    padding: 14px 28px;
    font-size: 1rem;
}

/* Template Classes */

/* Modern: clean, rounded, indigo accents */
.template-modern1 .line-items th {
    background: var(--bg-subtle);
    border-bottom-color: var(--border);
    color: var(--text-secondary);
    border-radius: 0;
}

.template-modern1 .invoice-card {
    border-top: 3px solid var(--primary);
}

/* Classic: serif font, dark borders, traditional */
.template-classic {
    font-family: 'Times New Roman', Times, serif;
}

.template-classic .invoice-card {
    border: 2px solid #1f2937;
    border-radius: 0;
    box-shadow: none;
}

.template-classic .line-items {
    border: 1px solid #1f2937;
}

.template-classic .line-items th {
    background: #1f2937;
    color: #ffffff;
    border-bottom: 1px solid #1f2937;
    font-family: 'Times New Roman', Times, serif;
    text-transform: none;
    letter-spacing: normal;
}

.template-classic .line-items td {
    border-bottom: 1px solid #d1d5db;
}

.template-classic .card-section-title {
    font-family: 'Times New Roman', Times, serif;
    text-transform: none;
    letter-spacing: normal;
    border-bottom: 1px solid #1f2937;
    padding-bottom: 8px;
}

.template-classic .totals {
    border: 1px solid #1f2937;
    border-radius: 0;
    background: #ffffff;
}

[data-theme="dark"] .template-classic .totals {
    background: #1e293b;
}

/* Professional: blue accents, bold header block */
.template-business {
    font-family: Arial, Helvetica, sans-serif;
}

.template-business .invoice-card {
    border: none;
    border-left: 4px solid #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.template-business .line-items th {
    background: #2563eb;
    color: #ffffff;
    border-bottom: 2px solid #1d4ed8;
    font-weight: 700;
}

.template-business .line-items td {
    border-bottom: 1px solid #dbeafe;
}

[data-theme="dark"] .template-business .line-items td {
    border-bottom: 1px solid #1e3a5f;
}

.template-business .card-section-title {
    color: #2563eb;
}

.template-business .totals {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

[data-theme="dark"] .template-business .totals {
    background: #1e3a5f;
    border-color: #2563eb;
}

.template-business .add-item-btn {
    color: #2563eb;
    border-color: #93c5fd;
}

[data-theme="dark"] .template-business .add-item-btn {
    color: #93c5fd;
    border-color: #2563eb;
}

.template-business .add-item-btn:hover {
    background: #dbeafe;
    border-color: #2563eb;
}

[data-theme="dark"] .template-business .add-item-btn:hover {
    background: #1e3a5f;
    border-color: #60a5fa;
}

/* Responsive */
@media (max-width: 1024px) {
    .meta-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .invoice-card {
        padding: 28px 32px;
    }
}

@media (max-width: 768px) {
    .hero {
        padding: 32px 0 24px;
    }

    .hero h1 {
        font-size: 1.875rem;
    }

    .hero p {
        font-size: 1rem;
        padding: 0 16px;
    }

    .navbar-inner {
        height: 56px;
    }

    .navbar-title {
        font-size: 1rem;
    }

    .navbar-badge {
        display: none;
    }

    .save-status {
        display: none;
    }

    .template-section {
        padding: 20px;
    }

    .template-options {
        gap: 12px;
    }

    .template-option label {
        padding: 12px 16px;
        min-width: 100px;
    }

    .template-icon {
        width: 40px;
        height: 56px;
        font-size: 1rem;
    }

    .invoice-card {
        padding: 20px;
        border-radius: var(--radius-lg);
    }

    .invoice-card::before {
        height: 3px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .meta-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .card-section {
        margin-bottom: 28px;
        padding-bottom: 28px;
    }

    .card-section-title {
        font-size: 0.9375rem;
    }

    .line-items th,
    .line-items td {
        padding: 10px 12px;
    }

    .line-items th {
        font-size: 0.6875rem;
    }

    .action-toolbar {
        flex-direction: column;
        gap: 10px;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }

    .totals-wrapper {
        margin-top: 20px;
    }

    .totals {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 16px;
    }

    .hero {
        padding: 24px 0 20px;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .navbar {
        padding: 0 16px;
    }

    .navbar-brand {
        gap: 8px;
    }

    .navbar-logo {
        width: 32px;
        height: 32px;
    }

    .template-option label {
        min-width: 90px;
        padding: 10px 12px;
    }

    .template-icon {
        width: 36px;
        height: 48px;
    }

    .template-option span {
        font-size: 0.75rem;
    }

    .invoice-card {
        padding: 16px;
    }

    .card-section-title {
        font-size: 0.875rem;
        margin-bottom: 14px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 10px 12px;
        font-size: 0.875rem;
    }

    .line-items textarea {
        padding: 8px 10px;
        font-size: 0.875rem;
    }

    .line-items input {
        padding: 8px 10px;
        font-size: 0.875rem;
    }

    .add-item-btn {
        padding: 12px 16px;
        font-size: 0.875rem;
    }

    .action-btn {
        padding: 12px 16px;
        font-size: 0.875rem;
    }

    .totals {
        padding: 16px;
    }

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Focus visible for keyboard navigation */
.btn:focus-visible,
.theme-toggle:focus-visible,
.template-option label:focus-visible,
.delete-row-btn:focus-visible,
.toast-close:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media print {
    .navbar, .action-bar {
        display: none;
    }

    body {
        background: white;
        color: #000;
    }

    .invoice-card {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    /* Make form inputs look like rendered text when printed */
    input, textarea, select {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 0 !important;
        font-family: var(--font-sans) !important;
        color: #000 !important;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Hide placeholders when printing */
    input::placeholder, textarea::placeholder {
        color: transparent !important;
    }

    /* Hide interactive elements */
    .delete-row-btn, #add-item-btn, .theme-toggle, .save-status {
        display: none !important;
    }

    /* Hide due date preset dropdown */
    .due-date-preset {
        display: none !important;
    }

    /* Make table rows print cleanly */
    .line-items td:before {
        font-weight: 700;
    }

    /* Ensure sections are visible */
    .form-section {
        break-inside: avoid;
    }

    .totals {
        break-inside: avoid;
    }

    /* Hide logo upload area, keep preview */
    #logo-placeholder, .logo-upload {
        display: none !important;
    }
}
