/* ============================================================
 * Practice Operations Console — cyan/teal palette
 *
 * Per ADR-022: distinct color palette per mock-* admin UI for
 * visual differentiation from sibling consoles. mock-practices is
 * cyan/teal (provider-side, calm); mock-payer is amber/orange.
 * ============================================================ */

:root {
  --primary: #0891B2;          /* sky-600 */
  --primary-dark: #0E7490;     /* sky-700 */
  --primary-light: #67E8F9;    /* cyan-300 */
  --accent: #06B6D4;           /* cyan-500 */
  --bg: #ECFEFF;               /* sky-50 */
  --bg-card: #FFFFFF;
  --bg-shell: #F0F9FF;         /* sky-50 lighter */
  --border: #7DD3FC;           /* sky-300 */
  --border-strong: #38BDF8;    /* sky-400 */
  --text: #0C4A6E;             /* sky-900 */
  --text-muted: #64748B;       /* slate-500 */
  --text-on-primary: #FFFFFF;
  --status-ok: #16A34A;        /* green-600 */
  --status-paused: #D97706;    /* amber-600 */
  --status-error: #DC2626;     /* red-600 */
  --shadow-sm: 0 1px 2px rgba(8, 145, 178, 0.08);
  --shadow-md: 0 4px 12px rgba(8, 145, 178, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-shell);
  color: var(--text);
  line-height: 1.5;
}

/* ----- Top bar ---------------------------------------------- */
.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--text-on-primary);
  padding: 24px 0;
  box-shadow: var(--shadow-md);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}
.brand {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  font-size: 28px;
  color: var(--primary-light);
}
.brand-name { letter-spacing: -0.01em; }
.subtitle {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  opacity: 0.85;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ----- Container + cards ------------------------------------ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.card-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 20px; }

/* ----- Status pill ------------------------------------------ */
.status-pill {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  background: #E2E8F0;
  color: var(--text-muted);
}
.status-pill[data-state="running"] {
  background: #DCFCE7;  /* green-100 */
  color: var(--status-ok);
}
.status-pill[data-state="paused"] {
  background: #FEF3C7;  /* amber-100 */
  color: var(--status-paused);
}
.status-pill[data-state="error"] {
  background: #FEE2E2;  /* red-100 */
  color: var(--status-error);
}

/* ----- Key/value grid --------------------------------------- */
.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0;
}
.kv-grid dt {
  color: var(--text-muted);
  font-size: 13px;
}
.kv-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

/* ----- Tick interval row ------------------------------------ */
.interval-row {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.interval-row label {
  font-size: 14px;
  color: var(--text-muted);
}
.interval-row input[type="number"] {
  width: 80px;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--bg-card);
  color: var(--text);
}
.interval-row input[type="number"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.interval-row input[aria-invalid="true"] {
  border-color: var(--status-error);
  outline-color: var(--status-error);
}

/* ----- Action buttons --------------------------------------- */
.actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.btn {
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--primary-dark);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-link {
  background: transparent;
  color: var(--primary-dark);
  text-decoration: underline;
  padding: 8px 4px;
}

/* ----- Roster grid ------------------------------------------ */
.roster-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.roster-block-wide {
  grid-column: 1 / -1;
}
.roster-block h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.roster-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.roster-list li {
  font-size: 14px;
  padding: 4px 0;
  border-bottom: 1px dotted var(--border);
}
.roster-list li:last-child { border-bottom: none; }
.roster-list .roster-parent { font-weight: 600; }
.roster-list .roster-child {
  padding-left: 16px;
  position: relative;
}
.roster-list .roster-child::before {
  content: "└─";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

/* ----- Payer mix bar chart ---------------------------------- */
.payer-mix-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}
.payer-mix-row {
  display: grid;
  grid-template-columns: 140px 1fr 60px;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.payer-mix-bar {
  height: 14px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.payer-mix-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--primary) 100%);
}
.payer-mix-pct { text-align: right; font-variant-numeric: tabular-nums; }

