/* ==========================================================================
   ABUGIDA SECURITY — Component Library
   ========================================================================== */

/* ---- Card base ---- */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
}

/* ---- Challenge card ---- */
.chal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
}
.chal-card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(194,32,41,0.06), transparent 60%);
  opacity: 0; transition: opacity var(--transition-base);
  pointer-events: none;
}
.chal-card::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--brand-gradient);
  transform: scaleX(0); transform-origin: left;
  transition: transform var(--transition-base);
}
.chal-card:hover { border-color: var(--border-strong); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.chal-card:hover::before { opacity: 1; }
.chal-card:hover::after { transform: scaleX(1); }
.chal-card.solved { border-color: rgba(51,177,122,0.35); background: linear-gradient(180deg, rgba(51,177,122,0.05), var(--bg-panel) 40%); }
.chal-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.chal-card-cat { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; color: var(--text-tertiary); text-transform: uppercase; }
.chal-card h3 { font-size: 16.5px; margin: 2px 0 0; line-height: 1.3; }
.chal-card .desc-snip { font-size: 13px; color: var(--text-tertiary); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chal-card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border-subtle); }
.chal-card-points { font-family: var(--font-mono); font-weight: 800; color: var(--gold-400); font-size: 15px; text-shadow: 0 0 14px rgba(214,171,52,0.35); }
.chal-card-solves { font-size: 12px; color: var(--text-tertiary); font-family: var(--font-mono); }
.chal-card-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.solved-check {
  position: absolute; top: 14px; right: 14px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--success-bg); color: var(--success);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 900;
}

/* ---- Difficulty pill ---- */
.pill { position: relative; }
.diff-Easy, .diff-Medium, .diff-Hard, .diff-Insane { border: 1px solid transparent; transition: box-shadow var(--transition-fast); }
.diff-Easy   { background: rgba(51,177,122,0.14); color: var(--diff-easy); border-color: rgba(51,177,122,0.3); }
.diff-Medium { background: rgba(214,171,52,0.14); color: var(--diff-medium); border-color: rgba(214,171,52,0.3); }
.diff-Hard   { background: rgba(226,67,76,0.14); color: var(--diff-hard); border-color: rgba(226,67,76,0.3); }
.diff-Insane { background: rgba(155,63,224,0.16); color: var(--diff-insane); border-color: rgba(155,63,224,0.32); }
.chal-card:hover .diff-Easy   { box-shadow: 0 0 12px -2px rgba(51,177,122,0.5); }
.chal-card:hover .diff-Medium { box-shadow: 0 0 12px -2px rgba(214,171,52,0.5); }
.chal-card:hover .diff-Hard   { box-shadow: 0 0 12px -2px rgba(226,67,76,0.5); }
.chal-card:hover .diff-Insane { box-shadow: 0 0 12px -2px rgba(155,63,224,0.5); }

/* ---- Category badge ---- */
.cat-badge { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-default); }

/* ---- Category page card ---- */
.category-card {
  padding: 28px 24px; border-radius: var(--radius-lg);
  background: linear-gradient(165deg, var(--bg-panel), var(--bg-panel-alt));
  border: 1px solid var(--border-subtle);
  position: relative; overflow: hidden;
  transition: transform var(--transition-base), border-color var(--transition-base);
}
.category-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--brand-gradient); transform: scaleX(0); transform-origin: left;
  transition: transform var(--transition-base);
}
.category-card:hover { transform: translateY(-4px); border-color: var(--border-strong); box-shadow: var(--shadow-glow-red-lg); }
.category-card:hover::before { transform: scaleX(1); }
.category-card .cat-icon {
  width: 46px; height: 46px; border-radius: var(--radius-md);
  background: linear-gradient(150deg, var(--red-700), var(--red-900));
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px; box-shadow: var(--shadow-glow-red);
}
.category-card h3 { font-size: 20px; margin: 0 0 4px; }
.category-card .cat-meta { font-size: 13px; color: var(--text-tertiary); margin-bottom: 18px; font-family: var(--font-mono); }

