/* RKInvoice Multi-Tenant Styles */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f4f3fb;
    --card-bg: #ffffff;
    --text-color: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

html {
    min-height: 100%;
    background: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    color: var(--text-color);
    background: transparent;
    line-height: 1.6;
    min-height: 100vh;
}

/* Decorative backdrop — a real node so it cannot fall behind <html> */
.page-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 70% 55% at 8% 12%, rgba(129, 140, 248, 0.55), transparent 58%),
        radial-gradient(ellipse 55% 50% at 92% 8%, rgba(167, 139, 250, 0.48), transparent 52%),
        radial-gradient(ellipse 60% 45% at 88% 88%, rgba(56, 189, 248, 0.28), transparent 55%),
        radial-gradient(ellipse 50% 40% at 12% 82%, rgba(244, 114, 182, 0.16), transparent 50%),
        radial-gradient(ellipse 40% 30% at 50% 48%, rgba(199, 210, 254, 0.45), transparent 70%),
        linear-gradient(165deg, #ece8ff 0%, #e4eaf8 48%, #efe7fb 100%);
}

.page-backdrop::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            -22deg,
            transparent 0,
            transparent 46px,
            rgba(79, 70, 229, 0.045) 46px,
            rgba(79, 70, 229, 0.045) 47px
        ),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
    background-size: auto, 180px 180px;
}

/* Screen Management */
.screen {
    display: none !important;
    position: relative;
    z-index: 1;
}

.screen.active {
    display: block !important;
}

/* Auth screens: chrome lives in landing.css */
#loginScreen.active,
#registerScreen.active,
#setPasswordScreen.active,
#termsScreen.active,
#pricingScreen.active {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

#registerScreen .login-container {
    max-width: 520px;
}

.logo {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

.logo h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.logo p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.login-card {
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow: 0 24px 48px -12px rgba(15, 23, 42, 0.35);
}

.login-card h2 {
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.demo-info {
    margin-top: 2rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 8px;
    font-size: 0.9rem;
}

.demo-info h4 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.demo-info p {
    margin: 0.25rem 0;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input[readonly] {
    background: var(--bg-color);
    color: var(--text-secondary);
    cursor: default;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-row .flex-1 { flex: 1; }
.form-row .flex-2 { flex: 2; }

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.btn-small.btn-tiny {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    min-width: auto;
}

.btn-remove {
    background: var(--danger-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* App Layout */
#appScreen.active {
    min-height: 100vh;
}

.app-header {
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(18px) saturate(1.35);
    -webkit-backdrop-filter: blur(18px) saturate(1.35);
    border-bottom: 1px solid rgba(229, 231, 235, 0.7);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 50;
}

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

.header-left h1 {
    font-size: 1.5rem;
}

.tenant-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.tenant-server-badge {
    background: #e0e7ff;
    color: #3730a3;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-server {
    text-transform: none;
    font-weight: 600;
}

.badge-server-master {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-server-data {
    background: #fef3c7;
    color: #92400e;
}

.tenants-server-overview {
    margin: 0 1rem 1.25rem;
}

.tenants-server-overview-title {
    font-size: 1rem;
    margin: 0 0 0.5rem;
}

.backend-servers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.35rem;
}

.backend-servers-header .tenants-server-overview-title {
    margin: 0;
}

.backend-server-add-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 0.75rem;
}

.backend-server-add-form input[type="url"],
.backend-server-add-form input[type="text"] {
    padding: 0.45rem 0.65rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}

.backend-server-add-form input[type="url"] {
    flex: 1 1 16rem;
    min-width: 12rem;
}

.backend-server-add-form input[type="text"] {
    flex: 0 1 10rem;
}

#backendServersStatus {
    margin: 0 0 0.75rem;
}

#backendServersStatus.is-error {
    color: #b91c1c;
}

#backendServersStatus.is-ok {
    color: #166534;
}

.tenants-server-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.9rem;
}

.tenants-server-table th,
.tenants-server-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.tenants-server-table th {
    background: #f9fafb;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.openapi-menu {
    position: relative;
    z-index: 60;
}

