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

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #dee2e6;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-primary: #0d6efd;
  --color-primary-hover: #0b5ed7;
  --color-danger: #dc3545;
  --color-danger-hover: #bb2d3b;
  --color-secondary: #6c757d;
  --color-secondary-hover: #5c636a;
  --color-success-bg: #d1e7dd;
  --color-error-bg: #f8d7da;
  --color-error-text: #842029;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --spacing: 8px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.875em;
  background: #eef0f2;
  padding: 2px 5px;
  border-radius: 3px;
}

/* NAV */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 calc(var(--spacing) * 3);
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.nav-links {
  display: flex;
  gap: calc(var(--spacing) * 2.5);
  align-items: center;
}

.nav-links a {
  color: var(--color-text);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.15s ease;
}

.nav-links a:hover {
  color: var(--color-primary);
  text-decoration: none;
}

.nav-links a.active {
  color: var(--color-primary);
  font-weight: 600;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}

.nav-toggle__bar {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--color-text);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle--open .nav-toggle__bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.nav-toggle--open .nav-toggle__bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle--open .nav-toggle__bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.nav-logout {
  color: var(--color-text-muted) !important;
}

/* MAIN */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: calc(var(--spacing) * 4) calc(var(--spacing) * 3);
}

/* AUTH */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: calc(var(--spacing) * 3);
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: calc(var(--spacing) * 5);
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: calc(var(--spacing) * 2);
}

.auth-logo img {
  width: 180px;
  height: auto;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: calc(var(--spacing) * 0.5);
}

.auth-subtitle {
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 3);
  font-size: 0.9rem;
}

/* FORM */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2.5);
  margin-top: calc(var(--spacing) * 3);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 0.75);
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-group input {
  padding: calc(var(--spacing) * 1.25) calc(var(--spacing) * 1.5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.form-group input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* PREFIXED INPUT (scheme dropdown + text field) */
.input-with-prefix {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.input-prefix-select {
  flex: 0 0 auto;
  padding: calc(var(--spacing) * 1.25) calc(var(--spacing) * 1.25);
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--color-text);
  background: #f1f3f5;
  cursor: pointer;
  outline: none;
  appearance: auto;
}

.input-prefix-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
  z-index: 1;
  position: relative;
}

.input-with-prefix input {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 0 var(--radius) var(--radius) 0 !important;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.form-group--checkbox {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 0.5);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.75);
  font-size: 0.9rem;
  cursor: pointer;
}

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

.label-optional {
  font-weight: 400;
  color: var(--color-text-muted);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--spacing) * 1.25) calc(var(--spacing) * 2);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--color-secondary);
  color: #fff;
}

.btn-secondary:hover {
  background: var(--color-secondary-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--color-danger-hover);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: calc(var(--spacing) * 0.5) calc(var(--spacing) * 1.25);
  font-size: 0.8rem;
}

/* ALERTS */
.alert {
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid #f1aeb5;
}

/* CARDS */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: calc(var(--spacing) * 3);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(var(--spacing) * 3);
  display: flex;
  flex-direction: column;
}

.card .btn {
  margin-top: auto;
  align-self: flex-start;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: calc(var(--spacing));
}

.card-body {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 2);
}

/* TABLE */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table tbody tr:hover {
  background: #f8f9fa;
}

.text-muted {
  color: var(--color-text-muted);
}

/* PROVIDER PANEL */
.provider-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: calc(var(--spacing) * 3);
}

.provider-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: calc(var(--spacing) * 3);
}

.provider-panel__title {
  font-size: 1rem;
  font-weight: 600;
}

.provider-panel__close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 4px;
}

.provider-panel__close:hover {
  color: var(--color-text);
}

/* RADIO TYPE SELECTOR */
.radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--spacing) * 1.5);
  margin-bottom: calc(var(--spacing) * 3);
}

.radio-option {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 1.5);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: calc(var(--spacing) * 1.75) calc(var(--spacing) * 2);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  user-select: none;
}

.radio-option input[type="radio"] {
  display: none;
}

.radio-option:hover {
  border-color: var(--color-primary);
  background: #f0f6ff;
}

.radio-option--active {
  border-color: var(--color-primary);
  background: #f0f6ff;
}

.radio-option__icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.radio-option strong {
  display: block;
  font-size: 0.9rem;
}

.radio-option small {
  display: block;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 1px;
}

/* PROVIDER FORM */
.provider-form {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2.5);
}

.provider-form--hidden {
  display: none;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--spacing) * 2);
}

.form-group--half {
  max-width: 200px;
}