/* ---- Stat card ---- */
.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card .stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-family: var(--font-mono); margin-bottom: 8px; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--text-primary); }
.stat-card .stat-value.gold { color: var(--gold-400); }
.stat-card .stat-value.red { color: var(--red-400); }
.stat-card .stat-sub { font-size: 12.5px; color: var(--text-tertiary); margin-top: 6px; }
.stat-card .stat-icon { position: absolute; top: 16px; right: 16px; opacity: 0.35; }

/* ---- Progress bar ---- */
.progress-track { height: 8px; background: var(--bg-elevated); border-radius: var(--radius-full); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--red-600), var(--gold-500)); border-radius: var(--radius-full); transition: width 600ms cubic-bezier(.4,0,.2,1); }

/* ---- Badge chip (achievements) ---- */
.badge-chip {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--bg-panel-alt); border: 1px solid var(--border-subtle);
  transition: border-color var(--transition-base), transform var(--transition-base);
}
.badge-chip:not(.locked):hover { border-color: rgba(214,171,52,0.4); transform: translateY(-2px); }
.badge-chip .badge-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(150deg, var(--gold-600), var(--gold-700));
  display: flex; align-items: center; justify-content: center; color: #1a1305; flex-shrink: 0;
  box-shadow: var(--shadow-glow-gold);
}
.badge-chip.locked { opacity: 0.4; }
.badge-chip.locked .badge-icon { background: var(--bg-elevated); color: var(--text-disabled); box-shadow: none; }
.badge-chip .badge-name { font-weight: 700; font-size: 13.5px; }
.badge-chip .badge-desc { font-size: 12px; color: var(--text-tertiary); }

