:root {
  --bg: #08131f;
  --bg-2: #0f2941;
  --sidebar-bg: rgba(5, 14, 24, 0.97);
  --panel: rgba(9, 24, 39, 0.82);
  --panel-border: rgba(122, 190, 242, 0.18);
  --text: #ecf6ff;
  --muted: #7fa4be;
  --accent: #66e1d2;
  --accent-2: #ffcf6e;
  --error: #ff8f8f;
  --sidebar-w: 288px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 20%, #1f3857, var(--bg) 45%),
    linear-gradient(150deg, var(--bg), var(--bg-2));
  display: flex;
}

/* ── Background decorations ─────────────────────────────── */
.bg-glow {
  position: fixed; inset: -25% -10% auto auto;
  width: 40vw; height: 40vw;
  background: radial-gradient(circle, rgba(79, 209, 197, 0.18), transparent);
  pointer-events: none; z-index: 0;
}
.mesh {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none; z-index: 0;
}

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--panel-border);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  z-index: 10;
  padding-bottom: 2rem;
}

.sidebar-brand {
  padding: 1.4rem 1.2rem 1.1rem;
  border-bottom: 1px solid rgba(122, 190, 242, 0.1);
  flex-shrink: 0;
}
.sidebar-brand .eyebrow {
  font-size: 0.65rem; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--accent-2);
}
.sidebar-brand h1 {
  font-size: 1rem; font-weight: 700; margin-top: 0.25rem; line-height: 1.3;
}

.sidebar-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.9rem 1rem 0.8rem;
  border-bottom: 1px solid rgba(122, 190, 242, 0.07);
}

.sidebar-nav-btn {
  border: 1px solid rgba(164, 207, 241, 0.22);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.5rem;
  cursor: pointer;
}

.sidebar-nav-btn.active {
  border-color: rgba(102, 225, 210, 0.42);
  background: rgba(102, 225, 210, 0.08);
  color: var(--accent);
}

.sidebar-section {
  padding: 0.9rem 1rem 0.7rem;
  border-bottom: 1px solid rgba(122, 190, 242, 0.07);
  flex-shrink: 0;
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.55rem;
}
.sidebar-section-title {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); font-weight: 600;
}

/* sidebar dropdown */
.sidebar-select {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: rgba(8, 27, 45, 0.82);
  color: var(--text);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font-size: 0.86rem;
  cursor: pointer;
}
.sidebar-select:focus { outline: none; border-color: var(--accent); }

/* sidebar form */
.sidebar-form { display: grid; gap: 0.5rem; margin-top: 0.65rem; }
.sidebar-form .form-label { font-size: 0.82rem; }
.sidebar-form .form-label input {
  border: 1px solid rgba(164, 207, 241, 0.35);
  background: rgba(8, 27, 45, 0.78);
  color: var(--text); border-radius: 8px;
  padding: 0.45rem 0.6rem; font-size: 0.85rem; width: 100%;
}
.sidebar-form .form-label input:focus { outline: none; border-color: var(--accent); }

/* sidebar location search */
.sidebar-search {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: rgba(8, 27, 45, 0.7);
  color: var(--text); border-radius: 8px;
  padding: 0.4rem 0.65rem; font-size: 0.82rem;
  margin-bottom: 0.5rem;
}
.sidebar-search:focus { outline: none; border-color: var(--accent); }

/* location list */
.location-list { display: flex; flex-direction: column; gap: 0.25rem; }

