:root {
  --ig-bg: #000000;
  --ig-card-bg: #121212;
  --ig-card-bg-alt: #1a1a1a;
  --ig-border: #2f2f2f;
  --ig-text: #f5f5f5;
  --ig-text-secondary: #a8a8a8;
  --ig-blue: #0095f6;
  --ig-blue-hover: #3ea6ff;
  --ig-red: #ed4956;
  --ig-green: #4caf50;
  --ig-gradient: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  --radius-card: 12px;
  --radius-btn: 8px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--ig-bg);
  color: var(--ig-text);
  line-height: 1.4;
  font-size: 14px;
}

a { color: var(--ig-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 600; }

.muted { color: var(--ig-text-secondary); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Topbar ---------- */

header.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--ig-border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

header.topbar .topbar-inner {
  width: 100%;
  max-width: 975px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  font-family: "Grand Hotel", "Brush Script MT", "Segoe Script", cursive;
  font-size: 1.9rem;
  font-weight: 400;
  line-height: 1;
  background: var(--ig-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--ig-red);
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.admin-badge {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-fill-color: initial;
  background: none;
  color: var(--ig-text-secondary);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--ig-border);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

nav.nav-icons {
  display: flex;
  align-items: center;
  gap: 22px;
}

.nav-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ig-text);
  cursor: pointer;
  background: none;
  border: none;
  font: inherit;
}
.nav-icon:hover { text-decoration: none; opacity: 0.65; }
.nav-icon svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-icon.active svg { stroke-width: 2.4; }
.nav-icon .nav-label { font-size: 0.62rem; display: none; }

/* ---------- Avatars ---------- */

.avatar {
  border-radius: 50%;
  background: var(--ig-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}
.avatar-sm { width: 32px; height: 32px; font-size: 0.85rem; }
.avatar-md { width: 44px; height: 44px; font-size: 1.05rem; }
.avatar-lg { width: 84px; height: 84px; font-size: 2rem; }

/* ---------- Layout ---------- */

main.ig-page {
  max-width: 630px;
  margin: 0 auto;
  padding: 92px 16px 90px;
}

main.ig-page.wide { max-width: 900px; }

.card {
  background: var(--ig-card-bg);
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 20px;
}

h1 { font-size: 1.35rem; margin: 0 0 6px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p.subtitle { color: var(--ig-text-secondary); margin-top: -6px; }

/* ---------- Auth pages (index / login) ---------- */

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 16px 40px;
  gap: 12px;
}

.auth-card {
  width: 100%;
  max-width: 350px;
  background: var(--ig-card-bg);
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  padding: 36px 40px 26px;
  text-align: center;
}

.auth-card .wordmark {
  font-size: 2.4rem;
  display: inline-block;
  margin-bottom: 22px;
}

.auth-card p.tagline {
  color: var(--ig-text);
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 20px;
}

.auth-card form label { text-align: left; }

.auth-switch-card {
  width: 100%;
  max-width: 350px;
  background: var(--ig-card-bg);
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  padding: 18px;
  text-align: center;
  font-size: 0.92rem;
}

/* ---------- Form card (register / profile) ---------- */

.ig-form-card {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

/* ---------- Fields ---------- */

fieldset {
  border: none;
  border-top: 1px solid var(--ig-border);
  margin: 0 0 18px;
  padding: 18px 0 0;
}
fieldset:first-of-type { border-top: none; padding-top: 0; }

legend {
  padding: 0;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ig-text-secondary);
  margin-bottom: 8px;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ig-text);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--ig-border);
  border-radius: 6px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #1a1a1a;
  color: var(--ig-text);
}

input::placeholder, textarea::placeholder { color: #6b6b6b; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #6b6b6b;
  background: #1f1f1f;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a8a8a8' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* ---------- Buttons ---------- */

.button-primary, .button-secondary, .button-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-btn);
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.button-primary {
  background: var(--ig-blue);
  color: #fff;
}
.button-primary:hover { background: var(--ig-blue-hover); text-decoration: none; }

