Add Rulesets page with HTML structure and CSS styles

- Created a new HTML file for the Rulesets page, including a header, toolbar, rules grid, and rule detail popup.
- Implemented JavaScript functionality for loading, filtering, sorting, and managing rules.
- Added CSS styles for the layout, components, and responsive design of the Rulesets page.
This commit is contained in:
Giuseppe Raffa
2026-04-15 08:06:29 +02:00
parent c9402de2e4
commit 3094c06467
13 changed files with 2010 additions and 27 deletions

View File

@@ -87,6 +87,10 @@ app.get('/live', renderPage('live', {
realtimeWsUrl: process.env.REALTIME_WS_URL || 'ws://localhost:3002'
}));
app.get('/rulesets', renderPage('rulesets', {
apiUrl: process.env.API_URL || 'http://localhost:3003'
}));
app.listen(PORT, '0.0.0.0', () => {
console.log(`Started on port ${PORT}`);
});

View File

@@ -31,10 +31,10 @@
</div>
</a>
<a class="card" href="/forecasts" title="Previsioni">
<a class="card" href="/rulesets" title="Rulesets">
<div>
<h3>Previsioni</h3>
<p>Visualizza le condizioni meteo attuali e le previsioni future.</p>
<h3>Rulesets</h3>
<p>Gestisci i template di configurazione per weather, data e logs.</p>
</div>
</a>

View File

@@ -28,6 +28,20 @@
</div>
</div>
<!-- Session Label Popup -->
<div class="session-label-overlay" id="sessionLabelOverlay" style="display:none">
<div class="session-popup">
<h2>Nome Sessione</h2>
<p class="popup-subtitle">I nuovi dati verranno taggati con questo nome</p>
<input type="text" id="sessionLabelInput" placeholder="es. Traversata Sardegna" />
<p style="font-size:0.8rem;color:#94a3b8;margin:8px 0;">Attuale: <span id="currentSessionLabel"></span></p>
<div style="display:flex;gap:8px;">
<button id="saveSessionLabelBtn">Salva</button>
<button id="cancelSessionLabelBtn" style="background:#334155;">Annulla</button>
</div>
</div>
</div>
<!-- Main Content -->
<div class="content" id="mainContent" style="display: none;">
<div class="header">
@@ -154,6 +168,10 @@
<div class="bar-sep"></div>
<button id="sessionLabelBtn" title="Sessione di registrazione">Sessione</button>
<div class="bar-sep"></div>
<button id="downloadBtn" title="Scarica CSV">Scarica</button>
</div>
@@ -299,6 +317,7 @@ function selectSession(sId, meta) {
document.getElementById('bottomBar').style.display = '';
document.getElementById('sensorName').textContent = meta.name || sId;
document.getElementById('sessionInfoTitle').textContent = `Sensore: ${meta.name || sId}`;
document.getElementById('currentSessionLabel').textContent = meta.sessionLabel || meta.session || sId;
liveData = {};
Object.values(miniCharts).forEach(c => c.destroy());
miniCharts = {};
@@ -704,4 +723,33 @@ function showToast(msg) {
}, 4500);
}
// --- Session Label Popup ---
document.getElementById('sessionLabelBtn').onclick = () => {
document.getElementById('sessionLabelInput').value = '';
document.getElementById('sessionLabelOverlay').style.display = 'flex';
};
document.getElementById('cancelSessionLabelBtn').onclick = () => {
document.getElementById('sessionLabelOverlay').style.display = 'none';
};
document.getElementById('saveSessionLabelBtn').onclick = async () => {
const label = document.getElementById('sessionLabelInput').value.trim();
if (!label || !currentSensorId) return;
try {
const res = await fetch(`${REALTIME_URL}/sessions/${currentSensorId}/label`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ label })
});
if (res.ok) {
document.getElementById('currentSessionLabel').textContent = label;
showToast(`Sessione rinominata: ${label}`);
} else {
showToast('Errore nel salvataggio');
}
} catch (err) {
showToast('Errore di connessione');
}
document.getElementById('sessionLabelOverlay').style.display = 'none';
};
</script>

View File