.provider-form__footer {
  display: flex;
  justify-content: flex-end;
  padding-top: calc(var(--spacing));
  border-top: 1px solid var(--color-border);
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge--blue {
  background: #dbeafe;
  color: #1e40af;
}

.badge--green {
  background: #dcfce7;
  color: #166534;
}

.badge--gray {
  background: #f1f5f9;
  color: #475569;
}

.badge--warning {
  background: #fef3c7;
  color: #92400e;
}

/* SEGMENTED CONTROL */
.seg-control {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-control__opt {
  display: flex;
  cursor: pointer;
}

.seg-control__opt input[type="radio"] {
  display: none;
}

.seg-control__opt span {
  display: block;
  padding: 5px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface);
  transition: background 0.12s ease, color 0.12s ease;
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
}

.seg-control__opt:last-child span {
  border-right: none;
}

.seg-control__opt input[type="radio"]:checked + span {
  background: var(--color-primary);
  color: #fff;
}

/* TABLE ACTIONS */
.table-actions {
  display: flex;
  gap: calc(var(--spacing) * 0.75);
  align-items: center;
  white-space: nowrap;
}

/* DETAILS EXPAND */
.details-toggle {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.details-toggle:hover {
  color: var(--primary-dark, var(--primary));
}
.details-expanded {
  margin-top: 6px;
}
.details-value {
  display: block;
  font-size: 0.78rem;
  word-break: break-all;
  color: var(--text-muted);
  background: var(--bg-subtle, #f5f5f5);
  padding: 4px 6px;
  border-radius: 4px;
  max-width: 480px;
}

/* INACTIVE ROW */
.row--inactive td {
  opacity: 0.5;
}

/* TOGGLE BUTTON */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 6px;
  border: 1px solid transparent;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.toggle-btn__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toggle-btn--active {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.toggle-btn--active .toggle-btn__dot {
  background: #16a34a;
}

.toggle-btn--active:hover {
  background: #bbf7d0;
}

.toggle-btn--inactive {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #64748b;
}

.toggle-btn--inactive .toggle-btn__dot {
  background: #94a3b8;
}

.toggle-btn--inactive:hover {
  background: #e2e8f0;
}

/* INLINE EDIT ROW */
.edit-row__cell {
  background: #f8f9fa;
  border-top: none !important;
  padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2) !important;
}

.inline-edit-form {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 1.5);
}

.inline-edit-fields {
  display: flex;
  gap: calc(var(--spacing) * 2);
  flex-wrap: wrap;
  align-items: flex-end;
}

.inline-edit-fields .form-group {
  flex: 1;
  min-width: 140px;
}

.inline-edit-fields .form-group--sm {
  flex: 0 0 100px;
}

.inline-edit-actions {
  display: flex;
  gap: calc(var(--spacing));
  justify-content: flex-end;
  padding-top: calc(var(--spacing));
  border-top: 1px solid var(--color-border);
}

/* SCHEDULE LIST */
.schedule-list {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2);
  margin-top: calc(var(--spacing) * 2);
}

.schedule-card {
  padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 3);
}

.schedule-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--spacing) * 2);
}

.schedule-card__info {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 1.25);
}

.schedule-card__name {
  font-size: 0.95rem;
}

.schedule-card__actions {
  display: flex;
  gap: calc(var(--spacing));
  flex-shrink: 0;
}

.schedule-card__status {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 2);
  margin-top: calc(var(--spacing) * 1.5);
  flex-wrap: wrap;
}

.schedule-form-panel {
  margin-top: calc(var(--spacing) * 2.5);
  padding-top: calc(var(--spacing) * 2.5);
  border-top: 1px solid var(--color-border);
}

.schedule-form__row {
  display: flex;
  gap: calc(var(--spacing) * 2.5);
  flex-wrap: wrap;
  align-items: flex-start;
}

.schedule-trigger-field {
  flex: 1;
  min-width: 180px;
}

.schedule-form__footer {
  display: flex;
  gap: calc(var(--spacing));
  margin-top: calc(var(--spacing) * 2);
  padding-top: calc(var(--spacing) * 2);
  border-top: 1px solid var(--color-border);
  justify-content: flex-end;
}

/* TOGGLE SWITCH */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin-top: calc(var(--spacing) * 0.5);
}

.toggle-switch input[type="checkbox"] {
  display: none;
}

.toggle-switch__track {
  width: 40px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 99px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-switch__track {
  background: var(--color-primary);
}

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

/* EMPTY STATE */
.empty-state {
  margin-top: calc(var(--spacing) * 5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  padding: calc(var(--spacing) * 6) 0;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
}

/* ===========================
  DATABASE INSPECTOR
   =========================== */

.lib-danger-zone {
  display: flex;
  gap: calc(var(--spacing));
  align-items: center;
  flex-shrink: 0;
}

.lib-counts {
  display: flex;
  gap: calc(var(--spacing) * 2);
  margin-bottom: calc(var(--spacing) * 3);
}

.lib-count-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3);
  min-width: 110px;
  text-align: center;
  box-shadow: var(--shadow);
}

