/* =============================================================================
   portal/public/style.css  —  Portal UI styles
   Clean, functional, no external dependencies.
   ============================================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --border:    #2d3148;
  --text:      #e2e8f0;
  --muted:     #6b7280;
  --accent:    #6366f1;
  --accent-h:  #818cf8;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #eab308;
  --radius:    8px;
  --font:      'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Login page ─────────────────────────────────────────────────────────── */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-card p.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
#app-page { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-title span { color: var(--accent); }

.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Sections ───────────────────────────────────────────────────────────── */
.section { margin-bottom: 2.5rem; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }

.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled)  { opacity: 0.85; }

.btn-ghost   { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)  { color: var(--text); border-color: var(--muted); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ── Role badge ─────────────────────────────────────────────────────────── */
.role-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}
.role-admin    { background: rgba(99,102,241,0.2); color: var(--accent-h); border: 1px solid rgba(99,102,241,0.4); }
.role-operator { background: rgba(107,114,128,0.15); color: var(--muted);  border: 1px solid var(--border); }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 0.75rem;
}

.card-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.card-name {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1 1 160px;
}

.card-ip {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--accent-h);
  flex: 0 0 auto;
}

.card-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.card-meta {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* ── Status badge ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  flex: 0 0 auto;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-connected    { color: var(--green); background: rgba(34,197,94,0.12); }
.badge-disconnected { color: var(--muted); background: rgba(107,114,128,0.15); }
.badge-revoked      { color: var(--red);   background: rgba(239,68,68,0.12); }

/* ── Instruction panel (collapsible) ────────────────────────────────────── */
.instruct-panel {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: none;
}

.instruct-panel.open { display: block; }

/* ── Instructions history table ─────────────────────────────────────────── */
.instr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 1rem;
}

.instr-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.instr-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: top;
  max-width: 320px;
  word-break: break-all;
}

.status-queued      { color: var(--yellow); }
.status-acknowledged{ color: var(--accent-h); }
.status-completed   { color: var(--green); }
.status-failed      { color: var(--red); }

/* ── Enroll modal / inline form ─────────────────────────────────────────── */
.enroll-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: none;
}

.enroll-form.open { display: block; }

/* ── Toast notifications ────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  max-width: 320px;
  animation: slideIn 0.2s ease;
}

.toast.toast-error   { border-color: var(--red);   color: #fca5a5; }
.toast.toast-success { border-color: var(--green);  color: #86efac; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Misc ───────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 0.9rem;
}

.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.error-text { color: var(--red); font-size: 0.82rem; margin-top: 0.4rem; }

.mono { font-family: monospace; }

@media (max-width: 600px) {
  .topbar { padding: 0.75rem 1rem; }
  .main-content { padding: 1.25rem 1rem; }
  .card-row { flex-direction: column; align-items: flex-start; }
  .card-actions { margin-left: 0; }
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}

.modal-close-btn:hover { color: var(--text); }

.modal-body {
  padding: 1rem 1.5rem 1.5rem;
}

.modal-body p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.key-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-family: monospace;
  font-size: 0.82rem;
  word-break: break-all;
  margin-bottom: 1rem;
  color: var(--accent-h);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.qr-container {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem;
}

.qr-container img,
.qr-container svg {
  max-width: 100%;
  width: 240px;
  height: auto;
}

.qr-spinner {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.qr-fallback {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-family: monospace;
  font-size: 0.78rem;
  white-space: pre;
  overflow-x: auto;
  color: var(--text);
}

.warning-box {
  background: rgba(234,179,8,0.1);
  border: 1px solid rgba(234,179,8,0.3);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  color: #fde047;
  margin-bottom: 0.75rem;
}
