/* Modern CSS with best practices */
:root {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --success-color: #10b981;
    --success-dark: #059669;
    --danger-color: #ef4444;
    --danger-dark: #dc2626;
    --secondary-color: #6b7280;
    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;

    /* Warning/Info/Error tokens */
    --warning-color: #f59e0b;
    --warning-dark: #d97706;
    --info-color: #3b82f6;
    --info-dark: #2563eb;
    --error-color: #ef4444;

    /* Spacing tokens */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography scale */
    --text-xs: 0.6875rem;
    --text-sm: 0.8125rem;
    --text-base: 0.875rem;
    --text-lg: 1rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.75rem;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
    padding: 0;
}

/* Sidebar Navigation Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: white;
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
}

.sidebar-logo svg {
    width: 28px;
    height: 28px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    padding: 8px 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

button.nav-item {
    background: none;
    border: none;
    width: 100%;
    font-family: inherit;
    font-size: inherit;
    text-align: left;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

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

.nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

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

.main-wrapper {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 32px;
    width: 100%;
}

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 16px 0;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--primary-color);
}

/* Page Sections */
.page-section {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.page-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.main-content {
    padding: 32px 0;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

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

.card-header h2 {
    margin: 0;
}

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

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.checkbox-label:hover {
    background-color: var(--bg-color);
    border-color: var(--primary-color);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"]:checked + span {
    color: var(--primary-color);
    font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-icon {
    width: 18px;
    height: 18px;
}

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

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

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

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

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

.btn-secondary:hover {
    background: var(--bg-color);
    border-color: var(--secondary-color);
}

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

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

.btn-warning {
    background: var(--warning-color);
    color: #fff;
}
.btn-warning:hover {
    background: var(--warning-dark);
}

.btn-info {
    background: var(--info-color);
    color: #fff;
}
.btn-info:hover {
    background: var(--info-dark);
}

.btn-sm {
    padding: 6px 12px;
    font-size: var(--text-sm);
}

.btn-lg {
    padding: 12px 24px;
    font-size: var(--text-lg);
}

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Webhook List */
.webhook-item {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

.webhook-item:hover {
    box-shadow: var(--shadow-md);
}

.webhook-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.webhook-url {
    font-weight: 600;
    color: var(--primary-color);
    word-break: break-all;
    flex: 1;
}

.webhook-id {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.webhook-events {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.event-badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    color: var(--secondary-color);
    opacity: 0.5;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    /* Prevent any clicks reaching elements underneath */
    pointer-events: all;
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    margin: 20px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 16px 24px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary-color);
    transform: translateX(400px);
    transition: transform 0.3s;
    z-index: 1001;
    max-width: 400px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

/* Loading Spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    margin: 20px auto;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Message */
.error-message {
    padding: 12px;
    background: #fee;
    border: 1px solid var(--danger-color);
    border-radius: var(--radius);
    color: var(--danger-color);
    margin-top: 12px;
    font-size: 14px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
}

/* Transaction List */
.transaction-item {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

.transaction-item:hover {
    box-shadow: var(--shadow-md);
}

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

.transaction-type {
    font-weight: 600;
    font-size: 14px;
}

.transaction-type.captured {
    color: var(--success-color);
}

.transaction-type.authorized {
    color: var(--primary-color);
}

.transaction-type.refunded {
    color: var(--danger-color);
}

.transaction-amount {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.transaction-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.transaction-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    .main-content {
        margin-left: 220px;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

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

    .main-wrapper {
        margin-left: 0;
    }

    .header-content {
        flex-direction: row;
        gap: 16px;
        align-items: center;
    }

    .checkbox-group {
        grid-template-columns: 1fr;
    }

    .webhook-header {
        flex-direction: column;
        gap: 12px;
    }

    .toast {
        left: 20px;
        right: 20px;
        bottom: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .container {
        padding: 0 16px;
    }
}

/* Mobile menu button */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-primary);
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
}

/* Table Styles */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table thead {
    background: var(--bg-color);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table th:last-child {
    border-right: none;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 14px;
    vertical-align: middle;
}

.data-table td:last-child {
    border-right: none;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg-color);
}

/* Responsive table */
@media (max-width: 768px) {
    .data-table {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 12px;
    }
}

/* Variance Bar Styles */
.variance-bar {
    height: 8px;
    background: var(--bg-color);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.variance-bar::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.variance-bar.excellent::after {
    background-color: #10b981;
}

.variance-bar.good::after {
    background-color: #3b82f6;
}

.variance-bar.warning::after {
    background-color: #f59e0b;
}

.variance-bar.critical::after {
    background-color: #ef4444;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    z-index: 100;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bg-color) 25%, #e8e8e8 50%, var(--bg-color) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius);
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Toast accessibility */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
}
[role="status"] {
    /* For screen readers */
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Better scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