.lib-count-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-text);
}

.lib-count-card__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.lib-tabs {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: calc(var(--spacing) * 2);
  gap: 0;
}

.lib-tab {
  padding: calc(var(--spacing) * 1.25) calc(var(--spacing) * 2.5);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.lib-tab:hover {
  color: var(--color-text);
  text-decoration: none;
}

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

.lib-table-card {
  padding: 0;
  overflow: hidden;
}

.lib-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.lib-table {
  font-size: 0.8rem;
  white-space: nowrap;
}

.lib-table th {
  font-size: 0.72rem;
  background: #f8f9fa;
  position: sticky;
  top: 0;
}

.lib-table td {
  vertical-align: middle;
}

.lib-hash {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 3px;
}

.lib-title {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-url {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.lib-date {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.lib-id {
  color: var(--color-text-muted);
  font-size: 0.78rem;
}

/* Content-type badges */
.lib-type-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lib-type-badge--movie   { background: #dbeafe; color: #1e40af; }
.lib-type-badge--series  { background: #dcfce7; color: #166534; }
.lib-type-badge--live    { background: #fef9c3; color: #854d0e; }
.lib-type-badge--tv_vod  { background: #fce7f3; color: #9d174d; }
.lib-type-badge--unsorted { background: #f1f5f9; color: #475569; }

/* Pagination */
.lib-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2.5);
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.lib-pagination__btns {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing));
}

.lib-pagination__page {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Success alert (library) */
.alert-success {
  background: var(--color-success-bg);
  color: #0a3622;
  border: 1px solid #a3cfbb;
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

/* ===========================
   SCHEDULE SECTION HEADERS
   =========================== */

.sched-section {
  margin-bottom: calc(var(--spacing) * 5);
}

.sched-section__title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 0.5);
}

.sched-section__desc {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 2);
}

/* ===========================
   PROVIDER TASK TABLE
   =========================== */

.provider-task-table .provider-task-table__name {
  font-weight: 500;
}

.provider-task-table td {
  vertical-align: middle;
}

.provider-task-table .toggle-btn,
.provider-task-table .btn {
  white-space: nowrap;
}

/* ===========================
   LIBRARY — METADATA INSPECTOR
   =========================== */

.lib-table--streams .lib-meta-cell {
  width: 120px;
  white-space: nowrap;
}

.lib-meta-details summary.lib-meta-summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-primary, #2563eb);
  user-select: none;
  list-style: none;
  padding: 2px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  display: inline-block;
}

.lib-meta-details summary.lib-meta-summary::-webkit-details-marker {
  display: none;
}

.lib-meta-details[open] summary.lib-meta-summary {
  margin-bottom: 6px;
}

.lib-meta-blob {
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--color-surface-alt, #f8fafc);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 6px;
  padding: 8px 10px;
  max-width: 480px;
  max-height: 260px;
  overflow-y: auto;
  position: absolute;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.lib-filtered-changed {
  color: var(--color-primary);
  font-style: italic;
}

.lib-flag {
  text-align: center;
  white-space: nowrap;
}

.lib-flag--yes {
  display: inline-block;
  background: #fff3cd;
  color: #664d03;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 6px;
}

.lib-flag--info {
  display: inline-block;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 6px;
}

/* ── sortable headers ── */
.lib-th-sort {
  white-space: nowrap;
}

.lib-th-link {
  display: block;
  color: inherit;
  text-decoration: none;
  user-select: none;
}

.lib-th-link:hover {
  color: var(--color-primary);
}

.lib-th-sort::after {
  content: "";
  display: inline-block;
  margin-left: 4px;
  opacity: 0.3;
  font-size: 0.7em;
}

.lib-th--asc::after  { content: "▲"; opacity: 1; }
.lib-th--desc::after { content: "▼"; opacity: 1; }

.lib-th-center { text-align: center; }

/* ── expand column ── */
.lib-th-expand { width: 32px; }

.lib-expand-cell { width: 32px; text-align: center; }

.lib-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.lib-expand-btn:hover,
.lib-expand-btn--open {
  color: var(--color-primary);
  background: #eff6ff;
}

/* ── detail row ── */
.lib-detail-row td {
  background: #f8fafc;
  border-top: none !important;
  padding: 0 !important;
}

.lib-detail-body {
  padding: 12px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--color-border);
}

.lib-detail-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lib-detail-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.lib-detail-value {
  font-size: 0.83rem;
  word-break: break-all;
}

.lib-detail-url {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--color-text);
  word-break: break-all;
}

.lib-detail-orig {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-left: 6px;
}

.lib-detail-pre {
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 6px 8px;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
}

.lib-streams-inner {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-top: 4px;
}

.lib-streams-inner th,
.lib-streams-inner td {
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  vertical-align: top;
}

.lib-streams-inner th {
  background: var(--color-surface);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.lib-streams-inner .lib-detail-url {
  font-size: 0.72rem;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

/* ── search bar ── */
.lib-search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.lib-search-input {
  flex: 1;
  max-width: 380px;
  padding: 7px 12px;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.lib-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

.lib-search-count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* local file provider form */
.form-hint--warn {
  color: var(--color-warning, #b45309);
  font-size: 0.82rem;
  margin: 0;
}

/* ===========================
   FILE BROWSER
   =========================== */

.file-browser {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.fb-toolbar {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  border-bottom: 1px solid var(--color-border);
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.fb-path {
  font-family: "SFMono-Regular", Consolas, monospace;
  word-break: break-all;
}

.fb-list {
  padding: 4px 0;
}

.fb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  user-select: none;
}

.fb-item:hover {
  background: #e8f0fe;
}

.fb-item--dir {
  color: var(--color-text);
  font-weight: 500;
}

.fb-item--file {
  color: var(--color-text-muted);
}

.fb-item--selected {
  background: #dbeafe;
  color: var(--color-primary);
  font-weight: 600;
}

.fb-item--selected:hover {
  background: #bfdbfe;
}

.fb-icon {
  font-size: 0.95rem;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.fb-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fb-empty {
  padding: 12px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.fb-loading, .fb-error {
  padding: 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.fb-error { color: var(--color-danger); }

.file-browser-selected {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 4px 0 2px;
}

.file-browser-selected__path {
  font-family: "SFMono-Regular", Consolas, monospace;
  word-break: break-all;
  color: var(--color-text);
}

.file-browser-selected__placeholder {
  color: var(--color-text-muted);
  font-style: italic;
}

.file-browser-selected__icon {
  flex-shrink: 0;
}

/* ===========================
   FILTERS PAGE
   =========================== */

.filter-header-actions {
  display: flex;
  gap: calc(var(--spacing));
  align-items: center;
  flex-shrink: 0;
}

/* Panel (add / edit drawer) */
.filter-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: calc(var(--spacing) * 3);
  margin-bottom: calc(var(--spacing) * 4);
}

.filter-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: calc(var(--spacing) * 2.5);
}

.filter-panel__title {
  font-size: 1rem;
  font-weight: 600;
}

.filter-panel__close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 4px;
  line-height: 1;
}

.filter-panel__close:hover { color: var(--color-text); }

/* Step label */
.filter-step-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 1.5);
}

.filter-step-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: calc(var(--spacing) * 2);
}

/* Type picker grid */
.filter-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: calc(var(--spacing) * 1.5);
  margin-bottom: calc(var(--spacing) * 2);
}

.filter-type-opt {
  display: flex;
  align-items: flex-start;
  gap: calc(var(--spacing) * 1.25);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: calc(var(--spacing) * 1.75) calc(var(--spacing) * 2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.filter-type-opt input[type="radio"] { display: none; }

.filter-type-opt:hover {
  border-color: var(--color-primary);
  background: #f0f6ff;
}

.filter-type-opt--active {
  border-color: var(--color-primary);
  background: #f0f6ff;
}

.filter-type-opt__body strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.filter-type-opt__body small {
  display: block;
  font-size: 0.76rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Form body layout */
.filter-form-body {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2.5);
  margin-bottom: calc(var(--spacing) * 2.5);
}

.filter-form-meta-row {
  display: flex;
  gap: calc(var(--spacing) * 2);
  align-items: flex-start;
}

.filter-form-meta-row .form-group { flex: 1; }
.filter-form-order { flex: 0 0 100px !important; }

/* Literal mode toggle */
.filter-literal-group {
  margin-bottom: calc(var(--spacing) * 1.5);
}

.filter-literal-label {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.75);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.filter-literal-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-primary, #0d6efd);
}

.filter-literal-hint {
  font-size: 0.78rem;
  font-weight: 400;
}

.filter-meta-input {
  width: 100%;
  padding: calc(var(--spacing) * 1.25) calc(var(--spacing) * 1.5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-meta-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* Scope chips */
.filter-scope-row {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing));
  margin-top: calc(var(--spacing) * 0.75);
}

.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border: 1px solid var(--color-border);
  border-radius: 99px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}

.scope-chip input[type="checkbox"] { display: none; }

.scope-chip:has(input:checked) {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
  font-weight: 600;
}

.scope-chip:hover {
  border-color: var(--color-primary);
  background: #f0f6ff;
}

/* Pattern list */
.filter-pattern-list {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing));
  margin-bottom: calc(var(--spacing));
}

.filter-row {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing));
}