@@ -0,0 +1,591 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="/static/styles/style.css">
<link rel="stylesheet" href="/static/styles/rulesets.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="rs-page">
<!-- Header -->
<div class="rs-header">
<div class="rs-header-left">
<a href="/dashboard" class="rs-back">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
</a>
<h1>Rulesets</h1>
<div class="rs-type-picker" id="typePicker">
<button class="active" data-type="weather">Weather</button>
<button data-type="data">Data</button>
<button data-type="logs">Logs</button>
</div>
</div>
<div class="rs-header-right">
<span class="rs-saving" id="savingIndicator">Salvato</span>
</div>
</div>
<!-- Toolbar -->
<div class="rs-toolbar">
<div class="rs-toolbar-left">
<button class="rs-filter-btn active" data-filter="all">Tutte</button>
<button class="rs-filter-btn" data-filter="active">Attive</button>
<button class="rs-filter-btn" data-filter="archived">Archiviate</button>
<select class="rs-sort-select" id="sortSelect">
<option value="created_at">Data creazione</option>
<option value="version">Versione</option>
</select>
</div>
<div class="rs-toolbar-right">
<button class="rs-new-btn" id="newRuleBtn">+ Nuova Rule</button>
</div>
</div>
<!-- Rules Grid -->
<div class="rs-grid" id="rulesGrid">
<div class="rs-empty">Caricamento...</div>
</div>
</div>
<!-- Rule Detail Popup -->
<div class="rs-overlay" id="ruleOverlay" style="display:none">
<div class="rs-popup">
<div class="rs-popup-header">
<div class="rs-popup-header-left">
<span class="rs-card-id" id="popupId"></span>
<span class="rs-saving" id="popupSaving">Salvato</span>
</div>
<button class="rs-popup-close" id="popupClose">&times;</button>
</div>
<div class="rs-popup-body">
<!-- Version + Description -->
<div class="rs-section">
<div class="rs-field-row">
<span class="rs-field-label">Versione</span>
<input class="rs-field-input" id="popupVersion" placeholder="1.0.0" />
</div>
<div class="rs-field-row" id="popupDescRow" style="display:none">
<span class="rs-field-label">Descrizione</span>
<textarea class="rs-field-textarea" id="popupDesc" placeholder="Descrizione opzionale..."></textarea>
</div>
</div>
<!-- Tags -->
<div class="rs-section">
<div class="rs-section-title">Tags</div>
<div class="rs-tags-wrap" id="popupTags">
<input class="rs-tag-input" id="tagInput" placeholder="Aggiungi tag..." />
</div>
</div>
<!-- Actions -->
<div class="rs-section">
<div class="rs-section-title">Azioni</div>
<div class="rs-actions">
<button class="rs-action-btn active-toggle" id="toggleActiveBtn">Attiva</button>
<button class="rs-action-btn archive-toggle" id="toggleArchiveBtn">Archivia</button>
<button class="rs-action-btn danger" id="deleteRuleBtn">Elimina</button>
</div>
</div>
<!-- Items -->
<div class="rs-section">
<div class="rs-items-header">
<div class="rs-section-title">Items</div>
<button class="rs-add-item-btn" id="addItemBtn">+ Aggiungi</button>
</div>
<div class="rs-item-labels" id="itemLabelsRow"></div>
<div id="itemsList"></div>
</div>
</div>
</div>
</div>
<!-- Confirm Dialog -->
<div class="rs-confirm-overlay" id="confirmOverlay" style="display:none">
<div class="rs-confirm-box">
<h3 id="confirmTitle">Conferma</h3>
<p id="confirmText">Sei sicuro?</p>
<div class="rs-confirm-actions">
<button id="confirmCancel">Annulla</button>
<button class="confirm-danger" id="confirmOk">Conferma</button>
</div>
</div>
</div>
<script>
const API_URL = '{{ apiUrl }}';
// --- State ---
let currentType = 'weather';
let currentFilter = 'all';
let currentSort = 'created_at';
let allRules = [];
let openRule = null; // rule attualmente aperta nel popup
let saveTimers = {};
// --- Item field definitions per tipo ---
const ITEM_SCHEMA = {
weather: [
{ key: 'group_name', label: 'Gruppo', cls: 'medium' },
{ key: 'ref', label: 'Ref', cls: 'medium' },
{ key: 'name', label: 'Nome', cls: 'wide' },
{ key: 'unit', label: 'Unita', cls: 'narrow' },
],
data: [
{ key: 'category', label: 'Categoria', cls: 'medium' },
{ key: 'path', label: 'Path', cls: 'wide' },
{ key: 'unit', label: 'Unita', cls: 'narrow' },
],
logs: [
{ key: 'path', label: 'Path', cls: 'wide' },
{ key: 'ref', label: 'Ref', cls: 'narrow' },
{ key: 'unit', label: 'Unita', cls: 'narrow' },
{ key: 'measurement', label: 'Measurement', cls: 'medium' },
],
};
const HAS_DESC = { weather: true, data: false, logs: true };
// ========== API helpers ==========
async function api(method, path, body) {
const opts = { method, headers: {} };
if (body) {
opts.headers['Content-Type'] = 'application/json';
opts.body = JSON.stringify(body);
}
const res = await fetch(`${API_URL}${path}`, opts);
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(err.error || `HTTP ${res.status}`);
}
return res.json();
}
// ========== Load & Render Rules ==========
async function loadRules() {
try {
const data = await api('GET', '/rules');
allRules = data[currentType] || [];
renderGrid();
} catch (err) {
console.error('Error loading rules:', err);
document.getElementById('rulesGrid').innerHTML = '<div class="rs-empty">Errore nel caricamento</div>';
}
}
function filterAndSort(rules) {
let filtered = rules;
if (currentFilter === 'active') filtered = rules.filter(r => r.active && !r.archived);
else if (currentFilter === 'archived') filtered = rules.filter(r => r.archived);
filtered.sort((a, b) => {
if (currentSort === 'version') return (b.version || '').localeCompare(a.version || '', undefined, { numeric: true });
return new Date(b.created_at) - new Date(a.created_at);
});
return filtered;
}
function renderGrid() {
const grid = document.getElementById('rulesGrid');
const rules = filterAndSort(allRules);
if (rules.length === 0) {
grid.innerHTML = '<div class="rs-empty">Nessuna rule trovata</div>';
return;
}
grid.innerHTML = rules.map(r => {
const badges = [];
if (r.active) badges.push('<span class="rs-badge active">Attiva</span>');
else badges.push('<span class="rs-badge inactive">Inattiva</span>');
if (r.archived) badges.push('<span class="rs-badge archived">Archiviata</span>');
const tags = (r.tags || []).map(t => `<span class="rs-tag">${esc(t)}</span>`).join('');
const desc = r.description ? `<div class="rs-card-desc">${esc(r.description)}</div>` : '';
const date = r.created_at ? new Date(r.created_at).toLocaleDateString('it-IT', { day: '2-digit', month: 'short', year: 'numeric' }) : '';
return `
<div class="rs-card" data-id="${r.id}" onclick="openRuleDetail('${r.id}')">
<div class="rs-card-header">
<div>
<div class="rs-card-version">v${esc(r.version)}</div>
<span class="rs-card-id">${esc(r.id)}</span>
</div>
<div class="rs-card-badges">${badges.join('')}</div>
</div>
${desc}
${tags ? `<div class="rs-card-tags">${tags}</div>` : ''}
<div class="rs-card-footer">
<span class="rs-card-date">${date}</span>
</div>
</div>`;
}).join('');
}
function esc(str) {
if (!str) return '';
const d = document.createElement('div');
d.textContent = str;
return d.innerHTML;
}
// ========== Type Picker ==========
document.querySelectorAll('#typePicker button').forEach(btn => {
btn.onclick = () => {
document.querySelectorAll('#typePicker button').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
currentType = btn.dataset.type;
loadRules();
};
});
// ========== Filters ==========
document.querySelectorAll('.rs-filter-btn').forEach(btn => {
btn.onclick = () => {
document.querySelectorAll('.rs-filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
currentFilter = btn.dataset.filter;
renderGrid();
};
});
document.getElementById('sortSelect').onchange = (e) => {
currentSort = e.target.value;
renderGrid();
};
// ========== New Rule ==========
document.getElementById('newRuleBtn').onclick = async () => {
try {
const rule = await api('POST', `/rules/${currentType}`, {
version: '1.0.0',
tags: [],
description: HAS_DESC[currentType] ? '' : undefined
});
allRules.unshift(rule);
renderGrid();
openRuleDetail(rule.id);
flash('Salvato');
} catch (err) {
console.error('Error creating rule:', err);
}
};
// ========== Rule Detail Popup ==========
async function openRuleDetail(ruleId) {
try {
const data = await api('GET', `/rules/${currentType}/${ruleId}`);
openRule = data;
renderPopup();
document.getElementById('ruleOverlay').style.display = 'flex';
} catch (err) {
console.error('Error loading rule detail:', err);
}
}
function closePopup() {
document.getElementById('ruleOverlay').style.display = 'none';
openRule = null;
loadRules(); // refresh grid
}
document.getElementById('popupClose').onclick = closePopup;
document.getElementById('ruleOverlay').onclick = (e) => {
if (e.target === document.getElementById('ruleOverlay')) closePopup();
};
function renderPopup() {
const r = openRule;
document.getElementById('popupId').textContent = r.id;
document.getElementById('popupVersion').value = r.version || '';
// Description
const descRow = document.getElementById('popupDescRow');
if (HAS_DESC[currentType]) {
descRow.style.display = 'flex';
document.getElementById('popupDesc').value = r.description || '';
} else {
descRow.style.display = 'none';
}
// Tags
renderTags();
// Action buttons state
updateActionButtons();
// Items
renderItems();
}
// --- Auto-save fields ---
document.getElementById('popupVersion').oninput = () => debounceFieldSave('version');
document.getElementById('popupDesc').oninput = () => debounceFieldSave('description');
function debounceFieldSave(field) {
clearTimeout(saveTimers[field]);
saveTimers[field] = setTimeout(() => saveRuleField(field), 500);
}
async function saveRuleField(field) {
if (!openRule) return;
const body = {};
if (field === 'version') body.version = document.getElementById('popupVersion').value.trim();
if (field === 'description') body.description = document.getElementById('popupDesc').value.trim();
try {
const updated = await api('PUT', `/rules/${currentType}/${openRule.id}`, body);
Object.assign(openRule, updated);
// Update in allRules too
const idx = allRules.findIndex(r => r.id === openRule.id);
if (idx >= 0) Object.assign(allRules[idx], updated);
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error saving field:', err);
}
}
// --- Tags ---
function renderTags() {
const wrap = document.getElementById('popupTags');
const input = document.getElementById('tagInput');
// Remove old chips
wrap.querySelectorAll('.rs-tag-chip').forEach(c => c.remove());
// Re-add chips before input
(openRule.tags || []).forEach((tag, i) => {
const chip = document.createElement('span');
chip.className = 'rs-tag-chip';
chip.innerHTML = `${esc(tag)}<button data-idx="${i}">&times;</button>`;
chip.querySelector('button').onclick = () => removeTag(i);
wrap.insertBefore(chip, input);
});
}
document.getElementById('tagInput').onkeydown = async (e) => {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
const val = e.target.value.trim().replace(/,$/, '');
if (!val || !openRule) return;
const tags = [...(openRule.tags || []), val];
e.target.value = '';
try {
const updated = await api('PUT', `/rules/${currentType}/${openRule.id}`, { tags });
openRule.tags = updated.tags;
renderTags();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error adding tag:', err);
}
}
};
async function removeTag(idx) {
if (!openRule) return;
const tags = [...(openRule.tags || [])];
tags.splice(idx, 1);
try {
const updated = await api('PUT', `/rules/${currentType}/${openRule.id}`, { tags });
openRule.tags = updated.tags;
renderTags();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error removing tag:', err);
}
}
// --- Action Buttons ---
function updateActionButtons() {
const r = openRule;
const activeBtn = document.getElementById('toggleActiveBtn');
const archiveBtn = document.getElementById('toggleArchiveBtn');
activeBtn.textContent = r.active ? 'Disattiva' : 'Attiva';
activeBtn.className = `rs-action-btn active-toggle${r.active ? '' : ' off'}`;
archiveBtn.textContent = r.archived ? 'Dearchivia' : 'Archivia';
archiveBtn.className = `rs-action-btn archive-toggle${r.archived ? ' on' : ''}`;
}
document.getElementById('toggleActiveBtn').onclick = async () => {
if (!openRule) return;
try {
const res = await api('PATCH', `/rules/${currentType}/${openRule.id}/active`);
openRule.active = res.active;
updateActionButtons();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error toggling active:', err);
}
};
document.getElementById('toggleArchiveBtn').onclick = async () => {
if (!openRule) return;
try {
const res = await api('PATCH', `/rules/${currentType}/${openRule.id}/archive`);
openRule.archived = res.archived;
updateActionButtons();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error toggling archive:', err);
}
};
document.getElementById('deleteRuleBtn').onclick = () => {
if (!openRule) return;
showConfirm('Elimina Rule', `Vuoi eliminare la rule ${openRule.id}? Questa azione e irreversibile.`, async () => {
try {
await api('DELETE', `/rules/${currentType}/${openRule.id}`);
allRules = allRules.filter(r => r.id !== openRule.id);
closePopup();
} catch (err) {
console.error('Error deleting rule:', err);
}
});
};
// --- Items ---
function renderItems() {
const schema = ITEM_SCHEMA[currentType];
const items = openRule.items || [];
// Labels row
const labelsRow = document.getElementById('itemLabelsRow');
labelsRow.innerHTML = schema.map(f => `<span class="${f.cls}">${f.label}</span>`).join('') +
'<span class="toggle-space">On</span><span class="delete-space"></span>';
// Items list
const list = document.getElementById('itemsList');
if (items.length === 0) {
list.innerHTML = '<div style="padding:12px;font-size:0.8rem;color:var(--text-tertiary);">Nessun item. Clicca "+ Aggiungi" per crearne uno.</div>';
return;
}
list.innerHTML = items.map(item => {
const fields = schema.map(f =>
`<input class="rs-item-field ${f.cls}" value="${esc(String(item[f.key] || ''))}" data-field="${f.key}" data-item-id="${item.id}" onchange="saveItemField(this)" />`
).join('');
const toggleCls = item.enabled ? 'on' : '';
return `<div class="rs-item" data-item-id="${item.id}">
${fields}
<div class="rs-toggle ${toggleCls}" onclick="toggleItem(${item.id})"></div>
<button class="rs-item-delete" onclick="deleteItem(${item.id})">&times;</button>
</div>`;
}).join('');
}
document.getElementById('addItemBtn').onclick = async () => {
if (!openRule) return;
const schema = ITEM_SCHEMA[currentType];
const body = {};
// Fill with empty/default values
schema.forEach(f => { body[f.key] = ''; });
// Need at least non-empty values — open with placeholders
// For now, create with placeholder values
schema.forEach(f => { body[f.key] = f.key === 'enabled' ? true : '-'; });
try {
const item = await api('POST', `/rules/${currentType}/${openRule.id}/items`, body);
if (!openRule.items) openRule.items = [];
openRule.items.push(item);
renderItems();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error adding item:', err);
}
};
async function saveItemField(input) {
if (!openRule) return;
const itemId = input.dataset.itemId;
const field = input.dataset.field;
const value = input.value.trim();
try {
await api('PUT', `/rules/${currentType}/${openRule.id}/items/${itemId}`, { [field]: value });
// Update local
const item = openRule.items.find(i => String(i.id) === String(itemId));
if (item) item[field] = value;
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error saving item field:', err);
}
}
async function toggleItem(itemId) {
if (!openRule) return;
try {
const res = await api('PATCH', `/rules/${currentType}/${openRule.id}/items/${itemId}/toggle`);
const item = openRule.items.find(i => i.id === itemId);
if (item) item.enabled = res.enabled;
renderItems();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error toggling item:', err);
}
}
async function deleteItem(itemId) {
if (!openRule) return;
try {
await api('DELETE', `/rules/${currentType}/${openRule.id}/items/${itemId}`);
openRule.items = openRule.items.filter(i => i.id !== itemId);
renderItems();
flash('Salvato', 'popupSaving');
} catch (err) {
console.error('Error deleting item:', err);
}
}
// ========== Confirm Dialog ==========
let confirmCallback = null;
function showConfirm(title, text, onConfirm) {
document.getElementById('confirmTitle').textContent = title;
document.getElementById('confirmText').textContent = text;
confirmCallback = onConfirm;
document.getElementById('confirmOverlay').style.display = 'flex';
}
document.getElementById('confirmCancel').onclick = () => {
document.getElementById('confirmOverlay').style.display = 'none';
confirmCallback = null;
};
document.getElementById('confirmOk').onclick = async () => {
document.getElementById('confirmOverlay').style.display = 'none';
if (confirmCallback) await confirmCallback();
confirmCallback = null;
};
// ========== Flash "Salvato" indicator ==========
function flash(text, elId = 'savingIndicator') {
const el = document.getElementById(elId);
el.textContent = text;
el.classList.add('visible');
setTimeout(() => el.classList.remove('visible'), 1500);
}
// ========== Init ==========
document.addEventListener('DOMContentLoaded', () => loadRules());
</script>
</body>