.location-item {
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.location-item:hover {
  background: rgba(102, 225, 210, 0.06);
  border-color: rgba(102, 225, 210, 0.18);
}
.location-item.selected {
  background: rgba(102, 225, 210, 0.1);
  border-color: rgba(102, 225, 210, 0.38);
}
.location-item__name { font-size: 0.84rem; font-weight: 600; line-height: 1.3; }
.location-item__meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.12rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

.state-badge {
  display: inline-block;
  background: rgba(255, 207, 110, 0.12);
  color: var(--accent-2); border-radius: 5px;
  padding: 0.05rem 0.35rem; font-size: 0.68rem; font-weight: 600;
}

/* loader spinner */
.loader-sm {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(102, 225, 210, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn-icon {
  width: 26px; height: 26px;
  border: 1px solid rgba(102, 225, 210, 0.38);
  background: rgba(102, 225, 210, 0.07);
  color: var(--accent);
  border-radius: 8px; font-size: 1.1rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; flex-shrink: 0;
}
.btn-icon:hover { background: rgba(102, 225, 210, 0.18); }

.btn-primary {
  border: none; border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), #65e6b5);
  color: #012a26; font-weight: 700; font-size: 0.9rem;
  padding: 0.55rem 1.1rem; cursor: pointer; transition: filter 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.btn-secondary {
  border: 1px solid rgba(102, 225, 210, 0.42);
  background: transparent; color: var(--accent);
  border-radius: 10px; font-size: 0.86rem;
  padding: 0.45rem 0.9rem; cursor: pointer; transition: background 0.15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: rgba(102, 225, 210, 0.1); }

.btn-ghost {
  border: 1px solid rgba(164, 207, 241, 0.22);
  background: transparent; color: var(--muted);
  border-radius: 10px; font-size: 0.86rem;
  padding: 0.45rem 0.9rem; cursor: pointer; white-space: nowrap;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(164, 207, 241, 0.45); }

.btn-sm { padding: 0.32rem 0.7rem !important; font-size: 0.8rem !important; }

/* ── MAIN CONTENT ───────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; padding: 2rem 2.5rem;
  min-height: 100vh;
  position: relative; z-index: 1;
  max-width: calc(100vw - var(--sidebar-w));
  display: flex; flex-direction: column; gap: 1rem;
}

/* Empty state */
.empty-state {
  display: flex; align-items: center; justify-content: center;
  flex: 1; height: 60vh;
}
.empty-state-inner { text-align: center; }
.empty-state-icon { font-size: 2rem; color: var(--muted); margin-bottom: 0.5rem; }
.empty-state-text { color: var(--muted); font-size: 1rem; }

/* Content panel card */
.content-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 1.5rem 1.75rem;
  backdrop-filter: blur(8px);
}
.content-panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.content-panel-header h2 { font-size: 1.12rem; margin-bottom: 0.15rem; }
.content-panel-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.muted { color: var(--muted); font-size: 0.87rem; }

/* Info grid (read-only FHIR config) */
.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
@media (max-width: 900px) { .info-grid { grid-template-columns: repeat(2, 1fr); } }

.info-cell {
  background: rgba(8, 27, 45, 0.6);
  border: 1px solid rgba(122, 190, 242, 0.12);
  border-radius: 10px; padding: 0.65rem 0.85rem;
}
.info-label {
  display: block; font-size: 0.68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.3rem;
}
.info-value { font-size: 0.88rem; font-weight: 500; word-break: break-all; }

/* Edit form (inline, inset style) */
.edit-form-inset {
  margin-top: 1rem;
  padding: 1.1rem 1.2rem;
  background: rgba(8, 27, 45, 0.5);
  border: 1px solid rgba(122, 190, 242, 0.14);
  border-radius: 12px;
}

/* Inline form grid layouts */
.inline-form { display: grid; gap: 0.8rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
@media (max-width: 960px) { .form-grid-4, .form-grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .form-grid-4, .form-grid-3 { grid-template-columns: 1fr; } }

.form-label { display: grid; gap: 0.28rem; font-size: 0.88rem; color: var(--muted); }
.form-label input {
  border: 1px solid rgba(164, 207, 241, 0.35);
  background: rgba(8, 27, 45, 0.78);
  color: var(--text); border-radius: 10px;
  padding: 0.55rem 0.7rem; font-size: 0.9rem; width: 100%;
}
.form-label input:focus { outline: none; border-color: var(--accent); }
.form-label select {
  border: 1px solid rgba(164, 207, 241, 0.35);
  background: rgba(8, 27, 45, 0.78);
  color: var(--text); border-radius: 10px;
  padding: 0.55rem 0.7rem; font-size: 0.9rem; width: 100%;
}
.form-label select:focus { outline: none; border-color: var(--accent); }
.optional { font-size: 0.7rem; color: var(--muted); margin-left: 0.3rem; }

.form-actions-row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.form-msg { font-size: 0.84rem; color: var(--accent-2); min-height: 1.1rem; }
.form-msg.error { color: var(--error); }

/* Chips */
.chips { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid rgba(122, 190, 242, 0.28);
  background: rgba(122, 190, 242, 0.07);
  border-radius: 8px; padding: 0.22rem 0.6rem;
  font-size: 0.77rem; color: var(--muted);
  font-family: monospace; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 320px;
}
.chip-accent {
  border-color: rgba(102, 225, 210, 0.32);
  background: rgba(102, 225, 210, 0.07);
  color: var(--accent);
}

/* Credential step */
.step-heading { font-size: 0.92rem; font-weight: 600; margin-bottom: 0.3rem; }
.step-desc { margin-bottom: 0.9rem; }

.confirm-step {
  margin-top: 1.25rem; padding-top: 1.25rem;
  border-top: 1px solid rgba(122, 190, 242, 0.12);
}

/* Secret refs list */
.refs-list { display: grid; gap: 0.45rem; margin-top: 0.75rem; }
.ref-row {
  display: flex; align-items: baseline; gap: 0.75rem;
  background: rgba(8, 27, 45, 0.65);
  border: 1px solid rgba(122, 190, 242, 0.12);
  border-radius: 10px; padding: 0.6rem 0.85rem;
}
.ref-label {
  font-size: 0.72rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  min-width: 68px; flex-shrink: 0;
}
.ref-value { font-family: monospace; font-size: 0.78rem; color: var(--accent); word-break: break-all; }

.badge-ok {
  display: inline-flex; align-items: center;
  background: rgba(102, 225, 210, 0.09);
  border: 1px solid rgba(102, 225, 210, 0.28);
  border-radius: 8px; padding: 0.28rem 0.75rem;
  font-size: 0.8rem; color: var(--accent); margin-bottom: 0.6rem;
}

/* Existing binding card */
.existing-binding-card {
  background: rgba(255, 207, 110, 0.04);
  border: 1px solid rgba(255, 207, 110, 0.28);
  border-radius: 14px; padding: 1rem 1.2rem;
  margin-bottom: 1.25rem;
}
.existing-binding-header {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.existing-binding-title {
  font-size: 0.88rem; font-weight: 600; flex: 1;
}
.existing-binding-actions { display: flex; gap: 0.5rem; margin-left: auto; }

.badge-saved {
  background: rgba(255, 207, 110, 0.12);
  border: 1px solid rgba(255, 207, 110, 0.38);
  color: var(--accent-2); border-radius: 6px;
  padding: 0.18rem 0.55rem; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  flex-shrink: 0;
}

.btn-danger {
  border: 1px solid rgba(255, 100, 100, 0.38);
  background: transparent; color: var(--error);
  border-radius: 10px; font-size: 0.86rem;
  padding: 0.45rem 0.9rem; cursor: pointer; white-space: nowrap;
}
.btn-danger:hover { background: rgba(255, 100, 100, 0.1); }

.ref-truncate {
  font-family: monospace; font-size: 0.75rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%; display: block;
  cursor: pointer; transition: color 0.1s;
}
.ref-truncate:hover { color: var(--accent); }
.ref-truncate.expanded {
  white-space: pre-wrap; word-break: break-all;
  overflow: visible; text-overflow: unset;
}
.ref-cell-span2 { grid-column: span 2; }

/* ── MFA Email section ──────────────────────────────────── */
.mfa-imap-section {
  margin-top: 0.75rem;
  padding: 0.9rem 1rem;
  background: rgba(102, 225, 210, 0.06);
  border: 1px solid rgba(102, 225, 210, 0.18);
  border-radius: 8px;
}
.mfa-email-generated { margin-bottom: 0.5rem; }
.mfa-email-display {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
.mfa-email-code {
  font-size: 0.85rem; font-family: monospace;
  color: var(--accent);
  background: rgba(102,225,210,0.10);
  padding: 0.2rem 0.55rem; border-radius: 4px;
  letter-spacing: 0.02em;
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.step-subheading {
  font-size: 0.88rem; font-weight: 600;
  color: var(--accent);
  padding: 0.4rem 0;
}

.rpa-list-wrap {
  margin-top: 1.1rem;
  border: 1px solid rgba(122, 190, 242, 0.12);
  border-radius: 12px;
  overflow: auto;
}

.rpa-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.rpa-table th, .rpa-table td {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid rgba(122, 190, 242, 0.08);
  font-size: 0.82rem;
}

.rpa-table th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  background: rgba(8, 27, 45, 0.5);
}

.rpa-table td code {
  font-size: 0.78rem;
  color: var(--accent);
}

.rpa-actions-cell {
  min-width: 180px;
}

.rpa-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.rpa-empty {
  color: var(--muted);
  text-align: center;
}

.rpa-test-output {
  margin-top: 0.7rem;
  border: 1px solid rgba(122, 190, 242, 0.2);
  border-radius: 10px;
  background: rgba(8, 27, 45, 0.72);
  color: #d8f0ff;
  padding: 0.7rem 0.8rem;
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow: auto;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 8, 13, 0.72);
  backdrop-filter: blur(2px);
}

.app-modal-card {
  position: relative;
  width: min(520px, 96vw);
  border-radius: 14px;
  border: 1px solid rgba(102, 225, 210, 0.3);
  background: linear-gradient(160deg, rgba(10, 31, 23, 0.98), rgba(10, 21, 27, 0.98));
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.45);
  padding: 1rem 1rem 0.9rem;
}

.app-modal-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.app-modal-message {
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-line;
}

.app-modal-options {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.55rem;
}

.app-modal-option {
  text-align: left;
  border: 1px solid rgba(122, 190, 242, 0.35);
  background: rgba(9, 26, 41, 0.82);
  color: var(--text);
  border-radius: 10px;
  padding: 0.62rem 0.72rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.app-modal-option:hover,
.app-modal-option:focus-visible {
  outline: none;
  border-color: rgba(102, 225, 210, 0.62);
  background: rgba(26, 51, 73, 0.9);
}

.app-modal-option__label {
  font-size: 0.9rem;
  font-weight: 600;
  display: block;
}

.app-modal-option__desc {
  margin-top: 0.22rem;
  font-size: 0.77rem;
  color: var(--muted);
  display: block;
}

.app-modal-option-danger {
  border-color: rgba(255, 100, 100, 0.45);
}

.app-modal-option-danger:hover,
.app-modal-option-danger:focus-visible {
  border-color: rgba(255, 140, 140, 0.8);
  background: rgba(70, 20, 20, 0.6);
}

.app-modal-actions {
  margin-top: 0.95rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

.app-modal-form {
  margin-top: 0.2rem;
  display: grid;
  gap: 0.65rem;
}

.app-modal-field {
  display: grid;
  gap: 0.28rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.app-modal-field-label {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
}

.app-modal-field input,
.app-modal-field textarea {
  border: 1px solid rgba(164, 207, 241, 0.35);
  background: rgba(8, 27, 45, 0.78);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  width: 100%;
}

.app-modal-field input:focus,
.app-modal-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.app-modal-field textarea {
  resize: vertical;
  min-height: 170px;
  font-family: "Consolas", "Courier New", monospace;
  line-height: 1.4;
  white-space: pre;
}

.app-modal-field-help {
  color: var(--muted);
  font-size: 0.74rem;
}

.app-modal-form-error {
  margin-top: 0.1rem;
  color: var(--error);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .app-modal-card {
    width: 100%;
    padding: 0.9rem;
  }
}
