/* assets/css/rules.css */

.page-wrap {
    max-width: 860px;
    margin: 0 auto;
    padding: 72px 24px 60px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 600; margin-bottom: 2px; }
.page-sub { font-size: 13.5px; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────── */
.btn {
    font-family: inherit; font-size: 13px; font-weight: 500;
    padding: 8px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-dark); background: var(--white);
    color: var(--text); cursor: pointer; transition: all .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-danger-sm { font-size: 12px; padding: 5px 10px; color: var(--danger); border-color: var(--danger-border); }
.btn-danger-sm:hover { background: var(--danger-bg); }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 15px; color: var(--text-muted); padding: 4px 6px; border-radius: var(--radius-sm); }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-icon.small { font-size: 13px; padding: 2px 4px; }

/* ── Legend ────────────────────────────────────── */
.legend {
    display: flex; gap: 20px; margin-bottom: 16px;
    font-size: 12.5px; color: var(--text-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot.red { background: #ef4444; }
.dot.green { background: #22c55e; }
.dot.gray { background: #c8ccd4; }

/* ── Filters ──────────────────────────────────── */
.filters { display: flex; gap: 10px; margin-bottom: 20px; }
.filters select {
    font-family: inherit; font-size: 13px; padding: 7px 10px;
    border: 1px solid var(--border-dark); border-radius: var(--radius-sm);
    background: var(--white); color: var(--text); outline: none; cursor: pointer;
}
.filters select:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(17,19,24,.08); }

/* ── Loading / Empty ──────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 0; color: var(--text-muted); font-size: 13.5px; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 0; color: var(--text-faint); font-size: 14px; }

/* ── Section headers ──────────────────────────── */
.section-header { margin: 24px 0 12px; }
.section-header:first-child { margin-top: 0; }
.section-header h2 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.section-header p { font-size: 12.5px; color: var(--text-faint); }

/* ── Rule cards ───────────────────────────────── */
.rules-list { display: flex; flex-direction: column; gap: 6px; }

.rule-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow .15s, opacity .15s;
}
.rule-card:hover { box-shadow: var(--shadow-md); }
.rule-card.deny  { border-left-color: #ef4444; }
.rule-card.allow { border-left-color: #22c55e; }
.rule-card.off   { opacity: .5; border-left-color: #c8ccd4; }

.rule-top {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 18px;
}

.rule-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.rule-summary {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 6px;
}
.text-red   { color: #ef4444; font-weight: 600; }
.text-green { color: #22c55e; font-weight: 600; }

/* ── Conditions (readable sentences) ──────────── */
.conditions {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.cond-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    margin-right: 4px;
}
.cond-list {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 0;
}
.cond-list li {
    font-size: 13px;
    color: var(--text-muted);
    padding: 2px 0;
    width: 100%;
}
.cond-list li strong {
    color: var(--text);
    font-weight: 500;
}
.cond-join {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-faint);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 1px 5px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: 1px;
}

.rule-note {
    font-size: 12px;
    color: var(--text-faint);
    font-style: italic;
    margin-top: 4px;
}

/* ── Right side: toggle ───────────────────────── */
.rule-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    padding-top: 2px;
}

.toggle-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-faint);
}

.toggle { position: relative; display: inline-block; width: 38px; height: 22px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute; inset: 0; background: var(--border-dark);
    border-radius: 11px; transition: background .2s;
}
.toggle-slider::before {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 16px; height: 16px; background: var(--white);
    border-radius: 50%; transition: transform .2s;
    box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.toggle input:checked + .toggle-slider { background: #10b981; }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Expanded bottom bar ──────────────────────── */
.rule-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 18px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-size: 12px;
}
.rule-id, .rule-priority {
    color: var(--text-faint);
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 11px;
    margin-right: 4px;
}

/* ── Condition preview (in modal) ─────────────── */
.cond-preview {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
    color: var(--text-muted);
}
.cond-preview strong { color: var(--text); font-weight: 500; }

/* ── Modal ────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 200; display: flex; align-items: center;
    justify-content: center; padding: 24px;
}
.modal {
    background: var(--white); border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 0;
}
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-muted); cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px 24px; }

/* ── Forms ────────────────────────────────────── */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea {
    width: 100%; padding: 8px 10px; font-size: 13px; font-family: inherit;
    color: var(--text); border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm); background: var(--white); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    border-color: var(--text); box-shadow: 0 0 0 3px rgba(17,19,24,.08);
}
.form-row textarea { resize: vertical; }
.form-row .hint { display: block; font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { display: none; font-size: 13px; color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-border); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 14px; }
.form-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }

/* ── Inline condition rows (create modal) ─────── */
.cond-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.cond-row select, .cond-row input {
    font-size: 12px; padding: 6px 7px; border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm); font-family: inherit; color: var(--text);
    background: var(--white); outline: none;
}
.cond-row .c-logic { width: 60px; }
.cond-row .c-field { flex: 2; }
.cond-row .c-op { width: 80px; }
.cond-row .c-val { flex: 1.5; }
.cond-row .c-err { flex: 1.5; }

@media (max-width: 640px) {
    .page-header { flex-direction: column; gap: 12px; }
    .filters { flex-wrap: wrap; }
    .legend { flex-wrap: wrap; gap: 10px; }
    .form-grid { grid-template-columns: 1fr; }
    .cond-row { flex-wrap: wrap; }
    .modal { max-width: 100%; }
    .rule-top { flex-direction: column; }
}