.openapi-menu-summary {
    list-style: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary-color);
    padding: 0.35rem 0.75rem;
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.7);
}

.openapi-menu-summary::after {
    content: " ▾";
    font-size: 0.75em;
}

.openapi-menu.is-open .openapi-menu-summary {
    background: #eef2ff;
}

.openapi-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 0.35rem 0;
    z-index: 70;
}

.openapi-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 0.9rem;
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
}

.openapi-menu-item:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.openapi-version-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.openapi-version-tabs .btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.openapi-swagger {
    background: #fff;
    border-radius: 8px;
    margin: 0 1rem 1.5rem;
    min-height: 70vh;
    overflow: auto;
}

.openapi-swagger .topbar {
    display: none;
}

.openapi-docs-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.openapi-docs-links a {
    display: inline-block;
    font-weight: 600;
    color: var(--primary-color);
}

.user-name {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Navigation */
.app-nav {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(18px) saturate(1.35);
    -webkit-backdrop-filter: blur(18px) saturate(1.35);
    border-bottom: 1px solid rgba(229, 231, 235, 0.7);
    padding: 0 2rem;
    display: flex;
    gap: 0.5rem;
}

.nav-item {
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--bg-color);
}

.nav-item.active {
    border-bottom-color: var(--primary-color);
    color: var(--primary-color);
}

/* Main Content */
.app-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.view-header h2 {
    font-size: 2rem;
}

.view-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.view-tenant-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.65rem 1.5rem;
    background: #fef3c7;
    border-bottom: 1px solid #f59e0b;
    color: #92400e;
    font-size: 0.95rem;
}

.view-tenant-banner[hidden] {
    display: none !important;
}

.view-tenant-banner-server {
    margin-left: 0.5rem;
    font-size: 0.85rem;
    opacity: 0.85;
}

/* Statistics view */
.statistics-content {
    padding: 1rem 0;
}
.statistics-section {
    margin-bottom: 2rem;
}
.statistics-section h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}
.statistics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.statistics-table th,
.statistics-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.statistics-table th {
    font-weight: 600;
    background: var(--bg-color);
}
.table-responsive {
    overflow-x: auto;
}

.statistics-charts {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
    max-width: 100%;
}
.statistics-chart-section {
    width: 100%;
    max-width: 100%;
}
.statistics-chart-section h3 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
    color: var(--text-secondary);
}
.statistics-chart-section .table-responsive {
    width: 100%;
    max-width: 100%;
}
.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.filters {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.filters select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

/* Compact pagination arrows in header */
.compact-pagination {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    margin-left: 0.5rem;
}

.btn-pagination-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.btn-pagination-arrow:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-pagination-arrow:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--bg-color);
}

/* Invoice list month navigation (havi nézet) */
.invoice-month-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.invoice-month-nav select {
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
}
.invoice-month-nav .btn-pagination-arrow {
    padding: 0.25rem 0.5rem;
}

.invoice-direction-toggle {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

/* Author display would otherwise override the HTML hidden attribute. */
.invoice-direction-toggle[hidden] {
    display: none !important;
}

.invoice-dir-btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.inbound-fetch-status {
    font-size: 0.85rem;
    color: var(--text-muted, #6b7280);
    max-width: 18rem;
}

.invoice-row-inbound {
    background-color: #f8fafc;
    border-left: 4px solid #64748b;
}

/* Invoice List */
.invoices-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.invoices-list.compact-mode {
    display: block;
    grid-template-columns: none;
    gap: 0;
}

/* Compact Invoice List */
.invoices-compact-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.invoice-row-compact {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s, transform 0.1s;
    cursor: pointer;
}

.invoice-row-desktop {
    display: grid;
    grid-template-columns: 80px 150px 1fr 120px 120px 100px;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    align-items: center;
    font-size: 0.8rem;
    line-height: 1.2;
}

.invoice-row-mobile {
    display: none;
}

.invoice-row-compact:last-child {
    border-bottom: none;
}

.invoice-row-compact:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateX(2px);
}

/* Color coding for invoice types */
.invoice-row-invoice {
    background-color: #f0fdf4; /* Light green */
    border-left: 4px solid #10b981; /* Green */
}

.invoice-row-proforma {
    background-color: #eff6ff; /* Light blue */
    border-left: 4px solid #3b82f6; /* Blue */
}

.invoice-row-storno {
    background-color: #fff7ed; /* Light orange */
    border-left: 4px solid #f97316; /* Orange */
}

.invoice-row-advance {
    background-color: #f5f3ff;
    border-left: 4px solid #7c3aed;
}

.invoice-row-modification {
    background-color: #fffbeb;
    border-left: 4px solid #d97706;
}

.invoice-row-modified-base {
    background-color: #f7fee7;
    border-left: 4px solid #ca8a04;
}

.chain-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.3rem;
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
    vertical-align: middle;
    white-space: nowrap;
}