/* ---- Table ---- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-tertiary); font-family: var(--font-mono); font-weight: 600;
  padding: 12px 16px; border-bottom: 1px solid var(--border-default);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); font-size: 14px; }
.data-table tbody tr:nth-child(even) td { background: rgba(255,255,255,0.012); }
.data-table tr:hover td { background: var(--bg-panel-alt); }
.data-table tr.current-user td { background: rgba(214,171,52,0.08); }
.data-table tr.current-user { position: relative; }
.data-table tr.current-user td:first-child { box-shadow: inset 2px 0 0 var(--gold-500); }

/* ---- Leaderboard rank ---- */
.rank-badge { font-family: var(--font-display); font-weight: 800; font-size: 14px; color: var(--text-tertiary); }
.rank-badge.top1 { color: var(--gold-400); font-size: 16px; }
.rank-badge.top2 { color: #c9c9d1; font-size: 15px; }
.rank-badge.top3 { color: #c9803f; font-size: 15px; }

/* ---- Podium ---- */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 16px; margin-bottom: 48px; }
.podium-slot { display: flex; flex-direction: column; align-items: center; width: 180px; }
.podium-slot .p-avatar { width: 56px; height: 56px; border-radius: 50%; margin-bottom: 10px; border: 2px solid var(--border-default); }
.podium-slot .p-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.podium-slot .p-points { font-family: var(--font-mono); color: var(--gold-400); font-size: 13px; margin-bottom: 12px; }
.podium-bar {
  width: 100%; border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 14px;
  font-family: var(--font-display); font-weight: 900; font-size: 26px;
  border: 1px solid var(--border-subtle); border-bottom: none;
}
.podium-slot.rank-1 { order: 2; }
.podium-slot.rank-2 { order: 1; }
.podium-slot.rank-3 { order: 3; }
.podium-slot.rank-1 .podium-bar { height: 140px; background: linear-gradient(180deg, rgba(214,171,52,0.22), rgba(214,171,52,0.05)); color: var(--gold-400); box-shadow: var(--shadow-glow-gold-lg); animation: podiumPulse 2.4s ease-in-out infinite; }
@keyframes podiumPulse { 0%,100% { box-shadow: var(--shadow-glow-gold-lg); } 50% { box-shadow: 0 0 0 1px rgba(214,171,52,0.35), 0 0 52px -8px var(--gold-glow); } }
.podium-slot.rank-2 .podium-bar { height: 108px; background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02)); color: #d5d6da; }
.podium-slot.rank-3 .podium-bar { height: 84px; background: linear-gradient(180deg, rgba(201,128,63,0.18), rgba(201,128,63,0.04)); color: #c9803f; }
.podium-slot.rank-1 .p-avatar { width: 68px; height: 68px; border-color: var(--gold-500); }

/* ---- Terminal ---- */
.terminal {
  background: #0a0b0d;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.terminal-bar { display: flex; align-items: center; gap: 7px; padding: 10px 14px; background: var(--bg-panel-alt); border-bottom: 1px solid var(--border-subtle); }
.terminal-dot { width: 10px; height: 10px; border-radius: 50%; }
.terminal-dot.red { background: #e2434c; } .terminal-dot.yellow { background: #d6ab34; } .terminal-dot.green { background: #33b17a; }
.terminal-title { margin-left: 8px; color: var(--text-tertiary); font-size: 12px; }
.terminal-body { padding: 16px; color: #c9d1d9; line-height: 1.7; white-space: pre-wrap; }
.terminal-body .t-prompt { color: var(--gold-500); }
.terminal-body .t-ok { color: var(--success); }
.terminal-body .t-path { color: #6ba3e0; }
.terminal-body .t-comment { color: var(--text-disabled); }

/* ---- Flag submission box ---- */
.flag-box { display: flex; gap: 10px; }
.flag-box input {
  flex: 1; font-family: var(--font-mono); letter-spacing: 0.02em;
  background: var(--bg-void); border: 1px solid var(--border-default);
  padding: 13px 15px; border-radius: var(--radius-sm); color: var(--text-primary); font-size: 14px;
}
.flag-box input:focus { outline: none; border-color: var(--red-600); box-shadow: 0 0 0 3px rgba(194,32,41,0.15); }
.flag-feedback { margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-sm); font-size: 13.5px; display: none; }
.flag-feedback.show { display: block; animation: feedbackIn 220ms ease; }
.flag-feedback.correct { background: var(--success-bg); border: 1px solid rgba(51,177,122,0.3); color: var(--success); }
.flag-feedback.incorrect { background: var(--danger-bg); border: 1px solid rgba(226,67,76,0.3); color: var(--danger); }
.flag-feedback .ff-title { font-family: var(--font-mono); font-weight: 800; font-size: 14px; margin-bottom: 4px; letter-spacing: 0.02em; }
@keyframes feedbackIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Sidebar info block ---- */
.info-sidebar { background: var(--bg-panel); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 22px; position: sticky; top: calc(var(--nav-height) + 20px); }
.info-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border-subtle); }
.info-row:last-child { border-bottom: none; }
.info-row .il { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); font-family: var(--font-mono); }
.info-row .iv { font-weight: 700; font-size: 14px; }

/* ---- Instance panel ---- */
.instance-panel { border: 1px dashed var(--border-default); border-radius: var(--radius-md); padding: 18px; margin-top: 16px; background: var(--bg-panel-alt); }
.instance-status { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.offline { background: var(--text-disabled); }
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulse 1.8s infinite; }
.status-dot.starting { background: var(--gold-500); animation: pulse 0.9s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.instance-target { font-family: var(--font-mono); background: var(--bg-void); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--gold-400); margin-bottom: 12px; word-break: break-all; }
.instance-timer { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-tertiary); }

