/* ServerPACS Web Operations Panel v649 - layout fix */
:root {
  --sp-bg: #0f172a;
  --sp-panel: #111827;
  --sp-panel2: #182235;
  --sp-text: #e5e7eb;
  --sp-muted: #9ca3af;
  --sp-line: rgba(148, 163, 184, .25);
  --sp-primary: #38bdf8;
  --sp-warn: #f59e0b;
  --sp-danger: #ef4444;
  --sp-ok: #22c55e;
  --sp-shadow: 0 18px 60px rgba(0,0,0,.34);
}
body.sp-light,
[data-theme="light"],
html.light {
  --sp-bg: #f8fafc;
  --sp-panel: #ffffff;
  --sp-panel2: #f1f5f9;
  --sp-text: #0f172a;
  --sp-muted: #475569;
  --sp-line: rgba(15, 23, 42, .14);
  --sp-primary: #0284c7;
  --sp-warn: #b45309;
  --sp-danger: #dc2626;
  --sp-ok: #16a34a;
  --sp-shadow: 0 14px 35px rgba(15,23,42,.18);
}
#servpacs-ops-root {
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.sp-ops-open {
  border: 1px solid rgba(56,189,248,.45);
  background: linear-gradient(180deg, rgba(56,189,248,.18), rgba(14,165,233,.12));
  color: var(--sp-text);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  min-height: 42px;
  box-shadow: 0 8px 25px rgba(0,0,0,.22);
}
.sp-ops-overlay {
  position: fixed;
  inset: 0;
  z-index: 99990;
  display: none;
  background: rgba(2, 6, 23, .68);
  backdrop-filter: blur(4px);
}
.sp-ops-overlay.open { display: flex; align-items: center; justify-content: center; padding: 18px; }
.sp-ops-modal {
  width: min(1120px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--sp-line);
  background: linear-gradient(180deg, var(--sp-panel), var(--sp-bg));
  box-shadow: var(--sp-shadow);
}
.sp-ops-close {
  border: 1px solid var(--sp-line);
  background: rgba(148,163,184,.12);
  color: var(--sp-text);
  border-radius: 12px;
  min-width: 38px;
  height: 38px;
  font-size: 22px;
  cursor: pointer;
}
.sp-ops-shell {
  display: grid;
  gap: 12px;
  padding: 14px;
  color: var(--sp-text);
  box-sizing: border-box;
  min-width: 0;
  max-height: inherit;
  overflow: auto;
}
.sp-ops-shell * { box-sizing: border-box; }
.sp-ops-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 2px 0 10px;
  background: linear-gradient(180deg, var(--sp-panel), rgba(17,24,39,.86));
}
.sp-ops-title { display: grid; gap: 3px; min-width: 0; }
.sp-ops-title h2 { margin: 0; font-size: clamp(16px, 2vw, 20px); font-weight: 850; }
.sp-ops-title span { color: var(--sp-muted); font-size: 12px; line-height: 1.35; }
.sp-ops-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sp-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--sp-line);
  padding-bottom: 8px;
}
.sp-tab {
  border: 1px solid var(--sp-line);
  background: rgba(148,163,184,.10);
  color: var(--sp-text);
  border-radius: 999px;
  padding: 9px 13px;
  font-weight: 800;
  cursor: pointer;
}
.sp-tab.active { border-color: rgba(56,189,248,.55); background: rgba(56,189,248,.18); }
.sp-tab-panel { display: none; }
.sp-tab-panel.active { display: block; }
.sp-ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 12px;
}
.sp-card {
  background: linear-gradient(180deg, var(--sp-panel), var(--sp-panel2));
  border: 1px solid var(--sp-line);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(0,0,0,.16);
  overflow: hidden;
  min-width: 0;
}
.sp-card-hd {
  padding: 12px 14px;
  border-bottom: 1px solid var(--sp-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.sp-card-hd h3 { margin: 0; font-size: 15px; font-weight: 850; }
.sp-card-hd small { color: var(--sp-muted); font-size: 12px; }
.sp-card-bd { padding: 12px 14px; display: grid; gap: 12px; }
.sp-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; min-width: 0; }
.sp-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; width: 100%; }
.sp-field { display: grid; gap: 5px; flex: 1 1 170px; min-width: min(170px, 100%); }
.sp-field.wide { flex-basis: 100%; }
.sp-field label { font-size: 12px; color: var(--sp-muted); font-weight: 750; }
.sp-field input,
.sp-field select,
.sp-field textarea {
  width: 100%;
  min-width: 0;
  background: rgba(15,23,42,.08);
  color: var(--sp-text);
  border: 1px solid var(--sp-line);
  border-radius: 10px;
  padding: 9px 10px;
  outline: none;
  font-size: 13px;
}
.sp-field textarea { min-height: 78px; resize: vertical; }
.sp-btn {
  border: 1px solid var(--sp-line);
  background: rgba(148,163,184,.12);
  color: var(--sp-text);
  border-radius: 12px;
  padding: 9px 11px;
  font-weight: 800;
  cursor: pointer;
  min-height: 38px;
  white-space: normal;
  line-height: 1.15;
}
.sp-btn:hover { border-color: var(--sp-primary); }
.sp-btn.primary { background: rgba(56,189,248,.16); border-color: rgba(56,189,248,.45); }
.sp-btn.ok { background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.45); }
.sp-btn.warn { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.45); }
.sp-btn.danger { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.45); }
.sp-btn:disabled { opacity: .55; cursor: not-allowed; }
.sp-status {
  border: 1px solid var(--sp-line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--sp-muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  max-height: 230px;
  overflow: auto;
  margin: 0;
  background: rgba(2,6,23,.16);
}
.sp-status.ok { color: var(--sp-ok); }
.sp-status.err { color: var(--sp-danger); }
.sp-status.warn { color: var(--sp-warn); }
.sp-badge { font-size: 12px; color: var(--sp-muted); border: 1px solid var(--sp-line); border-radius: 999px; padding: 6px 9px; }
.sp-results { display: grid; gap: 8px; max-height: 330px; overflow: auto; }
.sp-result-item { border: 1px solid var(--sp-line); border-radius: 12px; padding: 10px; background: rgba(148,163,184,.08); min-width: 0; }
.sp-result-item strong { display:block; margin-bottom: 4px; overflow-wrap: anywhere; }
.sp-result-item code { color: var(--sp-muted); font-size: 12px; word-break: break-all; }
.sp-note { color: var(--sp-muted); font-size: 12px; line-height: 1.35; }
/* Defensive fixes for crowded layouts */
.sp-ops-shell table, .sp-ops-shell pre, .sp-ops-shell code { max-width: 100%; }
@media (max-width: 720px) {
  .sp-ops-overlay.open { padding: 8px; }
  .sp-ops-modal { width: calc(100vw - 16px); max-height: calc(100vh - 16px); border-radius: 14px; }
  .sp-ops-shell { padding: 10px; gap: 10px; }
  .sp-ops-header { position: static; }
  .sp-buttons { grid-template-columns: 1fr; }
  .sp-field { flex-basis: 100%; }
}
/* If the panel is accidentally inserted inside the left sidebar, keep it usable instead of broken. */
#servpacs-ops-root .sp-ops-shell.sp-narrow-inline .sp-ops-grid { grid-template-columns: 1fr; }
#servpacs-ops-root .sp-ops-shell.sp-narrow-inline .sp-buttons { grid-template-columns: 1fr; }
#servpacs-ops-root .sp-ops-shell.sp-narrow-inline .sp-field { flex-basis: 100%; }


/* v649: pestañas siempre visibles dentro del drawer y menú recuperable */
.sp-ops-overlay.open { z-index: 100000 !important; }
.sp-ops-modal { display: flex; flex-direction: column; }
.sp-ops-shell { overflow: auto; }
.sp-tabs {
  position: sticky;
  top: 58px;
  z-index: 5;
  background: linear-gradient(180deg, var(--sp-panel), rgba(17,24,39,.94));
  padding-top: 6px;
}
.sp-tab { min-width: 150px; text-align: center; }
.sp-tab-panel { padding-top: 6px; }
.sp-ops-open {
  position: relative;
  z-index: 20;
}
.sp-status.err::before { content: 'ERROR: '; font-weight: 900; }
@media (max-width: 720px) {
  .sp-tabs { top: 0; }
  .sp-tab { min-width: 0; flex: 1 1 140px; }
}

/* v660: asegurar drawer por encima sin ocupar layout */
#servpacs-ops-root{display:block;margin:8px 0 10px 0}
.sp-ops-drawer,.sp-ops-modal{z-index:10000}
/* Query/Retrieve tiene su panel especializado v605; se evita duplicarlo aquí. */
[data-sp-tab-panel="qr"] { display: none !important; }