.chain-badge-modified {
    background-color: #fef3c7;
    color: #92400e;
}

.chain-badge-stornoed {
    background-color: #ffedd5;
    color: #9a3412;
}

.chain-badge-delta {
    background-color: #fff7ed;
    color: #b45309;
}

.invoice-row-nav-status {
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-status-compact {
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    background-color: #e5e7eb;
    color: #374151;
    white-space: nowrap;
}

.nav-status-compact.nav-status-done {
    background-color: #d1fae5;
    color: #047857;
}

.invoice-row-number {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.invoice-row-buyer {
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8rem;
}

.invoice-row-date {
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
}

.invoice-row-amount {
    font-weight: 600;
    color: var(--success-color);
    text-align: right;
    font-size: 0.8rem;
    white-space: nowrap;
}

.invoice-row-status {
    font-size: 0.7rem;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    text-align: center;
    background-color: #e5e7eb;
    color: #374151;
    white-space: nowrap;
}


/* Responsive adjustments for compact view */
@media (max-width: 1200px) {
    .invoice-row-compact {
        grid-template-columns: 70px 120px 1fr 100px 100px 80px;
        gap: 0.5rem;
        padding: 0.35rem 0.5rem;
    }
    
    .invoice-row-number,
    .invoice-row-buyer,
    .invoice-row-date,
    .invoice-row-amount {
        font-size: 0.8rem;
    }
}

@media (max-width: 768px) {
    .invoice-row-desktop {
        display: none;
    }
    
    .invoice-row-mobile {
        display: block;
        padding: 0.15rem 0.4rem;
        font-size: 0.6rem;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .invoice-row-mobile .nav-status-compact {
        display: inline-block;
        padding: 0.05rem 0.2rem;
        margin-right: 0.25rem;
        vertical-align: middle;
        font-size: 0.55rem;
    }
    
    .invoice-mobile-number {
        font-weight: 600;
        margin-right: 0.25rem;
    }
    
    .invoice-mobile-buyer {
        margin-right: 0.25rem;
    }
    
    .invoice-mobile-date {
        color: var(--text-secondary);
        margin-right: 0.25rem;
    }
    
    .invoice-mobile-amount {
        font-weight: 600;
        color: var(--success-color);
    }
}

.invoice-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.invoice-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.invoice-number {
    font-weight: 600;
    font-size: 1.1rem;
}

.invoice-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-draft { background: #e5e7eb; color: #374151; }
.status-submitted { background: #dbeafe; color: #1e40af; }
.status-done { background: #d1fae5; color: #047857; }
.status-failed { background: #fee2e2; color: #991b1b; }

.invoice-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.invoice-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.invoice-detail label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.invoice-detail .amount {
    font-weight: 600;
    color: var(--success-color);
    font-size: 1.1rem;
}

.transaction-id {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.invoice-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Invoice Form */
.invoice-form {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.12), var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

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

.form-section h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.invoice-item {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

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

.item-header h4 {
    color: var(--text-secondary);
}

.invoice-totals {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 2rem 0;
}

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

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

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Pagination */
.pagination {
    margin-top: 2rem;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.page-info {
    color: var(--text-secondary);
}

/* Messages */
.tax-number-error {
    display: block;
    color: #991b1b;
    margin-top: 0.25rem;
}

.tax-number-error[hidden] {
    display: none;
}

.correct-buyer-tax-form {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-width: 22rem;
}

.correct-buyer-tax-form[hidden] {
    display: none;
}

.correct-buyer-tax-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

.success-message {
    background: #d1fae5;
    color: #047857;
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

/* Form sections for register */
.form-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

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

.form-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--text-color);
}

.terms-box {
    max-height: 180px;
    overflow-y: auto;
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.terms-box p {
    margin: 0 0 0.75rem 0;
}

.terms-box p:last-child {
    margin-bottom: 0;
}

.terms-accept {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
    cursor: pointer;
}

.terms-accept input[type="checkbox"] {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.form-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.9rem;
}

.form-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

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

.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 3rem;
    background: white;
    border-radius: 8px;
}

/* API View */
.api-content {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.api-info h3 {
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.api-info h3:first-child {
    margin-top: 0;
}

.code-block {
    background: #1f2937;
    color: #f9fafb;
    padding: 1rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    display: block;
    overflow-x: auto;
}

code {
    background: var(--bg-color);
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.note {
    background: #fef3c7;
    border-left: 4px solid var(--warning-color);
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 4px;
}

/* ==================== Customers ==================== */
.customers-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.customer-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s ease;
}

.customer-card:hover {
    box-shadow: var(--shadow-lg);
}

.customer-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.customer-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-color);
}

.customer-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.customer-detail {
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.customer-detail label {
    color: var(--text-secondary);
    min-width: 80px;
}

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

.badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-weight: 500;
}

.badge-private {
    background: #dbeafe;
    color: #1e40af;
}

.search-input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    min-width: 250px;
}

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

.invoice-search-filters .search-input {
    min-width: 320px;
    flex: 1;
    max-width: 520px;
}

.invoice-search-month-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.invoice-search-month-wrap[hidden] {
    display: none !important;
}

.invoice-search-month-label {
    font-size: 0.85rem;
    color: var(--text-secondary, #64748b);
    white-space: nowrap;
}

.invoice-search-month-select {
    min-width: 160px !important;
    max-width: 200px !important;
    flex: 0 0 auto !important;
}

.invoice-search-hint {
    margin: 0 0 1rem;
    color: var(--text-secondary, #64748b);
    font-size: 0.9rem;
}

.invoice-search-hint.month-required {
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: 0.6rem 0.85rem;
}

.invoice-search-hint code {
    background: var(--bg-secondary, #f1f5f9);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.invoice-search-bulk {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0 0 0.75rem;
}

.invoice-search-bulk[hidden] {
    display: none !important;
}

.invoice-search-select-all {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.invoice-search-check-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    cursor: pointer;
}

.invoice-search-check,
.invoice-search-select-all input {
    width: 1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
}

.invoice-search-zip-status {
    font-size: 0.85rem;
    color: var(--text-secondary, #64748b);
}

.invoice-row-compact.has-select {
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
}

.invoice-number .invoice-search-check-label {
    margin-right: 0.45rem;
    vertical-align: middle;
}

.search-year-badge {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
    margin-left: 0.35rem;
}

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

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-content .modal-body {
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    /* Keep the title and close (X) button always visible while the modal
       body is scrolled. The header is the first child of the scrolling
       .modal-content, so position: sticky pins it to the top. */
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 2;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger-color);
}

.modal-content form {
    padding: 1.5rem;
}

.modal-content .form-section h4 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Button variants */
.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .app-nav {
        overflow-x: auto;
    }
    
    .invoices-list,
    .customers-list {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .filters {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .search-input {
        min-width: unset;
        width: 100%;
    }
    
    /* Invoice detail view - mobile optimizations */
    .invoice-detail-view {
        padding: 0.3rem;
    }
    
    .detail-section {
        margin-bottom: 1rem;
    }
    
    .detail-section h4 {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
        padding-bottom: 0.25rem;
    }
    
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .detail-grid label {
        font-size: 0.7rem;
    }
    
    .detail-grid span {
        font-size: 0.75rem;
    }
    
    /* Invoice items table - mobile */
    .invoice-items-table {
        font-size: 0.65rem;
    }
    
    .invoice-items-table th,
    .invoice-items-table td {
        padding: 0.25rem 0.15rem;
        font-size: 0.65rem;
    }
    
    .invoice-items-table th {
        font-size: 0.6rem;
        font-weight: 600;
    }
    
    /* NAV XML Response - mobile */
    .nav-xml-response {
        font-size: 0.5rem;
        padding: 0.5rem;
        max-height: 200px;
    }
    
    /* Modal adjustments for mobile - much narrower */
    .modal {
        padding: 0.05rem;
    }
    
    .modal-content {
        max-width: 92%;
        max-height: 98vh;
        border-radius: 4px;
    }
    
    .modal-content.modal-large {
        max-width: 92%;
    }
    
    .modal-header {
        padding: 0.3rem;
    }
    
    .modal-header h3 {
        font-size: 0.75rem;
    }
    
    .modal-body {
        padding: 0.3rem;
    }
    
    .invoice-detail-view {
        padding: 0.3rem;
    }
}

/* ==================== User Management ==================== */
.users-content {
    padding: 1.5rem;
}

.users-list {
    display: grid;
    gap: 1rem;
}

.directory-search {
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0 0 0.75rem;
    box-sizing: border-box;
}

.directory-summary {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 0.6rem;
}

.directory {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.directory-server {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.directory-server-head,
.directory-tenant-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    border: 0;
    background: #f9fafb;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    padding: 0.65rem 0.9rem;
}

.directory-server-head:hover,
.directory-tenant-head:hover {
    background: #f3f4f6;
}

.directory-server-head {
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.directory-tenant {
    border-top: 1px solid #e5e7eb;
}

.directory-tenant:first-child {
    border-top: 0;
}

.directory-tenant.is-open > .directory-tenant-head {
    background: #f8fafc;
}

.directory-tenant-name {
    font-weight: 600;
    flex: 1 1 12rem;
    min-width: 8rem;
}

.directory-tenant-tax,
.directory-tenant-count,
.directory-row-meta,
.directory-row-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.directory-tenant-tax {
    flex: 0 1 8rem;
}

.directory-tenant-count {
    flex: 0 0 auto;
    white-space: nowrap;
}

.directory-tenant-head .user-badges {
    margin-left: auto;
}

.directory-chevron {
    flex: 0 0 1rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.directory-tenant-body {
    padding: 0.75rem 0.9rem 1rem 2rem;
    background: #fafafa;
    border-top: 1px solid #e5e7eb;
}

.directory-subhead {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 0.9rem 0 0.4rem;
}

.directory-empty {
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
}

.directory-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.55rem 0.7rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 0.4rem;
}

.directory-row-main {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 12rem;
    flex: 1 1 14rem;
}

.directory-row-title {
    font-weight: 600;
}

.directory-row-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    flex: 1 1 12rem;
}

.directory-row-side .user-actions {
    justify-content: flex-end;
}

@media (max-width: 768px) {
    .directory-tenant-head,
    .directory-server-head {
        flex-wrap: wrap;
    }

    .directory-tenant-body {
        padding-left: 0.9rem;
    }

    .directory-row-side {
        align-items: stretch;
    }

    .directory-row-side .user-actions {
        justify-content: flex-start;
    }
}

.user-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.2s;
}

.user-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

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

.user-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    display: block;
    margin-bottom: 0.25rem;
}

.user-email {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: block;
}

.user-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.badge-admin {
    background: #dbeafe;
    color: #1e40af;
}

.badge-super_admin {
    background: #fef3c7;
    color: #92400e;
}

.badge-user {
    background: #e5e7eb;
    color: #374151;
}

.badge-accountant {
    background: #ccfbf1;
    color: #0f766e;
}

.form-hint {
    color: #4b5563;
    font-size: 0.9rem;
    margin: 0 0 1rem;
    line-height: 1.4;
}

.advance-settle-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 12rem;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.advance-settle-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.badge-active {
    background: #d1fae5;
    color: #047857;
}

.badge-inactive {
    background: #fee2e2;
    color: #991b1b;
}

.user-body {
    margin-bottom: 1rem;
}

.user-detail {
    display: flex;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.user-detail label {
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 120px;
}

.user-detail span {
    color: var(--text-color);
}

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

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

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-danger:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* ==================== Settings View ==================== */
.settings-subnav {
    display: flex;
    gap: 0.5rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.settings-subnav-item {
    flex: 0 0 auto;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font: inherit;
    padding: 0.85rem 0.75rem;
    white-space: nowrap;
}

.settings-subnav-item:hover,
.settings-subnav-item.active {
    color: var(--primary-color);
}

.settings-subnav-item.active {
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.settings-content [data-settings-panel][hidden] {
    display: none;
}

.settings-content > form > h3[data-settings-panel] {
    margin: 0 0 1rem;
}

.settings-content {
    padding: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
}

@media (max-width: 600px) {
    .settings-subnav {
        padding: 0 0.75rem;
    }

    .settings-content {
        padding: 1rem 0.75rem;
    }
}

.settings-content .form-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.settings-content .form-section h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
    font-size: 1.1rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.settings-content .form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.settings-content .form-actions {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ==================== API Key Display ==================== */
.api-key-display {
    padding: 1.5rem;
    text-align: center;
}

.api-key-display p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.api-key-value {
    background: #f3f4f6;
    border: 2px dashed var(--primary-color);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    word-break: break-all;
    color: var(--text-color);
    font-weight: 600;
    user-select: all;
}

/* ==================== Invoice Detail View ==================== */
.invoice-detail-view {
    padding: 1.5rem;
}

.detail-section {
    margin-bottom: 2rem;
}

.detail-section h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.detail-grid > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-grid label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.detail-grid span {
    color: var(--text-color);
    font-size: 1rem;
}

/* NAV XML Response styling */
.nav-xml-response {
    font-size: 0.7rem;
    line-height: 1.4;
    background-color: #f5f5f5;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    color: #333;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Invoice items table styling */
.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.invoice-items-table th,
.invoice-items-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.invoice-items-table th {
    background-color: var(--bg-color);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.invoice-items-table tbody tr:hover {
    background-color: #f9fafb;
}

.invoice-items-table tfoot {
    font-weight: 600;
    background-color: var(--bg-color);
}

/* Invoice number link styling */
.invoice-link {
    color: var(--primary-color);
    text-decoration: underline;
    cursor: pointer;
    font-weight: 500;
    transition: color 0.2s;
}

.invoice-link:hover {
    color: var(--primary-dark);
    text-decoration: none;
}

/* Export modal */
.export-format-options {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.export-format-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: normal;
    cursor: pointer;
}

.export-months-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.export-months-checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: normal;
    cursor: pointer;
}

.export-progress-container {
    margin: 1rem 0;
}

.export-progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.export-progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.2s ease;
}

.export-progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.export-message {
    margin-top: 0.5rem;
    min-height: 1.25rem;
    font-size: 0.875rem;
}

.export-message.error {
    color: var(--danger-color);
}

.export-message.success {
    color: var(--success-color);
}
.billing-modal-content { max-width: 1100px; width: calc(100% - 2rem); }
.billing-table-scroll { overflow-x: auto; margin: 1.2rem 0; }
.billing-history { width: 100%; border-collapse: collapse; font-size: .88rem; }
.billing-history th, .billing-history td { padding: .65rem; text-align: left; border-bottom: 1px solid #ddd; vertical-align: top; }
.billing-history td:last-child { overflow-wrap: anywhere; min-width: 9rem; }
.provision-panel { margin: 1rem 0; padding: 1rem; border: 1px solid var(--border-color, #ddd); border-radius: 8px; }
.provision-panel summary { cursor: pointer; font-weight: 600; }
.provision-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.provision-form label { display: flex; flex-direction: column; gap: .4rem; }
.provision-form input:not([type="checkbox"]) { width: 100%; padding: .6rem; box-sizing: border-box; }
.provision-form input[type="checkbox"] { align-self: flex-start; }
.provision-form .form-hint { grid-column: 1 / -1; }
