/* --- 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);
}
