@keyframes morph-blob {
  0%   { border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%; transform: translate(-50%, -50%) rotate(0deg)  scale(1);   }
  100% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; transform: translate(-50%, -50%) rotate(45deg) scale(1.1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #e2e8f0;
  margin: 0;
  padding: 2rem 1rem;
  min-height: 100vh;
  background-color: #03050a;
  position: relative;
  overflow-x: hidden;
}

#starfield {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: -2;
  pointer-events: none;
}

#healthBlob {
  position: fixed;
  top: 50%; left: 50%;
  width: min(60vw, 700px);
  height: min(60vw, 700px);
  background: #3b82f6;
  filter: blur(120px);
  opacity: 0.25;
  z-index: -1;
  pointer-events: none;
  animation: morph-blob 20s ease-in-out infinite alternate;
  transition: background 1.5s ease-in-out;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.container {
  max-width: 850px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

h1, h3, h4 {
  color: #93c5fd;
  margin-top: 0;
  text-shadow: 0 0 15px rgba(147, 197, 253, 0.4);
  font-weight: 600;
}

.box {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.15) 0%, rgba(15, 23, 42, 0.4) 100%);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  padding: 1.5rem;
  border-radius: 16px;
  margin-bottom: 1.5rem;
  box-shadow:
    0 15px 35px rgba(0, 0, 0, 0.5),
    inset 0 0 40px rgba(0, 0, 0, 0.6),
    inset 0 0 10px rgba(147, 197, 253, 0.1);
  transition: border-color 0.3s;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.flex-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.flex-row label {
  width: 140px;
  font-weight: bold;
  font-size: 0.9em;
  transition: color 0.3s;
}

/* ── Drop Zone ─────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 1px dashed rgba(147, 197, 253, 0.4);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1rem;
  background: rgba(0, 0, 0, 0.3);
  transition: background 0.3s, border-color 0.3s;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.5);
}

.drop-zone.dragover {
  background: rgba(59, 130, 246, 0.1);
  border-color: #60a5fa;
}

.file-input-label {
  display: inline-block;
  padding: 0.4rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background 0.2s;
}

.file-input-label:hover { background: rgba(255, 255, 255, 0.1); }

input[type="file"] { display: none; }

/* ── Form Controls ─────────────────────────────────────────────────────────── */
textarea,
input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.6rem;
  font-family: monospace;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  border-radius: 6px;
  box-sizing: border-box;
  transition: border-color 0.3s, background 0.3s;
  outline: none;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

textarea:focus,
input:focus,
select:focus {
  border-color: #38bdf8;
  background: rgba(0, 0, 0, 0.7);
  outline: 2px solid rgba(56, 189, 248, 0.3);
  outline-offset: 0;
}

textarea {
  height: 140px;
  resize: vertical;
  margin-bottom: 0.5rem;
}

/* ── Validation States ─────────────────────────────────────────────────────── */
.state-valid   { border-color: #10b981 !important; color: #10b981; }
.state-invalid { border-color: #ef4444 !important; color: #ef4444; }
.state-warning { border-color: #eab308 !important; color: #eab308; background: rgba(234, 179, 8, 0.05); }
.state-inactive {
  border-color: #334155 !important;
  color: #64748b;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
button {
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

button:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 3px;
}

button:hover:not(:disabled) {
  filter: brightness(1.1);
}

button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.3);
}

button:disabled {
  background: rgba(51, 65, 85, 0.5);
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-orange { background: linear-gradient(135deg, #ea580c, #c2410c) !important; box-shadow: 0 4px 15px rgba(234, 88, 12, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.2) !important; }
.btn-green  { background: linear-gradient(135deg, #059669, #047857) !important; box-shadow: 0 4px 15px rgba(5, 150, 105, 0.3),  inset 0 1px 1px rgba(255, 255, 255, 0.2) !important; }
.btn-gray   { background: linear-gradient(135deg, #475569, #334155);             box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1); }

/* ── Details / Summary ─────────────────────────────────────────────────────── */
details {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.5rem;
  border-radius: 6px;
  margin-bottom: 0.8rem;
  border-left: 3px solid #3b82f6;
}

summary {
  font-weight: bold;
  cursor: pointer;
  font-size: 0.95em;
  color: #cbd5e1;
  list-style: revert; /* keep browser disclosure triangle */
}

summary:focus-visible {
  outline: 2px solid #60a5fa;
  border-radius: 3px;
}

details p {
  font-size: 0.85em;
  color: #94a3b8;
  margin: 0.5rem 0 0;
  line-height: 1.4;
}

/* ── Keys & Checkbox ───────────────────────────────────────────────────────── */
.key-output { font-weight: bold; }

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.checkbox-wrapper input {
  width: auto;
  transform: scale(1.2);
  accent-color: #3b82f6;
  cursor: pointer;
}

/* ── QR Code ───────────────────────────────────────────────────────────────── */
.qr-wrapper {
  display: none;
  flex-direction: column;
  align-items: center;
  margin: 2rem 0;
  min-height: 280px;
  justify-content: center;
}

.qr-display-container {
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 16px;
  border: 1px solid rgba(0, 110, 183, 0.3);
}

.qr-loader {
  border: 4px solid rgba(0, 110, 183, 0.2);
  border-top-color: #006eb7;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  position: absolute;
}

.qr-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.qr-image {
  width: 260px;
  height: 260px;
  border-radius: 8px;
  display: none;
  cursor: zoom-in;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.qr-image:hover {
  transform: scale(1.03);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
#qrModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  cursor: zoom-out;
}

#qrModal.active {
  opacity: 1;
  pointer-events: auto;
}

#qrModal img {
  width: 50vh;
  height: 50vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  transform: scale(0.8);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: default;
}

#qrModal.active img {
  transform: scale(1);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (orientation: portrait) {
  #qrModal img {
    width: 90vw;
    height: 90vw;
  }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
  .flex-row { flex-wrap: wrap; }
  .flex-row label { width: 100%; }
}