.filter-input {
  flex: 1;
  padding: calc(var(--spacing)) calc(var(--spacing) * 1.25);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color 0.15s;
}

.filter-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.filter-input--repl { background: #f8f9fa; }

.filter-arrow {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  flex-shrink: 0;
  padding: 0 2px;
}

/* Pattern previews (read-only) */
.filter-card__patterns {
  margin-top: calc(var(--spacing) * 1.25);
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing) * 0.75);
}

.filter-pattern-preview {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.filter-code {
  background: #eef0f2;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 0.78rem;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.filter-code--repl {
  background: #dcfce7;
  color: #166534;
}

/* Form footer */
.filter-form-footer {
  display: flex;
  justify-content: flex-end;
  gap: calc(var(--spacing));
  padding-top: calc(var(--spacing) * 2);
  border-top: 1px solid var(--color-border);
}

/* Filter sections */
.filter-section {
  margin-bottom: calc(var(--spacing) * 4);
}

.filter-section__header {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 1.5);
  margin-bottom: calc(var(--spacing) * 1.5);
}

.filter-section__title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.filter-section__count { font-size: 0.75rem; }

/* Filter cards */
.filter-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2.5);
  margin-bottom: calc(var(--spacing) * 1.5);
  transition: opacity 0.15s;
}

