.profiles-page,
.profile-form-page,
.profile-detail-page {
  display: grid;
  gap: 14px;
}

.profiles-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(10, 29, 48, 0.95), rgba(7, 18, 32, 0.9));
}

.profiles-hero h1 { margin: 2px 0 5px; }
.profiles-hero p { margin: 0; color: var(--muted); }
.profiles-hero a { color: var(--primary); font-weight: 800; }

.profile-primary-action,
.profile-card button,
.profile-detail-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid rgba(34, 197, 94, 0.6);
  border-radius: 9px;
  color: #04100a;
  background: var(--primary);
  padding: 0 13px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.profile-card,
.profile-form-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 18, 32, 0.82);
  padding: 14px;
}
.profile-card-active { border-color: rgba(34, 197, 94, 0.65); box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.15); }
.profile-card header { display: flex; justify-content: space-between; gap: 12px; }
.profile-card h2 { margin: 3px 0; }
.profile-card p { color: var(--muted); min-height: 40px; }
.profile-state { color: var(--muted); font-size: 11px; font-weight: 900; }
.profile-active-badge { align-self: start; border-radius: 999px; color: var(--primary); background: rgba(34, 197, 94, 0.12); padding: 6px 9px; font-size: 11px; }

.profile-rule-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 12px 0; }
.profile-rule-summary div { border: 1px solid rgba(148, 163, 184, 0.12); border-radius: 8px; padding: 8px; }
.profile-rule-summary dt { color: var(--muted); font-size: 11px; }
.profile-rule-summary dd { margin: 3px 0 0; font-weight: 800; overflow-wrap: anywhere; }
.profile-performance { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 12px; }
.profile-performance strong { color: var(--accent); }
.profile-card footer,
.profile-detail-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.profile-card footer a,
.profile-detail-actions a { color: var(--primary); font-weight: 800; }
.profile-card footer form,
.profile-detail-actions form { margin: 0; }

