:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

* { 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.5;
}

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

.sidebar {
    width: 220px;
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px 0;
    flex-shrink: 0;
}

.sidebar h1 {
    font-size: 16px;
    padding: 0 20px 20px;
    border-bottom: 1px solid #334155;
    margin-bottom: 10px;
}

.sidebar a {
    display: block;
    padding: 10px 20px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.sidebar a:hover, .sidebar a.active {
    background: #334155;
    color: #ffffff;
}

.main-content {
    flex: 1;
    padding: 30px;
    max-width: 1200px;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-box {
    background: var(--surface);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 360px;
}

.login-box h1 {
    font-size: 22px;
    margin-bottom: 24px;
    text-align: center;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-muted);
}

input, select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus {
    border-color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

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

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

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

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

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

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

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-block {
    display: block;
    width: 100%;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

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

.card-header h2 {
    font-size: 18px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover {
    background: #f9fafb;
}

tr.dragging {
    opacity: 0.5;
    background: #dbeafe;
}

tr.drag-over {
    border-top: 2px solid var(--primary);
}

/* Toggle switch */
.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

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

.toggle .slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 11px;
    transition: background 0.2s;
}

.toggle .slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle input:checked + .slider {
    background: var(--success);
}

.toggle input:checked + .slider::before {
    transform: translateX(18px);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green {
    background: #dcfce7;
    color: #166534;
}

.badge-gray {
    background: #f3f4f6;
    color: #6b7280;
}

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

/* Conditions list */
.conditions-list {
    list-style: none;
}

.conditions-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.conditions-list select,
.conditions-list input {
    width: auto;
    flex: 1;
}

.conditions-list .field-select { width: 150px; flex: none; }
.conditions-list .match-select { width: 120px; flex: none; }

/* Error */
.error-msg {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}

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

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

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

.stat-card .label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    padding: 24px;
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 {
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* Drag handle */
.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    user-select: none;
}

.drag-handle:active {
    cursor: grabbing;
}