.filter-card--disabled { opacity: 0.55; }

.filter-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--spacing) * 2);
  flex-wrap: wrap;
}

.filter-card__meta {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 1.25);
  flex-wrap: wrap;
  flex: 1;
}

.filter-card__label { font-weight: 600; font-size: 0.9rem; }
.filter-card__label--auto { font-weight: 400; color: var(--color-text-muted); font-style: italic; }
.filter-card__order { font-size: 0.75rem; }

.filter-card__actions {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.75);
  flex-shrink: 0;
}

/* Inline edit panel */
.filter-edit-panel {
  margin-top: calc(var(--spacing) * 2);
  padding-top: calc(var(--spacing) * 2);
  border-top: 1px solid var(--color-border);
}

/* ── Confirmation modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.app-dialog__message {
  margin: 0;
  white-space: pre-wrap;
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  margin: var(--spacing);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal__header {
  padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2) 0;
}

.modal__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.modal__body {
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.modal__list {
  margin: calc(var(--spacing) * 0.75) 0 calc(var(--spacing) * 0.75) calc(var(--spacing) * 1.5);
  padding: 0;
  line-height: 1.7;
}

.modal__warning {
  margin-top: calc(var(--spacing) * 1);
  color: var(--color-error, #c0392b);
  font-size: 0.82rem;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: calc(var(--spacing) * 0.75);
  padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
  border-top: 1px solid var(--color-border);
}

/* ── Quality Terms ──────────────────────────────────────────────────────── */
.quality-section {
  margin-top: calc(var(--spacing) * 2);
  padding-top: calc(var(--spacing) * 2);
  border-top: 1px solid var(--color-border);
}

.quality-section__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: calc(var(--spacing) * 0.75);
  display: block;
}

.quality-section__hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: calc(var(--spacing) * 1.25);
  line-height: 1.4;
}

.quality-tags {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing) * 0.75);
  margin-bottom: calc(var(--spacing) * 1.25);
  min-height: 28px;
}

.quality-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #e8f0fe;
  color: #1a56db;
  border: 1px solid #c3d3fd;
  border-radius: 4px;
  padding: 2px 8px 2px 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: default;
}

.quality-tag__remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #4b72c9;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  display: flex;
  align-items: center;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.quality-tag__remove:hover {
  opacity: 1;
  color: var(--color-danger);
}

.quality-add-row {
  display: flex;
  gap: calc(var(--spacing) * 0.75);
  align-items: center;
}

.quality-add-input {
  font-size: 0.875rem;
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 180px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s;
}

.quality-add-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

.quality-add-btn {
  font-size: 0.8125rem;
  padding: 5px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.quality-add-btn:hover {
  background: #f1f3f5;
  border-color: #adb5bd;
}

.quality-empty {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ===========================
   VERSION DISPLAY
   =========================== */

.update-badge {
  background: var(--color-danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 9999px;
  animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