/* ----- Data table (Recent Activity) ------------------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ----- Service Requests section (QA-250 2c) ----------------- */
.sr-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.sr-filter-row label {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.sr-filter-row select,
.sr-filter-row input[type="search"] {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text);
  min-width: 140px;
}
.sr-search-label { flex: 1; min-width: 200px; }
.sr-search-label input { width: 100%; }

.sr-table tbody tr {
  cursor: pointer;
}
.sr-status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  background: #E2E8F0;
  color: var(--text-muted);
  white-space: nowrap;
}
.sr-status-badge[data-state="APPROVED"] { background: #DCFCE7; color: var(--status-ok); }
.sr-status-badge[data-state="PENDING"] { background: #DBEAFE; color: #1D4ED8; }
.sr-status-badge[data-state="SUBMITTED"] { background: #DBEAFE; color: #1D4ED8; }
.sr-status-badge[data-state="NEEDS_INFO"] { background: #FEF3C7; color: var(--status-paused); }
.sr-status-badge[data-state="DENIED"] { background: #FEE2E2; color: var(--status-error); }
.sr-status-badge[data-state="ERROR"] { background: #FEE2E2; color: var(--status-error); }
.sr-status-badge[data-state="SKIPPED_BY_CRD"] { background: #E0E7FF; color: #4338CA; }
.sr-status-badge[data-state="SKIPPED_BY_BUNDLE_VALIDATION"] { background: #E0E7FF; color: #4338CA; }
.sr-status-badge[data-state="NO_PIPELINE"] { background: #F1F5F9; color: var(--text-muted); font-style: italic; }

.sr-pa-outcome {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sr-pa-auth-num {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--status-ok);
}
.sr-pa-detail {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.sr-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sr-pagination .btn:disabled { opacity: 0.4; }

/* ----- Detail dialog (3 tabs + JSON viewer) ----------------- */
.dialog-lg {
  max-width: 900px;
  width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.dialog-header h3 { margin: 0; }
.dialog-tabs {
  display: flex;
  gap: 4px;
  margin: 12px 0 0 0;
  border-bottom: 1px solid var(--border);
}
.dialog-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.dialog-tab[aria-selected="true"] {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.dialog-tab:hover:not([aria-selected="true"]) {
  color: var(--primary);
}
.dialog-tab-body {
  flex: 1;
  overflow: auto;
  margin-top: 12px;
}
.json-viewer {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  margin: 0;
  white-space: pre;
  overflow: auto;
  color: var(--text);
}
.json-viewer.json-empty {
  color: var(--text-muted);
  font-style: italic;
  font-family: inherit;
  font-size: 14px;
  text-align: center;
  white-space: normal;
  padding: 32px;
}

/* ----- Misc ------------------------------------------------- */
.muted { color: var(--text-muted); font-size: 13px; }
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ----- Toast notifications ---------------------------------- */
#toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: grid;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
  font-size: 14px;
  min-width: 240px;
  max-width: 360px;
  animation: toast-in 0.18s ease-out;
}
.toast.toast-success { border-left-color: var(--status-ok); }
.toast.toast-error { border-left-color: var(--status-error); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ----- Confirm dialog overlay ------------------------------- */
/* Default hidden — opened via JS adding .is-open. The HTML `hidden`
 * attribute is unreliable here because author `display` rules override
 * it. Use class-toggled display instead. */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 47, 73, 0.4);
  display: none;
  place-items: center;
  z-index: 999;
}
.dialog-overlay.is-open {
  display: grid;
  animation: overlay-in 0.12s ease-out;
}
.dialog {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(8, 47, 73, 0.3);
}
.dialog h3 {
  margin: 0 0 12px 0;
  font-size: 17px;
}
.dialog p {
  margin: 0 0 20px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.dialog .actions { margin-top: 0; justify-content: flex-end; }
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ----- Responsive ------------------------------------------- */
@media (max-width: 800px) {
  .roster-grid { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .card-body { padding: 16px; }
}
