:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
}

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

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

.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1rem; }

/* Nav */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    margin-bottom: 2rem;
}
nav .nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 1.5rem;
    align-items: center;
}
nav a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}
nav a:hover, nav a.active {
    background: var(--primary);
    color: white;
}
nav .brand {
    font-weight: 700;
    font-size: 1.1rem;
    margin-right: 1rem;
}

/* Cards */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
}
.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-card .label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    background: #f1f5f9;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
}
td { font-size: 0.9rem; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-webhook { background: #dbeafe; color: #1d4ed8; }
.badge-app { background: #ede9fe; color: #7c3aed; }
.badge-sent { background: #dcfce7; color: #16a34a; }
.badge-failed { background: #fee2e2; color: #dc2626; }
.badge-pending { background: #fef3c7; color: #d97706; }

/* Forms */
form { margin-bottom: 1.5rem; }
.form-group {
    margin-bottom: 1rem;
}
label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}
input, select, textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
textarea { min-height: 100px; font-family: monospace; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

/* Section */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.section h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* Test results */
.test-result {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-top: 0.5rem;
}
.test-result.ok { background: #dcfce7; color: #16a34a; }
.test-result.error { background: #fee2e2; color: #dc2626; }

/* Preview */
.preview {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-top: 0.5rem;
}
.preview pre {
    white-space: pre-wrap;
    font-size: 0.8rem;
    max-height: 300px;
    overflow: auto;
}

/* Grid for form + table side by side */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* Action buttons in table */
.actions { display: flex; gap: 0.5rem; }

/* Source chips */
.chip {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    vertical-align: middle;
    margin-left: 0.25rem;
}
.chip-db { background: #dbeafe; color: #1d4ed8; }
.chip-env { background: #dcfce7; color: #16a34a; }
.chip-unset { background: #f1f5f9; color: #64748b; }

/* Detail panel */
.detail-panel {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin: 0.5rem 0;
}

/* Inline filter bar */
.filter-bar {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

/* Copy box */
.copy-box {
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    font-family: monospace;
    font-size: 0.8rem;
    word-break: break-all;
    margin: 0.5rem 0;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.modal-overlay.show {
    display: flex;
}
.modal {
    background: var(--surface);
    border-radius: 12px;
    max-width: 800px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    border-radius: 12px 12px 0 0;
    z-index: 1;
}
.modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}
.modal-close:hover {
    background: var(--border);
    color: var(--text);
}
.modal-body {
    padding: 1.5rem;
}
.modal-body .kv-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.5rem 1rem;
    margin-bottom: 1.5rem;
}
.modal-body .kv-grid .kv-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.825rem;
}
.modal-body .kv-grid .kv-value {
    font-size: 0.9rem;
}
.modal-body .json-block {
    margin-bottom: 1.5rem;
}
.modal-body .json-block h4 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-body .json-block pre {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.8rem;
    line-height: 1.5;
    overflow: auto;
    max-height: 350px;
    white-space: pre;
}
.modal-body .delivery-result {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}
.modal-body .delivery-result h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}
