* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #1a1a2e;
  line-height: 1.6;
}

header {
  background: #1a1a2e;
  color: #fff;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 { font-size: 1.3rem; font-weight: 600; }

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  background: #666;
  color: #fff;
}

.badge.ok { background: #27ae60; }
.badge.error { background: #e74c3c; }

nav {
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  padding: 0 2rem;
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  padding: 0.8rem 1.2rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: #666;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab:hover { color: #1a1a2e; }
.tab.active { color: #1a1a2e; border-bottom-color: #3498db; font-weight: 600; }

main { padding: 1.5rem 2rem; max-width: 1200px; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ================================================================
   Stat Cards
   ================================================================ */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 1.2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card h3 { font-size: 0.8rem; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.card p { font-size: 1.8rem; font-weight: 700; margin-top: 0.3rem; }

/* ================================================================
   Tables
   ================================================================ */

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

th, td { padding: 0.6rem 0.8rem; text-align: left; font-size: 0.85rem; }
th { background: #f8f9fa; font-weight: 600; color: #555; border-bottom: 2px solid #e0e0e0; }
tr:not(:last-child) td { border-bottom: 1px solid #f0f0f0; }
tr:hover td { background: #f8f9fa; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #eef4fb; }

/* ================================================================
   Buttons
   ================================================================ */

button {
  cursor: pointer;
  padding: 0.4rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  font-size: 0.8rem;
  transition: all 0.15s;
}

button:hover { background: #f0f0f0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

.actions button,
.btn-primary {
  background: #3498db;
  color: #fff;
  border-color: #2980b9;
}

.actions button:hover,
.btn-primary:hover { background: #2980b9; }

.btn-danger { background: #e74c3c; color: #fff; border-color: #c0392b; }
.btn-danger:hover { background: #c0392b; }

.btn-success { background: #27ae60; color: #fff; border-color: #219a52; }
.btn-success:hover { background: #219a52; }

.btn-warning { background: #f39c12; color: #fff; border-color: #e08e0b; }
.btn-warning:hover { background: #e08e0b; }

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.btn-toggle-on, .btn-toggle-off {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  width: 2.5rem;
  text-align: center;
  margin-right: 0.4rem;
  vertical-align: middle;
  line-height: 1.4;
  transition: background 0.15s;
}
.btn-toggle-on { background: #27ae60; color: #fff; }
.btn-toggle-on:hover:not(:disabled) { background: #219a52; }
.btn-toggle-off { background: #e74c3c; color: #fff; }
.btn-toggle-off:hover:not(:disabled) { background: #c0392b; }
.btn-toggle-on:disabled, .btn-toggle-off:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-group { display: inline-flex; gap: 0.3rem; }

/* ================================================================
   Pre / Code
   ================================================================ */

pre {
  background: #2d2d2d;
  color: #f0f0f0;
  padding: 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  overflow-x: auto;
  max-height: 300px;
  margin-top: 0.5rem;
}

pre:empty { display: none; }

/* ================================================================
   Auth Modal (existing)
   ================================================================ */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

/* Legacy .modal class (auth modal) */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-content input {
  padding: 0.6rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
}

.modal-content button {
  background: #3498db;
  color: #fff;
  border-color: #2980b9;
  padding: 0.6rem;
}

/* ================================================================
   Dialog Modal (new — for forms)
   ================================================================ */

.modal-dialog {
  background: #fff;
  border-radius: 10px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: #888;
  padding: 0.2rem 0.5rem;
  line-height: 1;
}
.modal-close:hover { color: #333; background: none; }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid #e0e0e0;
}

/* ================================================================
   Form Styles
   ================================================================ */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-group .hint {
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.2rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

/* ================================================================
   Form Sections (collapsible panels)
   ================================================================ */

.form-section {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.form-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  background: #f8f9fa;
  cursor: pointer;
  user-select: none;
}

.form-section-header h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
}

.form-section-header .chevron {
  font-size: 0.7rem;
  color: #888;
  transition: transform 0.2s;
}

.form-section.collapsed .form-section-body { display: none; }
.form-section.collapsed .chevron { transform: rotate(-90deg); }

.form-section-body {
  padding: 1rem;
  border-top: 1px solid #e0e0e0;
}

/* ================================================================
   Toggle Switch
   ================================================================ */

.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* Override .form-group label which sets display:block and breaks toggle layout */
label.toggle-switch,
.form-group label.toggle-switch {
  display: inline-flex;
  font-size: inherit;
  font-weight: normal;
  color: inherit;
  margin-bottom: 0;
  width: auto;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

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

.toggle-switch input:checked + .toggle-slider {
  background: #3498db;
}

.toggle-switch input:checked + .toggle-slider::after {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.8rem;
  color: #555;
  cursor: pointer;
}

/* ================================================================
   Chip Select (multi-select as chips)
   ================================================================ */

.chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-select label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 14px;
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  background: #fff;
}

.chip-select label:hover { border-color: #3498db; }

.chip-select input {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.chip-select input:checked + span {
  color: #fff;
}

.chip-select label:has(input:checked) {
  background: #3498db;
  border-color: #3498db;
  color: #fff;
}

/* ================================================================
   Condition Builder (filter)
   ================================================================ */

.condition-row {
  display: grid;
  grid-template-columns: 1fr 120px 1fr auto;
  gap: 0.5rem;
  align-items: start;
  margin-bottom: 0.5rem;
}

.condition-row input,
.condition-row select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.8rem;
}

.condition-row .btn-remove {
  background: none;
  border: none;
  color: #e74c3c;
  font-size: 1.1rem;
  padding: 0.3rem;
  line-height: 1;
}

.condition-row .btn-remove:hover { color: #c0392b; background: none; }

.condition-row .value-select,
.condition-row .value-multi-select {
  width: 100%;
  min-width: 0;
}

.condition-row .value-multi-select {
  min-height: 60px;
  max-height: 120px;
}

/* ================================================================
   Sub-tabs (within shop detail / run detail)
   ================================================================ */

.sub-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 1rem;
}

.sub-tab {
  background: none;
  border: none;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: #666;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.sub-tab:hover { color: #1a1a2e; background: none; }
.sub-tab.active { color: #1a1a2e; border-bottom-color: #3498db; font-weight: 600; background: none; }

.sub-content { display: none; }
.sub-content.active { display: block; }

/* ================================================================
   Detail Panels (shop detail, run detail)
   ================================================================ */

.detail-panel {
  display: none;
}

.detail-panel.active {
  display: block;
}

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #3498db;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 1rem;
}

.detail-back:hover { color: #2980b9; background: none; text-decoration: underline; }

.detail-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.list-view { }
.list-view.hidden { display: none; }

/* ================================================================
   Action Cards (actions tab)
   ================================================================ */

.action-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.action-card {
  background: #fff;
  border-radius: 8px;
  padding: 1.2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.action-card h4 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.action-card p {
  font-size: 0.78rem;
  color: #666;
  margin-bottom: 0.8rem;
}

.action-card .action-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.action-card input {
  padding: 0.35rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.8rem;
  width: 80px;
}

.action-card pre {
  margin-top: 0.5rem;
  max-height: 120px;
  font-size: 0.72rem;
}

/* ================================================================
   Schedule Table
   ================================================================ */

.schedule-section {
  margin-bottom: 1.5rem;
}

.schedule-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #333;
}

/* ================================================================
   Issue Filters
   ================================================================ */

.filter-tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.filter-tab {
  padding: 0.3rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 14px;
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-tab:hover { border-color: #3498db; }
.filter-tab.active { background: #3498db; color: #fff; border-color: #3498db; }

/* ================================================================
   Expandable detail row
   ================================================================ */

tr.detail-row td {
  background: #f8f9fa;
  padding: 0.8rem;
}

tr.detail-row pre {
  margin: 0;
  max-height: 200px;
  font-size: 0.75rem;
}

tr.detail-row.hidden { display: none; }

/* ================================================================
   Mode Toggle (AND/OR)
   ================================================================ */

.mode-toggle {
  display: inline-flex;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.8rem;
}

.mode-toggle button {
  border: none;
  border-radius: 0;
  padding: 0.3rem 0.8rem;
  font-size: 0.78rem;
  background: #fff;
  color: #666;
}

.mode-toggle button.active {
  background: #3498db;
  color: #fff;
}

.mode-toggle button:hover:not(.active) { background: #f0f0f0; }

/* ================================================================
   Status badges
   ================================================================ */

.status-completed { color: #27ae60; }
.status-running { color: #f39c12; }
.status-failed { color: #e74c3c; }
.status-paused { color: #e67e22; }
.status-open { color: #e74c3c; }
.status-acknowledged { color: #f39c12; }
.status-resolved { color: #27ae60; }

.inline-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}

.inline-badge.active { background: #d4edda; color: #155724; }
.inline-badge.inactive { background: #f8d7da; color: #721c24; }
.inline-badge.paused { background: #fff3cd; color: #856404; }

/* ================================================================
   Health detail panel
   ================================================================ */

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.5rem;
}

.health-item {
  background: #fff;
  border-radius: 6px;
  padding: 0.8rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.health-dot.ok { background: #27ae60; }
.health-dot.error { background: #e74c3c; }
.health-dot.unknown { background: #ccc; }

.health-item .health-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #333;
}

/* ================================================================
   Mini table (overview recent runs)
   ================================================================ */

.mini-table {
  font-size: 0.8rem;
}

.mini-table th, .mini-table td {
  padding: 0.4rem 0.6rem;
}

/* ================================================================
   Empty state
   ================================================================ */

.empty-state {
  text-align: center;
  padding: 2rem;
  color: #888;
  font-size: 0.85rem;
}

/* ================================================================
   Responsive
   ================================================================ */

/* ================================================================
   Toggle Row (compact inline toggles)
   ================================================================ */

.toggle-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.toggle-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.toggle-item .toggle-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  cursor: pointer;
}

/* ================================================================
   Section description (below form-section-header)
   ================================================================ */

.section-desc {
  font-size: 0.78rem;
  color: #888;
  margin-bottom: 1rem;
  line-height: 1.4;
}

/* ================================================================
   Save timestamp
   ================================================================ */

.save-timestamp {
  display: block;
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.5rem;
}

/* ================================================================
   Master shop panel
   ================================================================ */

.master-panel {
  background: #fff;
  border: 2px solid #3498db;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.master-panel .form-section-header {
  background: #eaf2fb;
}

.master-panel .master-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #3498db;
  font-weight: 700;
  margin-left: 0.5rem;
}

/* ================================================================
   Key-value pair rows (for rule config)
   ================================================================ */

.kv-pair-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.kv-pair-row input,
.kv-pair-row select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.8rem;
  min-width: 0;
}

.kv-pair-row .kv-arrow {
  color: #888;
  font-size: 0.9rem;
  text-align: center;
}

.kv-pair-row .btn-remove {
  background: none;
  border: none;
  color: #e74c3c;
  font-size: 1.1rem;
  padding: 0.3rem;
  line-height: 1;
}

.kv-pair-row .btn-remove:hover { color: #c0392b; background: none; }

/* ================================================================
   Optgroup styling for filter field dropdown
   ================================================================ */

.field-select {
  max-width: 100%;
}

.field-select optgroup {
  font-weight: 600;
  font-size: 0.8rem;
}

/* ================================================================
   Progress bar for running syncs
   ================================================================ */

.progress-bar {
  position: relative;
  height: 20px;
  background: #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  min-width: 100px;
}
.progress-fill {
  height: 100%;
  background: #3498db;
  border-radius: 10px;
  transition: width 0.3s ease;
}
.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  font-weight: 600;
  color: #333;
}

/* ================================================================
   Queue panel grid
   ================================================================ */

.queue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.queue-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
}
.queue-card h4 {
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
  color: #333;
}
.queue-counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.queue-count {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.queue-count.active { background: #e8f4fd; color: #2980b9; }
.queue-count.waiting { background: #fef9e7; color: #f39c12; }
.queue-count.completed { background: #eafaf1; color: #27ae60; }
.queue-count.failed { background: #fdedec; color: #e74c3c; }
.queue-count.delayed { background: #f4ecf7; color: #8e44ad; }

/* ================================================================
   Mappings table toolbar
   ================================================================ */

.mappings-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.mappings-toolbar select,
.mappings-toolbar input {
  padding: 0.4rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* ================================================================
   Pagination controls
   ================================================================ */

.paginator {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  color: #666;
}
.paginator button {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

/* ================================================================
   Searchable Select Component
   ================================================================ */

.searchable-select {
  position: relative;
  min-width: 180px;
}

.ss-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  transition: border-color 0.15s;
}

.ss-input-wrap:focus-within {
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.ss-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  background: transparent;
  min-width: 0;
}

.ss-clear {
  background: none;
  border: none;
  color: #888;
  font-size: 1rem;
  padding: 0 0.4rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

.ss-clear:hover { color: #e74c3c; background: none; }

.ss-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
}

.ss-dropdown.open { display: block; }

.ss-option {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.ss-option:hover { background: #eef4fb; }
.ss-option.selected { background: #d4e6f9; }

.ss-option-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.ss-no-results {
  padding: 0.5rem 0.6rem;
  font-size: 0.78rem;
  color: #888;
  font-style: italic;
}

.ss-more {
  padding: 0.35rem 0.6rem;
  font-size: 0.72rem;
  color: #3498db;
  font-style: italic;
}

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

.mapping-tabs-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.mapping-inner-tab {
  background: none;
  border: none;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.78rem;
  color: #666;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.mapping-inner-tab:hover { color: #1a1a2e; background: none; }
.mapping-inner-tab.active { color: #1a1a2e; border-bottom-color: #3498db; font-weight: 600; background: none; }

.mapping-add-btn {
  margin-left: auto;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  position: relative;
}

.mapping-add-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 160px;
  display: none;
}

.mapping-add-dropdown.open { display: block; }

.mapping-add-dropdown .mapping-add-item {
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  display: block;
}

.mapping-add-dropdown .mapping-add-item:hover { background: #eef4fb; }

/* ================================================================
   Mapping Tab Content
   ================================================================ */

.mapping-tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.mapping-tab-header h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #333;
}

.mapping-tab-header .mapping-meta {
  font-size: 0.72rem;
  color: #888;
}

.mapping-io-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.mapping-io-bar .btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.file-input-hidden {
  display: none;
}

.mapping-entity-list {
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
}

.mapping-entity-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.8rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.8rem;
}

.mapping-entity-row:last-child { border-bottom: none; }

.mapping-entity-row:hover { background: #fafbfc; }

.mapping-entity-row .master-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-entity-row .mapping-arrow {
  color: #888;
  font-size: 0.9rem;
  text-align: center;
  flex-shrink: 0;
}

.mapping-save-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.mapping-save-bar .save-timestamp {
  margin-top: 0;
}

/* ================================================================
   Flag Filter Chips (in mapping tab)
   ================================================================ */

.flag-filter-section {
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 0.8rem;
  margin-bottom: 1rem;
}

.flag-filter-section summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: #333;
}

.flag-filter-section summary:hover { color: #3498db; }

/* ================================================================
   Parameter Tree
   ================================================================ */

.param-tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0.8rem;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.param-filter-mode {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.82rem;
}

.param-filter-mode select {
  padding: 0.2rem 0.4rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.8rem;
}

.param-type-section {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 0.6rem;
}

.param-type-section summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
  padding: 0.6rem 0.8rem;
  user-select: none;
}

.param-type-section summary:hover { color: #3498db; }

.param-names-list {
  overflow-y: auto;
  padding: 0 0.4rem 0.4rem;
}

.param-name-row { border-bottom: 1px solid #f0f0f0; }
.param-name-row:last-child { border-bottom: none; }

.param-name-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem;
}

.param-name-header:hover { background: #fafbfc; }

.param-filter-check { flex-shrink: 0; }
.param-filter-check input { cursor: pointer; }

.param-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  color: #888;
  width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
  padding: 0;
}

.param-expand-btn:hover { color: #3498db; }
.param-expand-placeholder { width: 1.2rem; flex-shrink: 0; }

.param-name-label {
  font-size: 0.82rem;
  font-weight: 500;
  min-width: 120px;
}

.param-value-count {
  font-size: 0.72rem;
  color: #999;
  flex-shrink: 0;
}

.param-name-header .mapping-arrow {
  color: #888;
  font-size: 0.9rem;
  flex-shrink: 0;
  margin: 0 0.3rem;
}

.param-name-target, .param-value-target {
  flex: 1;
  max-width: 200px;
  padding: 0.2rem 0.4rem;
  border: 1px solid #e0e0e0;
  border-radius: 3px;
  font-size: 0.78rem;
}

.param-name-target:focus, .param-value-target:focus {
  border-color: #3498db;
  outline: none;
}

.param-values-panel {
  margin-left: 2.5rem;
  padding: 0.3rem 0 0.5rem;
  border-left: 2px solid #e8e8e8;
}

.param-value-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
}

.param-value-row:hover { background: #f8f9fa; }

.param-value-label {
  min-width: 100px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #555;
}

.param-value-target { max-width: 180px; }

/* ================================================================
   Stat card detail line
   ================================================================ */

.stat-detail {
  display: block;
  font-size: 0.72rem;
  color: #888;
  font-weight: 400;
  margin-top: 0.1rem;
}

/* ================================================================
   Overview error banner
   ================================================================ */

.overview-error {
  background: #fdedec;
  color: #c0392b;
  border: 1px solid #e74c3c;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

/* ================================================================
   Last refreshed timestamp
   ================================================================ */

.refreshed-timestamp {
  font-size: 0.72rem;
  color: #aaa;
  margin-top: 1rem;
  text-align: right;
}

/* ================================================================
   Quick action button loading state
   ================================================================ */

.actions button.loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

/* ================================================================
   Responsive
   ================================================================ */

/* Filter rule cards */
.filter-rule-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  transition: background 0.15s, opacity 0.15s;
}
.filter-rule-card:hover { background: #f5f7fa; }
.filter-rule-card.active { background: #eef4ff; border-color: #4a90d9; }
.filter-rule-card.disabled { opacity: 0.55; }
.filter-rule-card.dragging { opacity: 0.4; }
.filter-rule-card.drag-over { border-top: 2px solid #3498db; margin-top: -1px; }
.filter-drag-handle {
  cursor: grab; color: #bbb; font-size: 0.9rem; flex-shrink: 0;
  user-select: none; padding: 0 0.2rem;
}
.filter-drag-handle:hover { color: #666; }
.filter-rule-toggle { flex-shrink: 0; }
.filter-action-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.filter-action-include { background: #d4edda; color: #155724; }
.filter-action-exclude { background: #f8d7da; color: #721c24; }
.filter-rule-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  cursor: pointer;
  min-width: 0;
}
.filter-rule-info strong { font-size: 0.85rem; }
.filter-rule-summary {
  font-size: 0.75rem;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Filter editor advanced toggle */
.filter-advanced-details {
  margin-top: 1rem;
  border-top: 1px solid #e0e0e0;
  padding-top: 0.5rem;
}

.filter-advanced-summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #888;
  user-select: none;
  padding: 0.3rem 0;
}

.filter-advanced-summary:hover { color: #3498db; }

.filter-advanced-details[open] .filter-advanced-summary { color: #555; }

/* Bulk value textarea for in/nin operators (legacy, kept for compat) */
.filter-bulk-values {
  width: 100%;
  min-height: 60px;
  max-height: 120px;
  resize: vertical;
  font-family: monospace;
  font-size: 0.78rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}
.filter-bulk-values:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

/* Tag/chip input for in/nin operators */
.tag-input-container {
  position: relative;
  width: 100%;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.3rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  min-height: 34px;
  align-items: center;
  cursor: text;
  transition: border-color 0.15s;
}

.tag-chips:focus-within {
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: #e0e7ee;
  color: #333;
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-chip-remove {
  background: none;
  border: none;
  color: #888;
  font-size: 0.85rem;
  padding: 0 0.1rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

.tag-chip-remove:hover { color: #e74c3c; background: none; }

.tag-input {
  border: none;
  outline: none;
  font-size: 0.8rem;
  padding: 0.15rem 0.3rem;
  min-width: 80px;
  flex: 1;
  background: transparent;
}

.tag-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
}

.tag-dropdown.open { display: block; }

.tag-dropdown-item {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.tag-dropdown-item:hover { background: #4a90d9; color: #fff; }

.tag-dropdown-empty {
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  color: #888;
  font-style: italic;
}

/* ── Clickable table rows ── */
.clickable-row {
  cursor: pointer;
  transition: background 0.15s;
}
.clickable-row:hover td {
  background: #edf2f7;
}
.clickable-row td:first-child {
  border-left: 3px solid transparent;
}
.clickable-row:hover td:first-child {
  border-left-color: #3498db;
}

/* ── Schedules tab ── */
.sched-header {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  background: #f0f2f5;
  border-radius: 8px;
}
.sched-cron-summary {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.sched-cron-line {
  font-size: 0.85rem;
}
.sched-cron-line code {
  font-size: 0.8rem;
  background: #e8ecf0;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}
.sched-table {
  width: 100%;
  border-collapse: collapse;
}
.sched-table th {
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #666;
  padding: 0.5rem 0.6rem;
  border-bottom: 2px solid #ddd;
}
.sched-table td {
  padding: 0.6rem;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
  font-size: 0.88rem;
}
.sched-table tr:hover td {
  background: #f8f9fb;
}
.sched-inline-select {
  font-size: 0.82rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  margin: 0 0.2rem;
}
.sched-inline-time {
  font-size: 0.82rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  width: 5.5rem;
  margin-left: 0.2rem;
}
.sched-next-run {
  color: #666;
  font-size: 0.78rem;
  margin-left: 3.2rem;
}

@media (max-width: 768px) {
  main { padding: 1rem; }
  nav { padding: 0 1rem; }
  header { padding: 0.8rem 1rem; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .condition-row { grid-template-columns: 1fr; }
  .modal-dialog { width: 95%; max-height: 90vh; }
  .mapping-entity-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .mapping-entity-row .mapping-arrow { display: none; }
  .docs-panel { width: 90% !important; }
}

/* ================================================================
   Documentation Side Panel
   ================================================================ */

.docs-btn {
  background: #3498db;
  color: #fff;
  border: none;
  padding: 0.3rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 0.15s;
}
.docs-btn:hover { background: #2980b9; }

.docs-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 900;
}
.docs-overlay.open { display: block; }

.docs-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 460px;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 910;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.docs-panel.open { transform: translateX(0); }

.docs-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.docs-panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: #2c3e50;
}
.docs-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: #999;
  line-height: 1;
  padding: 0 0.3rem;
}
.docs-close:hover { color: #333; }

.docs-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
  scroll-behavior: smooth;
}

/* TOC */
.docs-toc {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin-bottom: 1.5rem;
}
.docs-toc h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.docs-toc ol {
  margin: 0;
  padding-left: 1.3rem;
}
.docs-toc li {
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
}
.docs-toc a {
  color: #3498db;
  text-decoration: none;
}
.docs-toc a:hover { text-decoration: underline; }

/* Section styling */
.docs-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #f0f0f0;
}
.docs-section:last-child { border-bottom: none; }

.docs-section h3 {
  color: #2c3e50;
  font-size: 1.05rem;
  margin: 0 0 0.6rem;
  padding-top: 0.3rem;
}
.docs-section h4 {
  color: #34495e;
  font-size: 0.92rem;
  margin: 0.8rem 0 0.4rem;
}
.docs-section p,
.docs-section li {
  font-size: 0.85rem;
  line-height: 1.55;
  color: #444;
}
.docs-section ul {
  padding-left: 1.2rem;
  margin: 0.3rem 0;
}
.docs-section li { margin-bottom: 0.2rem; }

.docs-section code {
  background: #f4f4f4;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-size: 0.82rem;
  color: #c0392b;
}

/* Groups table */
.docs-groups-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 0.5rem 0;
}
.docs-groups-table th {
  background: #f8f9fa;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
  color: #495057;
}
.docs-groups-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}
.docs-groups-table tr:hover td { background: #f8f9fa; }
.docs-groups-table .mechanism-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 500;
}
.mechanism-pricelist { background: #e8f5e9; color: #2e7d32; }
.mechanism-stock { background: #e3f2fd; color: #1565c0; }
.mechanism-batch { background: #fff3e0; color: #e65100; }
.mechanism-image { background: #f3e5f5; color: #7b1fa2; }
.mechanism-separate { background: #fce4ec; color: #c62828; }

.docs-tip {
  background: #e8f4fd;
  border-left: 3px solid #3498db;
  padding: 0.5rem 0.8rem;
  margin: 0.5rem 0;
  border-radius: 0 4px 4px 0;
  font-size: 0.83rem;
  color: #2c3e50;
}

.spinner-sm {
  width: 16px; height: 16px;
  border: 2px solid #ddd;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