.profile-message,
.profile-error { border-radius: 9px; padding: 10px 12px; }
.profile-message { color: var(--primary); background: rgba(34, 197, 94, 0.1); }
.profile-error { color: #fecaca; background: rgba(239, 68, 68, 0.12); }

.profile-automation {
  --automation-color: var(--muted-2);
  display: grid;
  gap: 14px;
  border: 1px solid color-mix(in srgb, var(--automation-color) 38%, var(--border));
  border-left: 4px solid var(--automation-color);
  border-radius: 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--automation-color) 7%, rgba(7, 18, 32, .96)), rgba(7, 18, 32, .88));
  padding: 16px;
}
.profile-automation-healthy { --automation-color: var(--primary); }
.profile-automation-running { --automation-color: var(--accent); }
.profile-automation-due { --automation-color: #f59e0b; }
.profile-automation-failed { --automation-color: #ef4444; }
.profile-automation-waiting { --automation-color: #60a5fa; }
.profile-automation-header { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.profile-automation-header h2 { margin: 7px 0 5px; }
.profile-automation-header p { max-width: 760px; margin: 0; color: var(--muted); }
.profile-mode-badge { display: inline-flex; border-radius: 999px; color: var(--primary); background: rgba(34, 197, 94, .11); padding: 5px 9px; font-size: 11px; font-weight: 900; letter-spacing: .05em; }
.profile-worker-status { display: grid; flex: 0 1 380px; gap: 3px; border: 1px solid color-mix(in srgb, var(--automation-color) 35%, var(--border)); border-radius: 10px; background: rgba(2, 10, 20, .5); padding: 10px 12px; }
.profile-worker-status > span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.profile-worker-status > strong { color: var(--automation-color); font-size: 17px; }
.profile-worker-status > small { color: var(--muted); line-height: 1.35; }
.profile-automation-metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 0; }
.profile-automation-metrics > div { min-width: 0; border: 1px solid rgba(148, 163, 184, .12); border-radius: 9px; background: rgba(2, 10, 20, .42); padding: 10px; }
.profile-automation-metrics dt { min-height: 28px; color: var(--muted); font-size: 11px; }
.profile-automation-metrics dd { margin: 3px 0; color: var(--text); font-size: 21px; font-weight: 900; }
.profile-automation-metrics small { color: var(--muted); }
.profile-automation-timing { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.profile-automation-timing > div { display: grid; gap: 3px; min-width: 0; padding: 0 10px; border-left: 1px solid rgba(148, 163, 184, .16); }
.profile-automation-timing span { color: var(--muted); font-size: 11px; }
.profile-automation-timing strong { overflow-wrap: anywhere; font-size: 13px; }
.profile-latest-run { display: flex; align-items: center; flex-wrap: wrap; gap: 7px 12px; border-radius: 8px; background: rgba(148, 163, 184, .08); padding: 9px 11px; font-size: 12px; }
.profile-latest-run span { flex: 1 1 320px; color: var(--muted); }
.profile-latest-run code { border-radius: 5px; color: var(--accent); background: rgba(56, 189, 248, .1); padding: 3px 6px; }
.profile-latest-run-failed strong { color: #fca5a5; }
.profile-latest-run-completed strong { color: var(--primary); }
.profile-audit-note { margin: 0; color: var(--muted); font-size: 11px; }

.profile-form { display: grid; gap: 12px; }
.profile-form-section h2 { margin: 0 0 10px; }
.profile-form-section > p { color: var(--muted); }
.profile-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.profile-form label { display: grid; gap: 5px; }
.profile-form label > span { color: var(--muted); font-size: 12px; font-weight: 800; }
.profile-form input,
.profile-form select,
.profile-form textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: rgba(2, 10, 20, 0.8); padding: 9px; }
.profile-form small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.profile-form [hidden] { display: none !important; }
.profile-match-range { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.profile-field-wide { grid-column: 1 / -1; }
.profile-market-table { display: grid; gap: 7px; }
.profile-market-row { display: grid; grid-template-columns: minmax(160px, 1fr) repeat(2, minmax(120px, 1fr)); gap: 10px; align-items: end; border-bottom: 1px solid rgba(148, 163, 184, 0.1); padding: 8px 0; }
.profile-market-toggle { display: flex !important; align-items: center; }
.profile-market-toggle input,
.profile-check input { width: auto; }
.profile-sport-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 12px; }
.profile-option-card { display: flex !important; align-items: center; gap: 10px !important; min-height: 64px; border: 1px solid var(--border); border-radius: 9px; background: rgba(2, 10, 20, .55); padding: 10px; cursor: pointer; }
.profile-option-card:has(input:checked) { border-color: rgba(34, 197, 94, .55); background: rgba(34, 197, 94, .08); }
.profile-option-card input { width: auto; accent-color: var(--primary); }
.profile-option-card > span { display: grid; gap: 3px; }
.profile-option-card strong { color: var(--text); }
.profile-option-card small { color: var(--muted); }
.profile-check { display: flex !important; align-items: center; align-self: end; min-height: 39px; }
.profile-form-actions { display: flex; align-items: center; gap: 12px; }
.profile-form-actions a { color: var(--muted); }
.profile-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.profile-market-rule-list { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-market-rule-list span { border-radius: 999px; color: var(--accent); background: rgba(56, 189, 248, 0.1); padding: 7px 10px; }
.profile-danger-action { color: #fecaca !important; border-color: rgba(239, 68, 68, 0.5) !important; background: rgba(239, 68, 68, 0.12) !important; }
.profile-run-list { display: grid; gap: 8px; }
.profile-run { display: grid; grid-template-columns: minmax(170px, 1.4fr) repeat(4, minmax(80px, .6fr)); gap: 10px; align-items: center; border: 1px solid var(--border); border-left: 3px solid var(--muted-2); border-radius: 9px; background: rgba(2, 10, 20, .5); padding: 10px; }
.profile-run > div { display: grid; gap: 2px; }
.profile-run span { color: var(--muted); font-size: 11px; }
.profile-run p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; }
.profile-run-completed { border-left-color: var(--primary); }
.profile-run-failed { border-left-color: #ef4444; }
.profile-run-skipped { border-left-color: var(--accent); }

@media (max-width: 760px) {
  .profiles-hero { align-items: stretch; flex-direction: column; }
  .profile-grid,
  .profile-detail-grid,
  .profile-form-grid { grid-template-columns: 1fr; }
  .profile-field-wide { grid-column: auto; }
  .profile-match-range { grid-template-columns: 1fr; }
  .profile-market-row { grid-template-columns: 1fr; }
  .profile-sport-options { grid-template-columns: 1fr; }
  .profile-run { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-run > div:first-child,
  .profile-run p { grid-column: 1 / -1; }
  .profile-automation-header { align-items: stretch; flex-direction: column; }
  .profile-worker-status { flex-basis: auto; }
  .profile-automation-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-automation-timing { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 761px) and (max-width: 1180px) {
  .profile-automation-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .profile-automation-timing { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  .profile-automation-metrics,
  .profile-automation-timing { grid-template-columns: 1fr; }
}