/* ---- Toast ---- */
#toast-stack { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-md);
  padding: 14px 16px; box-shadow: var(--shadow-md); font-size: 13.5px;
  display: flex; align-items: flex-start; gap: 10px;
  animation: toastIn 220ms ease;
}
.toast.success { border-left: 3px solid var(--success); box-shadow: var(--shadow-md), 0 0 20px -8px rgba(51,177,122,0.4); }
.toast.error { border-left: 3px solid var(--danger); box-shadow: var(--shadow-md), 0 0 20px -8px rgba(226,67,76,0.4); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.toast.hide { animation: toastOut 200ms ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,5,6,0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 900; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity var(--transition-base);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-box { background: var(--bg-panel); border: 1px solid var(--border-default); border-radius: var(--radius-lg); max-width: 520px; width: 100%; padding: 28px; box-shadow: var(--shadow-md); transform: translateY(10px) scale(0.98); transition: transform var(--transition-base); max-height: 86vh; overflow-y: auto; }
.modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
.modal-close { position: absolute; top: 18px; right: 18px; cursor: pointer; color: var(--text-tertiary); background: none; border: none; font-size: 20px; }

/* ---- Skeleton loader ---- */
.skeleton { background: linear-gradient(90deg, var(--bg-panel-alt) 25%, var(--bg-elevated) 50%, var(--bg-panel-alt) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel-card { height: 168px; border-radius: var(--radius-md); }

/* ---- Empty / error state ---- */
.empty-state, .error-state { text-align: center; padding: 64px 24px; color: var(--text-tertiary); }
.empty-state .es-icon, .error-state .es-icon { margin-bottom: 16px; opacity: 0.5; }
.empty-state h3, .error-state h3 { color: var(--text-secondary); font-size: 17px; }

/* ---- Filter bar ---- */
.filter-bar { background: var(--bg-panel); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 18px 20px; margin-bottom: 28px; }
.filter-search { position: relative; margin-bottom: 14px; }
.filter-search input { width: 100%; background: var(--bg-void); border: 1px solid var(--border-default); border-radius: var(--radius-sm); padding: 11px 14px 11px 38px; color: var(--text-primary); font-size: 14px; }
.filter-search input:focus { outline: none; border-color: var(--red-600); }
.filter-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: var(--radius-full); font-size: 12.5px; font-weight: 600;
  background: var(--bg-panel-alt); border: 1px solid var(--border-default); color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition-fast); font-family: var(--font-mono);
}
.chip:hover { border-color: var(--text-tertiary); }
.chip.active { background: linear-gradient(160deg, var(--red-600), var(--red-800)); border-color: var(--red-500); color: #fff; box-shadow: 0 3px 12px -4px var(--red-glow); }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; background: var(--bg-panel-alt); padding: 4px; border-radius: var(--radius-sm); width: fit-content; }
.tab-btn { padding: 8px 16px; font-size: 13px; font-weight: 600; border-radius: 5px; color: var(--text-tertiary); cursor: pointer; background: none; border: none; font-family: var(--font-body); transition: color var(--transition-fast), background var(--transition-fast); }
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { background: var(--bg-elevated); color: var(--gold-400); box-shadow: 0 0 0 1px var(--border-strong); }

/* ---- Auth card ---- */
.auth-wrap { min-height: calc(100vh - var(--nav-height)); display: flex; align-items: center; justify-content: center; padding: 40px 20px; position: relative; }
.auth-card { width: 100%; max-width: 420px; background: var(--bg-panel); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 36px; box-shadow: var(--shadow-md); position: relative; overflow: hidden; }
.auth-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--brand-gradient); }

/* ---- Admin table controls ---- */
.admin-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.status-tag { padding: 3px 9px; border-radius: var(--radius-full); font-size: 11px; font-weight: 700; text-transform: uppercase; font-family: var(--font-mono); }
.status-tag.enabled { background: var(--success-bg); color: var(--success); }
.status-tag.disabled { background: var(--danger-bg); color: var(--danger); }

@media (max-width: 900px) {
  .info-sidebar { position: static; }
  .podium { gap: 8px; }
  .podium-slot { width: 110px; }
}
@media (max-width: 640px) {
  .flag-box { flex-direction: column; }
  .grid-auto { grid-template-columns: 1fr; }
  #toast-stack { left: 16px; right: 16px; max-width: none; }
}
