@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&display=swap');

:root {
  /* ===== LIGHT MODE PALETTE ===== */
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --border: #e5e5ea;
  --text: #0b0b0f;
  --text-muted: #4a4a55;
  --input-bg: #ffffff;
  --btn-sec-border: #d9d9d9;
  --btn-sec-color: #000000;
  --btn-sec-hover-bg: #d9d9d9;
  --btn-sec-hover-color: #ffffff;
  --accent: #6d6df6;
  --accent-hover: #5a5af0;
  --danger: #f65d6d;
  --success: #16a34a;
}

[data-theme="dark"], body.dark-mode {
  /* ===== DARK MODE PALETTE ===== */
  --bg: #0e0e11;
  --bg-card: #18181c;
  --border: #2c2c34;
  --text: #f0f0f5;
  --text-muted: #9c9ca8;
  --input-bg: #222228;
  --btn-sec-border: #3e3e48;
  --btn-sec-color: #f0f0f5;
  --btn-sec-hover-bg: #3e3e48;
  --btn-sec-hover-color: #ffffff;
  --accent: #6d6df6;
  --accent-hover: #5a5af0;
  --danger: #f65d6d;
  --success: #22c55e;
}

* { 
  box-sizing: border-box; 
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: lexend, BlinkMacSystemFont, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  width: 100%;
  max-width: 440px;
  margin-top: 30px;
  margin-bottom: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.card.wide { 
  max-width: 960px; 
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.brand img { 
  height: 72px; 
  width: auto; 
  max-width: 100%;
  object-fit: contain;
}
.brand span { 
  font-size: 18px; 
  font-weight: 700; 
  letter-spacing: 0.5px; 
}

label { 
  display: block; 
  font-size: 13px; 
  font-weight: 600; 
  margin: 16px 0 6px; 
}

input, select {
  width: 100%;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, select:focus { 
  outline: none; 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px rgba(109, 109, 246, 0.15);
}

.hint { 
  font-size: 12px; 
  color: var(--text-muted); 
  margin-top: 5px; 
  line-height: 1.4;
}

/* ===== GLOBAL TRANSITIONS ===== */
body, .card, input, select, button, .btn, table, th, td, nav, .badge, .theme-toggle-btn {
  transition: background-color 0.3s ease,
              color 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
}

/* ===== THEME TOGGLE BUTTON ===== */
.theme-toggle-btn {
  position: relative;
  background: transparent !important;
  border: 1.5px solid var(--border) !important;
  border-radius: 50% !important;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text) !important;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  margin-right: 4px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.theme-toggle-btn:hover {
  background: var(--border) !important;
  transform: scale(1.08);
}
.theme-toggle-btn:active {
  transform: scale(0.92);
}

.theme-toggle-btn.clicked {
  animation: themeBtnPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes themeBtnPop {
  0% { transform: scale(1); }
  40% { transform: scale(0.82) rotate(-15deg); }
  75% { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.theme-toggle-btn svg {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -10px;
  margin-left: -10px;
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light mode: Moon visible */
.moon-icon {
  opacity: 1 !important;
  visibility: visible !important;
  transform: rotate(0deg) scale(1) !important;
  stroke: var(--text) !important;
}
.sun-icon {
  opacity: 0 !important;
  visibility: hidden !important;
  transform: rotate(90deg) scale(0.2) !important;
  stroke: #facc15 !important;
}

/* Dark mode: Sun visible */
[data-theme="dark"] .moon-icon,
body.dark-mode .moon-icon {
  opacity: 0 !important;
  visibility: hidden !important;
  transform: rotate(-90deg) scale(0.2) !important;
}

[data-theme="dark"] .sun-icon,
body.dark-mode .sun-icon {
  opacity: 1 !important;
  visibility: visible !important;
  transform: rotate(0deg) scale(1) !important;
  stroke: #facc15 !important;
}

/* ===== BUTTONS ===== */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  user-select: none;
}
button:hover, .btn:hover { 
  background: var(--accent-hover); 
  color: #fff; 
}
button:active, .btn:active {
  transform: scale(0.98);
}

/* Secondary buttons */
button.secondary, .btn.secondary {
  background: transparent !important;
  border: 1.5px solid var(--btn-sec-border) !important;
  color: var(--btn-sec-color) !important;
}
button.secondary:hover, .btn.secondary:hover {
  background: var(--btn-sec-hover-bg) !important;
  border: 1.5px solid var(--btn-sec-border) !important;
  color: var(--btn-sec-hover-color) !important;
}

button.danger, .btn.danger { background: var(--danger); color: #fff; }
button.danger:hover, .btn.danger:hover { background: var(--danger); color: #fff; }
.full { width: 100%; margin-top: 20px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; line-height: 1.4; }
.footer-link { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted); }
.footer-link a { color: var(--accent); text-decoration: none; font-weight: 600; }
.footer-link a:hover { text-decoration: underline; }

/* ===== TABLES & BADGES ===== */
.table-wrap { 
  overflow-x: auto; 
  -webkit-overflow-scrolling: touch;
  margin-top: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.table-wrap::-webkit-scrollbar {
  height: 6px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 13px; 
}

.table-wrap table {
  min-width: 650px;
}

/* Key-value tables */
table.kv-table {
  min-width: 0 !important;
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
table.kv-table th {
  width: 35%;
  background: rgba(125, 125, 125, 0.04);
}
table.kv-table td {
  word-break: break-all;
}

th, td { 
  text-align: left; 
  padding: 10px 12px; 
  border-bottom: 1px solid var(--border); 
}
th { 
  color: var(--text-muted); 
  font-weight: 600; 
}
tr:last-child td, tr:last-child th {
  border-bottom: none;
}

.badge { 
  display: inline-block; 
  padding: 3px 9px; 
  border-radius: 999px; 
  font-size: 11px; 
  font-weight: 600; 
}
.badge.active { background: rgba(22,163,74,0.12); color: var(--success); }
.badge.banned, .badge.revoked { background: rgba(246,93,109,0.12); color: var(--danger); }
.badge.pending { background: rgba(109,109,246,0.12); color: var(--accent); }

.section { margin-top: 28px; }
.section h2 { font-size: 16px; margin-bottom: 6px; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

nav.topbar { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 24px; 
  flex-wrap: wrap;
  gap: 12px;
}
nav.topbar .brand { 
  margin: 0; 
  justify-content: flex-start; 
}
nav.topbar .brand img {
  height: 56px;
}

/* ============================================================
   RESPONSIVE MOBILE STYLES (Screen width <= 640px)
   ============================================================ */
@media (max-width: 640px) {
  body {
    padding: 12px 10px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .card {
    padding: 22px 16px;
    margin-top: 10px;
    margin-bottom: 16px;
    border-radius: 12px;
  }

  .card.wide {
    padding: 18px 14px;
    margin-top: 8px;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  input, select {
    font-size: 16px;
    padding: 12px 14px;
    min-height: 44px;
  }

  button, .btn {
    min-height: 44px;
    padding: 11px 16px;
    font-size: 14px;
  }

  nav.topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
  }

  nav.topbar .brand {
    justify-content: space-between;
    width: 100%;
  }

  nav.topbar .brand img {
    height: 48px;
  }

  nav.topbar .row {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  nav.topbar .row .hint {
    width: 100%;
    margin-bottom: 4px;
  }

  nav.topbar .row .btn,
  nav.topbar .row button {
    flex: 1;
    text-align: center;
    min-width: 80px;
  }

  /* Admin form stacking */
  #inviteForm, #buildForm {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 10px;
  }

  #inviteForm input,
  #inviteForm select,
  #inviteForm button,
  #buildForm select,
  #buildForm input,
  #buildForm button {
    width: 100% !important;
  }

  table.kv-table th {
    width: 40%;
    padding: 8px 10px;
  }

  table.kv-table td {
    padding: 8px 10px;
  }
}

/* ============================================================
   FEATURES & DEVELOPERS (HOME PAGE)
   ============================================================ */
.features-title { color: var(--text) !important; }
.feature-group {
  background: #d9d9d9 !important;
  border: 1px solid #d9d9d9 !important;
  box-shadow: none;
}
.feature-group:hover {
  background: #c4c4c4 !important;
  border-color: #c4c4c4 !important;
}
.feature-group-header h3 { color: #000 !important; }
.feature-group-header:hover { background: rgba(0, 0, 0, 0.06) !important; }
.feature-group-header .chevron { color: #000 !important; }
.feature-list li {
  color: #000 !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
}
.feature-list li::before { color: rgba(0, 0, 0, 0.5) !important; }

/* ===== DEVELOPERS (TEAM) ===== */
.developers-title { color: var(--text) !important; }
.developers-subtitle { color: var(--text-muted) !important; }
.developer-card {
  background: #d9d9d9 !important;
  border: 1px solid #d9d9d9 !important;
  box-shadow: none;
}
.developer-card:hover {
  background: #c4c4c4 !important;
  border-color: #c4c4c4 !important;
}
.developer-avatar {
  border: 3px solid rgba(0, 0, 0, 0.2) !important;
  background: rgba(255, 255, 255, 0.3) !important;
}
.developer-name { color: #000 !important; }
.developer-role { color: rgba(0, 0, 0, 0.6) !important; }
.developer-bio { color: #000 !important; }
.developer-links a {
  background: rgba(0, 0, 0, 0.12) !important;
  color: #000 !important;
}
.developer-links a:hover {
  background: #000 !important;
  color: #fff !important;
}

/* ===== FOOTER ===== */
.footer { border-top: 1px solid var(--border) !important; }
.footer p { color: var(--text-muted) !important; }
.footer a { color: var(--accent) !important; }
.footer a:hover { color: var(--accent-hover) !important; }
