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

/* Light Theme (default) */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #eab308;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --modal-backdrop: rgba(0, 0, 0, 0.4);
    --input-bg: #ffffff;
    --code-bg: #f1f5f9;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.15);
    --warning: #eab308;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.15);
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --modal-backdrop: rgba(0, 0, 0, 0.7);
    --input-bg: #1e293b;
    --code-bg: #0f172a;
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --success: #22c55e;
        --success-bg: rgba(34, 197, 94, 0.15);
        --warning: #eab308;
        --error: #ef4444;
        --error-bg: rgba(239, 68, 68, 0.15);
        --bg: #0f172a;
        --card: #1e293b;
        --border: #334155;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        --modal-backdrop: rgba(0, 0, 0, 0.7);
        --input-bg: #1e293b;
        --code-bg: #0f172a;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
}

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

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 18px;
    font-weight: 600;
}

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

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}

.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--error); }

/* Buttons */
.btn {
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn:hover { opacity: 0.9; }

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

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

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

.btn-sm {
    padding: 4px 8px;
    font-size: 11px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--card);
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.stat-card h3 {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
}

/* Sections */
.section {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
}

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

.section-header h2 {
    font-size: 14px;
    font-weight: 600;
}

/* Webhooks List */
.webhooks-list, .endpoints-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.webhook-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.15s;
}

.webhook-item:hover {
    border-color: var(--primary);
}

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

.webhook-id {
    font-family: monospace;
    font-size: 12px;
    color: var(--muted);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.webhook-status {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Status badges - light mode defaults */
.status-pending { background: #fef3c7; color: #92400e; }
.status-completed { background: #dcfce7; color: #166534; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-partial_failed { background: #fed7aa; color: #9a3412; }

/* Status badges - dark mode */
[data-theme="dark"] .status-pending { background: rgba(234, 179, 8, 0.2); color: #fbbf24; }
[data-theme="dark"] .status-completed { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
[data-theme="dark"] .status-failed { background: rgba(239, 68, 68, 0.2); color: #f87171; }
[data-theme="dark"] .status-partial_failed { background: rgba(249, 115, 22, 0.2); color: #fb923c; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .status-pending { background: rgba(234, 179, 8, 0.2); color: #fbbf24; }
    :root:not([data-theme="light"]) .status-completed { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
    :root:not([data-theme="light"]) .status-failed { background: rgba(239, 68, 68, 0.2); color: #f87171; }
    :root:not([data-theme="light"]) .status-partial_failed { background: rgba(249, 115, 22, 0.2); color: #fb923c; }
}

.webhook-info {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--muted);
    grid-column: 1 / -1;
}

.webhook-info span {
    display: flex;
    gap: 4px;
}

.webhook-dispatches {
    grid-column: 1 / -1;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.dispatch-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dispatch-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--card);
    border-radius: 4px;
    font-size: 11px;
    border: 1px solid var(--border);
    cursor: default;
}

.dispatch-badge.success {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.3);
}

.dispatch-badge.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

.dispatch-status {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dispatch-status.success { background: var(--success); }
.dispatch-status.error { background: var(--error); }

.dispatch-endpoint {
    font-weight: 600;
    color: var(--text);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dispatch-code {
    font-family: monospace;
    font-weight: 600;
}

.dispatch-badge.success .dispatch-code { color: var(--success); }
.dispatch-badge.error .dispatch-code { color: var(--error); }

.dispatch-time {
    color: var(--muted);
    font-size: 10px;
}

/* Endpoints */
.endpoint-item {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

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

.endpoint-name {
    font-size: 13px;
    font-weight: 600;
}

.endpoint-url {
    font-family: monospace;
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 8px;
}

.endpoint-actions {
    display: flex;
    gap: 6px;
}

.endpoint-stats {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--muted);
}

.endpoint-toggle {
    position: relative;
    width: 36px;
    height: 20px;
}

.endpoint-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--muted);
    border-radius: 20px;
    transition: 0.2s;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

input:checked + .toggle-slider { background: var(--success); }
input:checked + .toggle-slider:before { transform: translateX(16px); }

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-backdrop);
    z-index: 100;
}

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

.modal-content {
    background: var(--card);
    border-radius: 8px;
    width: 90%;
    max-width: 440px;
    max-height: 90vh;
    overflow: hidden;
}

.modal-content.large {
    max-width: 640px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 14px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

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

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

/* Forms */
#endpointForm {
    padding: 16px;
}

.form-group {
    margin-bottom: 12px;
    padding: 0;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--input-bg);
    color: var(--text);
}

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

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
}

/* Webhook Details */
#webhookDetails {
    padding: 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-section h3 {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--muted);
    text-transform: uppercase;
}

.detail-grid {
    display: grid;
    gap: 4px;
}

.detail-row {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
}

.detail-label {
    color: var(--muted);
}

.detail-value {
    font-family: monospace;
    word-break: break-all;
}

pre {
    background: var(--code-bg);
    padding: 10px;
    border-radius: var(--radius);
    font-size: 11px;
    overflow-x: auto;
    border: 1px solid var(--border);
    color: var(--text);
}

/* Pagination */
.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.pagination-info {
    display: flex;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.pagination-separator { color: var(--border); }

.pagination-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Utilities */
.loading, .empty-state {
    text-align: center;
    padding: 32px;
    color: var(--muted);
}

.empty-state-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    cursor: pointer;
    transition: all 0.2s;
    color: var(--muted);
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

/* Hide icons based on theme */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

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

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

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

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}