.button-secondary {
  background: #1a1a1a;
  color: var(--ig-text);
  border: 1px solid var(--ig-border);
}
.button-secondary:hover { background: #232323; text-decoration: none; }

.button-danger {
  background: #1a1a1a;
  color: var(--ig-red);
  border: 1px solid var(--ig-border);
}
.button-danger:hover { background: #2a1417; text-decoration: none; }

.button-full { width: 100%; }

.button-primary:disabled, .button-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

.connect-gate-card code {
  background: #232323;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}
.button-small { padding: 6px 12px; font-size: 0.78rem; border-radius: 6px; }

.button-round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  background: var(--ig-gradient);
  color: #fff;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.button-round:hover { opacity: 0.85; }

/* ---------- Alerts ---------- */

.alert {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}
.alert-error { background: rgba(237, 73, 86, 0.12); color: #ff7b85; border: 1px solid rgba(237, 73, 86, 0.35); }
.alert-success { background: rgba(76, 175, 80, 0.12); color: #74d478; border: 1px solid rgba(76, 175, 80, 0.35); }
.alert-warn { background: rgba(255, 193, 7, 0.12); color: #ffcf5c; border: 1px solid rgba(255, 193, 7, 0.35); }

.page-links {
  margin-top: 6px;
  font-size: 0.85rem;
}

/* ---------- Profile header (dashboard) ---------- */

.profile-header {
  display: flex;
  align-items: center;
  gap: 22px;
}
.profile-header-info h1 { margin: 0 0 4px; }

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}
.section-title-row h2 { margin: 0; }
.link-see-all { font-size: 0.85rem; font-weight: 600; }

/* ---------- Stats strip ---------- */

.stats-strip {
  display: flex;
  flex-wrap: wrap;
  background: var(--ig-card-bg);
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  margin-bottom: 20px;
}
.stat {
  flex: 1 1 20%;
  min-width: 108px;
  text-align: center;
  padding: 16px 8px;
  border-right: 1px solid var(--ig-border);
  border-bottom: 1px solid var(--ig-border);
}
.stat:nth-last-child(-n+1) { border-right: none; }
.stat .num { font-size: 1.4rem; font-weight: 700; }
.stat .lbl { font-size: 0.68rem; color: var(--ig-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }

/* ---------- Redeem form ---------- */

.small-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.small-form label { margin-bottom: 0; flex: 1; min-width: 180px; }

/* ---------- Prize / business "post" cards ---------- */

.prize-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.prize-card {
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  background: var(--ig-card-bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.prize-media {
  aspect-ratio: 1.6 / 1;
  background: var(--ig-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.9);
}
.prize-media svg { width: 46px; height: 46px; stroke: #fff; fill: none; stroke-width: 1.6; }

.prize-body { padding: 14px 16px; flex: 1; }
.prize-card h3 { margin: 0 0 6px; font-size: 1rem; }
.prize-card p { margin: 4px 0; font-size: 0.85rem; color: var(--ig-text-secondary); }
.prize-card p strong { color: var(--ig-text); }

.prize-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--ig-border);
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--ig-border);
  background: #1a1a1a;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ig-text);
  cursor: pointer;
  font-family: inherit;
}
.icon-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.icon-btn:hover { background: #232323; }
.icon-btn.danger { color: var(--ig-red); }
.icon-btn.danger:hover { background: #2a1417; }

/* ---------- Chips / badges ---------- */

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.chip-ok { background: rgba(76, 175, 80, 0.15); color: #74d478; }
.chip-warn { background: rgba(255, 193, 7, 0.15); color: #ffcf5c; }
.chip-off { background: #232323; color: var(--ig-text-secondary); }

/* ---------- Codes list ---------- */

.codes-list {
  margin: 0 16px 14px;
  max-height: 170px;
  overflow-y: auto;
  border-top: 1px dashed var(--ig-border);
  padding-top: 8px;
}
.code-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  padding: 5px 0;
  font-family: "Courier New", monospace;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 40px 10px;
  color: var(--ig-text-secondary);
}
.empty-state svg { width: 40px; height: 40px; stroke: var(--ig-text-secondary); fill: none; stroke-width: 1.4; margin-bottom: 10px; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px;
  overflow-y: auto;
  z-index: 100;
}

.hidden { display: none; }

.modal {
  background: var(--ig-card-bg-alt);
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  padding: 0;
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ig-border);
}
.modal-header h2 { margin: 0; font-size: 0.95rem; }

.modal-header button, .modal-header a.modal-close-link {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--ig-text-secondary);
  line-height: 1;
}

.modal form { padding: 20px 20px 0; }
.modal .actions-row { padding: 0 20px 20px; border-top: 1px solid var(--ig-border); margin-top: 6px; padding-top: 16px; }

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* ---------- Bottom mobile nav ---------- */

.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 54px;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--ig-border);
  align-items: center;
  justify-content: space-around;
  z-index: 50;
}
.bottom-nav .nav-icon svg { width: 25px; height: 25px; }

/* ---------- Backoffice ---------- */

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ig-border);
  border-radius: var(--radius-card);
  margin-bottom: 20px;
}
table.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  background: var(--ig-card-bg);
}
table.admin-table th, table.admin-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--ig-border);
  font-size: 0.85rem;
  white-space: nowrap;
}
table.admin-table th {
  color: var(--ig-text-secondary);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  font-weight: 700;
}
table.admin-table tr:last-child td { border-bottom: none; }
table.admin-table td.wrap { white-space: normal; }

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.search-row input { margin-top: 0; flex: 1; min-width: 200px; }

.kv-list { margin: 0; }
.kv-list div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--ig-border); font-size: 0.85rem; }
.kv-list div:last-child { border-bottom: none; }
.kv-list span.k { color: var(--ig-text-secondary); }
.kv-list span.v { text-align: right; font-weight: 600; }

footer.site-footer {
  text-align: center;
  color: var(--ig-text-secondary);
  font-size: 0.75rem;
  padding: 20px;
}

/* ---------- Responsive ---------- */

@media (max-width: 700px) {
  header.topbar nav.nav-icons { display: none; }
  .bottom-nav { display: flex; }
  main.ig-page { padding-bottom: 80px; }
  .auth-wrapper { padding-bottom: 80px; }
}

@media (max-width: 480px) {
  .card { padding: 18px; }
  .auth-card { padding: 30px 22px 22px; }
  .profile-header { flex-wrap: wrap; text-align: center; justify-content: center; }
  .profile-header-info { width: 100%; }
  .avatar-lg { width: 64px; height: 64px; font-size: 1.5rem; margin: 0 auto; }
  .small-form { flex-direction: column; align-items: stretch; }
  .small-form label { min-width: 0; }
  .stat { flex: 1 1 33%; }
  .section-title-row { justify-content: flex-start; }
  .modal-backdrop { padding: 24px 12px; }
  .actions-row { flex-direction: column; }
  .actions-row .button-primary, .actions-row .button-secondary, .actions-row .button-danger { width: 100%; }
}
