/* =============================================================================
 * AccessRules Components Styles
 * ============================================================================= */

/* =============================================================================
 * Access Level Select
 * ============================================================================= */

.accessLevelSelect {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.accessLevelSelect.compact {
  gap: 0;
}

.accessLevelLabel {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.accessLevelDropdown {
  padding: 0.375rem 0.5rem;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-primary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 80px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.accessLevelDropdown:hover:not(:disabled) {
  box-shadow: 0 0 0 2px var(--primary-color-light);
}

.accessLevelDropdown:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary-color);
}

.accessLevelDropdown:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =============================================================================
 * Access Rules Editor
 * ============================================================================= */

.accessRulesEditor {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-primary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.editorHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.editorTitle {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.templateBadge {
  background: var(--info-color);
  color: white;
  font-size: 0.625rem;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 700;
}

.headerActions {
  display: flex;
  gap: 0.5rem;
}

/* =============================================================================
 * Tabs
 * ============================================================================= */

.tabsContainer {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tabList {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: -2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.tabIcon {
  font-size: 1rem;
}

.tabBadge {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.tab.active .tabBadge {
  background: var(--primary-color);
  color: white;
}

.tabContent {
  min-height: 200px;
}

/* =============================================================================
 * Rules Section
 * ============================================================================= */

.rulesSection {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sectionHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sectionTitle {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.addButton {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.addButton:hover {
  background: var(--primary-color-dark);
}

.addButton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =============================================================================
 * Rule Card
 * ============================================================================= */

.ruleCard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.875rem;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.ruleHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ruleItem {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ruleItemIcon {
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.ruleItemName {
  font-weight: 500;
  color: var(--text-primary);
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.875rem;
}

.ruleActions {
  display: flex;
  gap: 0.25rem;
}

.iconButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all 0.2s;
}

.iconButton:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.iconButton.danger:hover {
  background: #fed7d7;
  color: #c53030;
  border-color: #fc8181;
}

/* =============================================================================
 * Permissions Grid
 * ============================================================================= */

.permissionsGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.permissionItem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.permissionLabel {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-weight: 500;
}

/* View Toggle */
.viewToggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.viewCheckbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary-color);
}

/* =============================================================================
 * Empty State
 * ============================================================================= */

.emptyState {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-tertiary);
  text-align: center;
}

.emptyIcon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

.emptyText {
  font-size: 0.875rem;
  margin: 0;
}

.emptyHint {
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* =============================================================================
 * Add Rule Modal
 * ============================================================================= */

.addRuleForm {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.formGroup {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.formLabel {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
}

.formInput {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.formInput:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-color-light);
}

.formSelect {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
}

.formHint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.formActions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* =============================================================================
 * Action Bar
 * ============================================================================= */

.actionBar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.secondaryButton {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.secondaryButton:hover {
  background: var(--bg-tertiary);
}

.secondaryButton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primaryButton {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.primaryButton:hover {
  background: var(--primary-color-dark);
}

.primaryButton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =============================================================================
 * Loading State
 * ============================================================================= */

.loadingContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  gap: 1rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============================================================================
 * JSON Editor Tab
 * ============================================================================= */

.jsonEditor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.jsonTextarea {
  width: 100%;
  min-height: 300px;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
  background: var(--bg-secondary);
  color: var(--text-primary);
  resize: vertical;
}

.jsonTextarea:focus {
  outline: none;
  border-color: var(--primary-color);
}

.jsonError {
  color: #c53030;
  font-size: 0.8125rem;
  padding: 0.5rem;
  background: #fed7d7;
  border-radius: 4px;
}

.jsonHint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* =============================================================================
 * Access Rules Table (Checkbox Matrix)
 * ============================================================================= */

.tableWrapper {
  overflow-x: auto;
  margin: 0 -0.5rem;
  padding: 0 0.5rem;
}

.accessRulesTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  min-width: 800px;
}

.accessRulesTable th,
.accessRulesTable td {
  padding: 0.5rem 0.375rem;
  border-bottom: 1px solid var(--border-color);
  text-align: center;
  vertical-align: middle;
}

.accessRulesTable th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}

.accessRulesTable tbody tr:hover {
  background: var(--bg-secondary);
}

.colObject {
  text-align: left !important;
  min-width: 220px;
  max-width: 350px;
}

.colView {
  width: 50px;
}

.colGroupHeader {
  border-left: 2px solid var(--border-color);
  background: var(--bg-tertiary) !important;
}

.colGroupHeader:nth-of-type(3) {
  background: rgba(72, 187, 120, 0.1) !important;
}

.colGroupHeader:nth-of-type(4) {
  background: rgba(66, 153, 225, 0.1) !important;
}

.colGroupHeader:nth-of-type(5) {
  background: rgba(237, 100, 166, 0.1) !important;
}

.subHeader th {
  font-size: 0.625rem;
  padding: 0.25rem 0.375rem;
  background: var(--bg-primary) !important;
  font-weight: 700;
  color: var(--text-tertiary);
}

.subHeader th:nth-child(n+3):nth-child(-n+6) {
  background: rgba(72, 187, 120, 0.05) !important;
}

.subHeader th:nth-child(n+7):nth-child(-n+10) {
  background: rgba(66, 153, 225, 0.05) !important;
}

.subHeader th:nth-child(n+11):nth-child(-n+14) {
  background: rgba(237, 100, 166, 0.05) !important;
}

.objectCell {
  text-align: left !important;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.objectIcon {
  color: var(--text-tertiary);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.objectCode {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  color: var(--text-primary);
  word-break: break-all;
}

.checkboxCell {
  width: 32px;
  padding: 0.375rem 0.25rem !important;
}

.checkboxCell input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--primary-color);
  margin: 0;
}

.checkboxCell input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.actionsCell {
  width: 40px;
  padding: 0.375rem !important;
}

.ruleRow td {
  padding: 0.5rem 0.375rem;
}

.ruleRow td:nth-child(n+3):nth-child(-n+6) {
  background: rgba(72, 187, 120, 0.02);
}

.ruleRow td:nth-child(n+7):nth-child(-n+10) {
  background: rgba(66, 153, 225, 0.02);
}

.ruleRow td:nth-child(n+11):nth-child(-n+14) {
  background: rgba(237, 100, 166, 0.02);
}

/* Toggle between Card and Table View */
.viewToggleButton {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.viewToggleButton:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.viewToggleButton.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Object Selector */
.objectSelector {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.objectSelectorLabel {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggleCustomButton {
  padding: 0.125rem 0.5rem;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-size: 0.6875rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.toggleCustomButton:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Add Rule Matrix (Checkbox Style) */
.addRuleMatrix {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.matrixHeader {
  display: grid;
  grid-template-columns: 80px repeat(3, 1fr);
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.matrixGroup {
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.matrixRow {
  display: grid;
  grid-template-columns: 80px repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.25rem 0;
}

.matrixLabel {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.matrixCell {
  display: flex;
  justify-content: center;
  align-items: center;
}

.matrixCell input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary-color);
}