View File

@@ -0,0 +1,771 @@
/* --- Rulesets Page --- */
.rs-page {
max-width: 1200px;
margin: 0 auto;
padding: 0 24px 120px;
}
/* Header */
.rs-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24px 0 16px;
position: sticky;
top: 0;
z-index: 10;
background: var(--header-bg);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid var(--header-border);
margin-bottom: 20px;
}
.rs-header h1 {
font-size: 1.5rem;
font-weight: 700;
color: var(--text-primary);
}
.rs-header-left {
display: flex;
align-items: center;
gap: 16px;
}
.rs-header-right {
display: flex;
align-items: center;
gap: 12px;
}
/* Type Picker */
.rs-type-picker {
display: flex;
gap: 4px;
background: rgba(241, 245, 249, 0.8);
border-radius: 12px;
padding: 4px;
}
.rs-type-picker button {
padding: 6px 16px;
border: none;
border-radius: 8px;
background: transparent;
color: var(--text-secondary);
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
}
.rs-type-picker button.active {
background: white;
color: var(--accent-color);
box-shadow: var(--shadow-sm);
}
.rs-type-picker button:hover:not(.active) {
color: var(--text-primary);
}
/* Toolbar */
.rs-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.rs-toolbar-left {
display: flex;
align-items: center;
gap: 8px;
}
.rs-toolbar-right {
display: flex;
align-items: center;
gap: 8px;
}
.rs-filter-btn {
padding: 6px 14px;
border: 1px solid var(--header-border);
border-radius: 8px;
background: white;
color: var(--text-secondary);
font-size: 0.8rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
}
.rs-filter-btn.active {
background: var(--accent-light);
color: var(--accent-color);
border-color: var(--accent-border);
}
.rs-filter-btn:hover:not(.active) {
border-color: var(--accent-border);
color: var(--text-primary);
}
.rs-sort-select {
padding: 6px 12px;
border: 1px solid var(--header-border);
border-radius: 8px;
background: white;
color: var(--text-secondary);
font-size: 0.8rem;
font-family: inherit;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
padding-right: 28px;
background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 10px center;
}
.rs-new-btn {
padding: 8px 20px;
border: none;
border-radius: 10px;
background: var(--accent-color);
color: white;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.rs-new-btn:hover {
background: var(--accent-hover);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
/* Rules Grid */
.rs-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 16px;
}
.rs-empty {
grid-column: 1 / -1;
text-align: center;
padding: 60px 20px;
color: var(--text-secondary);
font-size: 0.95rem;
}
/* Rule Card */
.rs-card {
background: white;
border: 1px solid rgba(226, 232, 240, 0.6);
border-radius: 20px;
padding: 20px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
}
.rs-card:hover {
border-color: var(--accent-border);
box-shadow: 0 8px 30px rgba(191, 219, 254, 0.3);
transform: translateY(-2px);
}
.rs-card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 12px;
}
.rs-card-id {
font-family: 'SF Mono', 'Fira Code', monospace;
font-size: 0.8rem;
color: var(--text-tertiary);
background: var(--surface);
padding: 2px 8px;
border-radius: 6px;
}
.rs-card-version {
font-size: 1.1rem;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 4px;
}
.rs-card-desc {
font-size: 0.8rem;
color: var(--text-secondary);
margin-bottom: 12px;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.rs-card-badges {
display: flex;
gap: 6px;
flex-wrap: wrap;
align-items: center;
}
.rs-badge {
padding: 3px 10px;
border-radius: 20px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.rs-badge.active {
background: #dcfce7;
color: #16a34a;
}
.rs-badge.archived {
background: #fef3c7;
color: #d97706;
}
.rs-badge.inactive {
background: var(--surface);
color: var(--text-tertiary);
}
.rs-card-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(226, 232, 240, 0.4);
}
.rs-card-items-count {
font-size: 0.75rem;
color: var(--text-tertiary);
}
.rs-card-date {
font-size: 0.75rem;
color: var(--text-tertiary);
}
.rs-card-tags {
display: flex;
gap: 4px;
flex-wrap: wrap;
margin-bottom: 8px;
}
.rs-tag {
padding: 2px 8px;
border-radius: 6px;
font-size: 0.7rem;
background: rgba(241, 245, 249, 0.8);
color: var(--text-secondary);
}
/* ===== POPUP OVERLAY ===== */
.rs-overlay {
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.4);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
z-index: 2000;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
}
.rs-popup {
background: white;
border-radius: 24px;
width: 700px;
max-width: 95vw;
max-height: 85vh;
overflow-y: auto;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
border: 1px solid var(--header-border);
}
.rs-popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24px 28px 16px;
border-bottom: 1px solid var(--header-border);
position: sticky;
top: 0;
background: white;
border-radius: 24px 24px 0 0;
z-index: 1;
}
.rs-popup-header-left {
display: flex;
align-items: center;
gap: 12px;
}
.rs-popup-close {
width: 32px;
height: 32px;
border: none;
background: var(--surface);
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-secondary);
font-size: 1.2rem;
transition: all 0.2s ease;
}
.rs-popup-close:hover {
background: #fee2e2;
color: #ef4444;
}
.rs-popup-body {
padding: 20px 28px 28px;
}
/* Popup sections */
.rs-section {
margin-bottom: 20px;
}
.rs-section-title {
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.8px;
color: var(--text-tertiary);
margin-bottom: 8px;
}
/* Inline editable fields */
.rs-field-row {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 8px;
}
.rs-field-label {
font-size: 0.8rem;
color: var(--text-secondary);
min-width: 80px;
font-weight: 500;
}
.rs-field-input {
flex: 1;
padding: 8px 12px;
border: 1px solid var(--header-border);
border-radius: 8px;
font-size: 0.85rem;
font-family: inherit;
color: var(--text-primary);
transition: border-color 0.2s ease;
background: white;
}
.rs-field-input:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.rs-field-textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--header-border);
border-radius: 8px;
font-size: 0.85rem;
font-family: inherit;
color: var(--text-primary);
resize: vertical;
min-height: 60px;
transition: border-color 0.2s ease;
}
.rs-field-textarea:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
/* Action buttons row */
.rs-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.rs-action-btn {
padding: 6px 14px;
border: 1px solid var(--header-border);
border-radius: 8px;
font-size: 0.8rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
background: white;
color: var(--text-secondary);
}
.rs-action-btn:hover {
border-color: var(--accent-border);
color: var(--text-primary);
}
.rs-action-btn.active-toggle {
background: #dcfce7;
color: #16a34a;
border-color: #bbf7d0;
}
.rs-action-btn.active-toggle.off {
background: white;
color: var(--text-secondary);
border-color: var(--header-border);
}
.rs-action-btn.archive-toggle.on {
background: #fef3c7;
color: #d97706;
border-color: #fde68a;
}
.rs-action-btn.danger {
color: #ef4444;
border-color: #fecaca;
}
.rs-action-btn.danger:hover {
background: #fef2f2;
border-color: #fca5a5;
}
/* Items section */
.rs-items-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.rs-add-item-btn {
padding: 4px 12px;
border: 1px dashed var(--accent-border);
border-radius: 8px;
background: var(--accent-light);
color: var(--accent-color);
font-size: 0.8rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
}
.rs-add-item-btn:hover {
background: var(--accent-color);
color: white;
border-style: solid;
}
/* Item row */
.rs-item {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
background: var(--surface);
border-radius: 10px;
margin-bottom: 6px;
transition: all 0.2s ease;
}
.rs-item:hover {
background: rgba(241, 245, 249, 1);
}
.rs-item-field {
padding: 5px 8px;
border: 1px solid transparent;
border-radius: 6px;
font-size: 0.8rem;
font-family: inherit;
color: var(--text-primary);
background: transparent;
transition: all 0.2s ease;
min-width: 0;
}
.rs-item-field:focus {
border-color: var(--accent-color);
background: white;
outline: none;
}
.rs-item-field.narrow {
width: 60px;
flex-shrink: 0;
}
.rs-item-field.medium {
width: 100px;
flex-shrink: 0;
}
.rs-item-field.wide {
flex: 1;
min-width: 80px;
}
/* Toggle switch for item enabled */
.rs-toggle {
width: 36px;
height: 20px;
background: #cbd5e1;
border-radius: 10px;
position: relative;
cursor: pointer;
transition: background 0.2s ease;
flex-shrink: 0;
}
.rs-toggle.on {
background: #22c55e;
}
.rs-toggle::after {
content: '';
position: absolute;
width: 16px;
height: 16px;
background: white;
border-radius: 50%;
top: 2px;
left: 2px;
transition: transform 0.2s ease;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.rs-toggle.on::after {
transform: translateX(16px);
}
.rs-item-delete {
width: 24px;
height: 24px;
border: none;
background: transparent;
color: var(--text-tertiary);
cursor: pointer;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1rem;
flex-shrink: 0;
transition: all 0.2s ease;
}
.rs-item-delete:hover {
background: #fef2f2;
color: #ef4444;
}
/* Tags input */
.rs-tags-wrap {
display: flex;
flex-wrap: wrap;
gap: 6px;
align-items: center;
padding: 6px;
border: 1px solid var(--header-border);
border-radius: 8px;
min-height: 38px;
background: white;
}
.rs-tags-wrap:focus-within {
border-color: var(--accent-color);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.rs-tag-chip {
display: flex;
align-items: center;
gap: 4px;
padding: 3px 8px;
background: var(--accent-light);
color: var(--accent-color);
border-radius: 6px;
font-size: 0.75rem;
font-weight: 500;
}
.rs-tag-chip button {
border: none;
background: none;
color: inherit;
cursor: pointer;
padding: 0;
font-size: 0.85rem;
opacity: 0.6;
line-height: 1;
}
.rs-tag-chip button:hover {
opacity: 1;
}
.rs-tag-input {
border: none;
outline: none;
font-size: 0.8rem;
font-family: inherit;
flex: 1;
min-width: 80px;
padding: 2px 4px;
background: transparent;
color: var(--text-primary);
}
/* Saving indicator */
.rs-saving {
font-size: 0.75rem;
color: var(--accent-color);
opacity: 0;
transition: opacity 0.2s ease;
}
.rs-saving.visible {
opacity: 1;
}
/* Item field labels header */
.rs-item-labels {
display: flex;
align-items: center;
gap: 8px;
padding: 0 12px 4px;
font-size: 0.7rem;
color: var(--text-tertiary);
text-transform: uppercase;
letter-spacing: 0.5px;
font-weight: 600;
}
.rs-item-labels span.narrow { width: 60px; flex-shrink: 0; }
.rs-item-labels span.medium { width: 100px; flex-shrink: 0; }
.rs-item-labels span.wide { flex: 1; min-width: 80px; }
.rs-item-labels span.toggle-space { width: 36px; flex-shrink: 0; }
.rs-item-labels span.delete-space { width: 24px; flex-shrink: 0; }
/* Confirm dialog */
.rs-confirm-overlay {
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.5);
backdrop-filter: blur(4px);
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
}
.rs-confirm-box {
background: white;
border-radius: 16px;
padding: 24px;
width: 360px;
max-width: 90vw;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
text-align: center;
}
.rs-confirm-box h3 {
margin-bottom: 8px;
font-size: 1rem;
color: var(--text-primary);
}
.rs-confirm-box p {
font-size: 0.85rem;
color: var(--text-secondary);
margin-bottom: 20px;
}
.rs-confirm-actions {
display: flex;
gap: 8px;
justify-content: center;
}
.rs-confirm-actions button {
padding: 8px 20px;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
font-family: inherit;
border: 1px solid var(--header-border);
background: white;
color: var(--text-secondary);
transition: all 0.2s ease;
}
.rs-confirm-actions button.confirm-danger {
background: #ef4444;
color: white;
border-color: #ef4444;
}
.rs-confirm-actions button.confirm-danger:hover {
background: #dc2626;
}
/* Back link */
.rs-back {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--text-secondary);
text-decoration: none;
font-size: 0.85rem;
font-weight: 500;
transition: color 0.2s ease;
}
.rs-back:hover {
color: var(--accent-color);
}