/* ─────────────────────────────────────────────────────────────────────────────
   Data Portal – custom stylesheet
   Design tokens
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #0f1117;
  --sidebar-width: 260px;
  --sidebar-text: #c9d1db;
  --sidebar-text-muted: #6b7280;
  --sidebar-active-bg: rgba(99, 102, 241, 0.15);
  --sidebar-active-color: #818cf8;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
  --sidebar-brand-color: #ffffff;
  --sidebar-section-label: #4b5563;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --bg-page: #f4f5f7;
  --bg-card: #ffffff;
  --border-color: #e5e7eb;
  --text-primary: #111827;
  --text-muted: #6b7280;

  --radius-card: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 8px 24px rgba(0, 0, 0, 0.10);
}

/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
}

body.has-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  width: var(--sidebar-width);
  min-height: 100vh;
  padding: 0 0 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--sidebar-brand-color);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 0.75rem;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.topbar-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-nav { padding: 0 0.75rem; }

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-section-label);
  padding: 0.5rem 0.75rem 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link i { font-size: 1rem; width: 1.1rem; text-align: center; }

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
}

.sidebar-footer {
  padding: 1rem 1.25rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 1rem;
}

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }
.sidebar-username { font-size: 0.85rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-role { font-size: 0.72rem; color: var(--sidebar-text-muted); }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.sidebar-logout:hover { color: var(--danger); }

/* ── Topbar (mobile) ────────────────────────────────────────────────────────── */
.topbar {
  display: none;
  background: var(--sidebar-bg);
  color: #fff;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.btn-icon { background: transparent; border: none; color: #fff; padding: 0.25rem; }
.btn-ghost { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-ghost:hover { background: var(--border-color); }

/* ── Main content ────────────────────────────────────────────────────────────── */
.main-content {
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.main-content.full-width {
  grid-column: 1 / -1;
  height: 100vh;
}

.content-wrapper {
  padding: 2rem 2.5rem;
  width: 100%;
  flex: 1;
}

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.9rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  background: var(--bg-card);
}

.form-card, .data-table-card, .info-card { border-radius: var(--radius-card); }

.info-card { background: #f8f9ff; border-color: #e0e7ff; }

.code-hint {
  background: #f1f3f5;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-primary);
  word-break: break-all;
}

/* ── Dashboard cards (list view) ─────────────────────────────────────────────── */
.dashboard-card {
  border-radius: var(--radius-card);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  background: var(--bg-card);
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
  color: var(--text-primary);
}

.dashboard-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
  border-color: var(--primary);
}

.dashboard-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.dashboard-card-footer { border-top: 1px solid var(--border-color); padding-top: 0.75rem; }

/* ── Iframe layout ───────────────────────────────────────────────────────────── */
.iframe-page { height: calc(100vh - 0px); }

.iframe-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  min-height: 52px;
  flex-shrink: 0;
}

.iframe-wrapper { position: relative; }

.iframe-wrapper iframe {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 52px);
  border: none;
  display: block;
}

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table { font-size: 0.9rem; }
.table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-color);
  padding: 0.75rem 1rem;
}
.table tbody td { padding: 0.85rem 1rem; vertical-align: middle; }
.table-hover tbody tr:hover { background: #f9fafb; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  font-weight: 600;
  font-size: 0.72rem;
  border-radius: 6px;
  padding: 0.3em 0.65em;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-secondary { background: #f3f4f6; color: #4b5563; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-login {
  height: 46px;
  font-size: 1rem;
  font-weight: 600;
}

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1117 0%, #1e1b4b 100%);
  padding: 2rem;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  overflow: hidden;
  margin: 0 auto 1rem;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.25);
}

.login-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.login-title { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.75rem; }

.login-card .form-label { text-align: left; display: block; }
.login-card .form-control { text-align: left; }

.login-footer { color: rgba(255,255,255,0.3); font-size: 0.8rem; margin-top: 2rem; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #9ca3af;
  margin: 0 auto 1.25rem;
}

/* ── Danger / warning icons ──────────────────────────────────────────────────── */
.danger-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: #fee2e2; color: var(--danger);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
  flex-shrink: 0;
}
.warning-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: #fef3c7; color: var(--warning);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
  flex-shrink: 0;
}
.dashboard-summary { background: #f9fafb; border: 1px solid var(--border-color); }

/* ── Access toggle ───────────────────────────────────────────────────────────── */
.access-toggle {
  cursor: pointer;
  border: 1px solid var(--border-color);
  transition: border-color 0.15s, background 0.15s;
}
.access-toggle:hover { border-color: var(--primary); background: #f8f9ff; }
.access-toggle.granted { background: #f0fdf4; border-color: #a7f3d0; }

/* ── Messages ────────────────────────────────────────────────────────────────── */
.messages-container { margin-bottom: 1.5rem; }

/* ── Dev embed debug panel ───────────────────────────────────────────────────── */
.embed-debug {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  z-index: 1000;
  background: #1e1b4b;
  border-top: 2px solid #f59e0b;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.embed-debug summary {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 600;
  color: #fbbf24;
  list-style: none;
  user-select: none;
}
.embed-debug summary::-webkit-details-marker { display: none; }
.embed-debug summary:hover { background: rgba(255,255,255,0.05); }

.embed-debug-body {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.embed-debug-url {
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  word-break: break-all;
  color: #a5b4fc;
  display: block;
  max-height: 80px;
  overflow-y: auto;
}

/* ── 2FA — setup wizard step indicator ──────────────────────────────────────── */
.setup-steps {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.setup-steps .step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--dp-muted);
  flex: 0 0 auto;
}

.setup-steps .step.active { color: var(--dp-primary); }
.setup-steps .step.done   { color: var(--dp-success); }

.setup-steps .step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--dp-border);
  color: var(--dp-muted);
}
.setup-steps .step.active .step-dot {
  background: var(--dp-primary);
  color: #fff;
}
.setup-steps .step.done .step-dot {
  background: var(--dp-success);
  color: #fff;
}

.setup-steps .step-line {
  flex: 1;
  height: 2px;
  background: var(--dp-border);
  margin-bottom: 1.4rem;
}

/* QR code displayed during setup */
.qr-code-img {
  max-width: 200px;
  border-radius: 8px;
  border: 1px solid var(--dp-border);
  padding: 8px;
  background: #fff;
}

/* Backup token grid */
.backup-tokens {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem;
}

.backup-token {
  display: block;
  background: var(--dp-bg-alt);
  border: 1px solid var(--dp-border);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  text-align: center;
  letter-spacing: 0.05em;
  color: var(--dp-text);
}

/* 2FA login OTP step icon */
.otp-icon-wrap {
  text-align: center;
  font-size: 3rem;
  color: var(--dp-primary);
  opacity: 0.8;
}

/* Status badges in profile page */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-active  { background: rgba(16,185,129,.15); color: #059669; }
.status-warning { background: rgba(245,158,11,.15);  color: #b45309; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  body.has-sidebar {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
    height: 100vh;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    transition: left 0.25s ease;
    z-index: 500;
  }

  .sidebar.open { left: 0; }

  .topbar { display: flex !important; grid-row: 1; height: 56px; }

  .main-content { grid-row: 2; height: calc(100vh - 56px); }

  .content-wrapper { padding: 1.25rem; }
}

@media (max-width: 576px) {
  .page-header { flex-direction: column; }
  .content-wrapper { padding: 1rem; }
}
