:root {
  --app-bg: #f6f7fb;
  --app-panel: #ffffff;
  --app-border: #e3e6ee;
  --app-muted: #6b7280;
  --app-accent: #4f46e5;
  --app-code-bg: #eef0ff;
}

[data-bs-theme="dark"] {
  --app-bg: #12141a;
  --app-panel: #1b1e27;
  --app-border: #2c3040;
  --app-muted: #9aa3b5;
  --app-accent: #8b93ff;
  --app-code-bg: #262a3d;
}

body {
  background: var(--app-bg);
  color: var(--bs-body-color);
  transition: background 0.2s, color 0.2s;
}

.shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--app-accent);
  color: #fff;
}

.admin-link {
  color: var(--app-accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.intro h1 {
  font-size: 1.6rem;
  margin: 0 0 6px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--app-accent);
  font-weight: 700;
}

.intro-copy,
.helper-text {
  margin: 0;
  color: var(--app-muted);
  font-size: 0.9rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card,
.panel {
  background: var(--app-panel);
  border: 1px solid var(--app-border);
  border-radius: 14px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
}

.stat-label {
  color: var(--app-muted);
  font-size: 0.78rem;
}

.stat-card strong {
  font-size: 1.5rem;
}

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 1.1rem;
  margin: 0;
}

.count-pill {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--app-code-bg);
  font-size: 0.8rem;
}

.filter-select {
  width: auto;
}

.coupon-list,
.usage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.coupon-row {
  display: grid;
  grid-template-columns: 170px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--app-border);
  border-radius: 12px;
}

.coupon-code {
  text-align: center;
}

.coupon-meta .coupon-reward {
  overflow: visible;
  white-space: normal;
  color: var(--bs-body-color);
  font-size: 0.95rem;
  padding-left: 12px;
  border-left: 2px solid var(--app-border);
}

.coupon-meta .coupon-reward.is-empty {
  color: var(--app-muted);
  font-weight: 400;
}

.coupon-meta span {
  padding-left: 14px;
}

.coupon-row.is-used {
  opacity: 0.6;
  background: var(--app-code-bg);
}

.coupon-code {
  padding: 8px 12px;
  border: 1px dashed var(--app-accent);
  border-radius: 8px;
  background: var(--app-code-bg);
  color: var(--app-accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
}

.coupon-row.is-expired .coupon-code {
  border-color: var(--app-muted);
  color: var(--app-muted);
}

.coupon-row.is-expired {
  opacity: 0.6;
}

.coupon-row.is-used .coupon-code {
  text-decoration: line-through;
}

.coupon-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--app-muted);
}

.coupon-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coupon-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.usage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--app-border);
}

.usage-info {
  flex: 1;
  min-width: 0;
  color: var(--app-muted);
  font-size: 0.82rem;
}

.empty-state {
  margin: 0;
  padding: 20px 8px;
  text-align: center;
  color: var(--app-muted);
  list-style: none;
}

footer {
  margin-top: 24px;
  text-align: center;
  color: var(--app-muted);
  font-size: 0.8rem;
}

/* admin page */
.admin-form {
  display: grid;
  gap: 8px;
  max-width: 520px;
}

.admin-form label {
  font-size: 0.85rem;
  font-weight: 600;
}

.admin-form .btn {
  justify-self: start;
  margin-top: 6px;
}

.button-dark {
  background: var(--app-accent);
  border-color: var(--app-accent);
  color: #fff;
}

.source-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--app-border);
}

.admin-source-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.source-name {
  font-weight: 600;
}

.source-url {
  color: var(--app-muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.remove-button {
  color: #dc3545;
  border: 1px solid #dc3545;
}

.toast {
  display: none;
}

@media (max-width: 575px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .intro {
    flex-direction: column;
    align-items: stretch;
  }

  .intro h1 {
    font-size: 1.3rem;
  }

  .coupon-row {
    grid-template-columns: 1fr auto;
  }

  .coupon-code {
    grid-column: 1 / -1;
    text-align: center;
    padding: 12px;
    font-size: 1.1rem;
  }

  .coupon-meta {
    grid-column: 1;
  }

  .coupon-meta .coupon-reward,
  .coupon-meta span {
    padding-left: 0;
    border-left: 0;
  }
}

.coupon-code-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--app-accent);
}

.report-preview {
  display: block;
  max-width: 100%;
  max-height: 200px;
  margin-top: 8px;
  border: 1px solid var(--app-border);
  border-radius: 8px;
}

.report-notice {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--app-border);
  border-radius: 8px;
  background: var(--app-code-bg);
  font-size: 0.82rem;
  color: var(--app-muted);
}

.report-notice ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.report-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--app-border);
  border-radius: 8px;
  cursor: zoom-in;
}

.report-full {
  display: block;
  max-width: 100%;
  max-height: 50vh;
  margin: 0 auto 12px;
  border-radius: 8px;
}

.stat-card-button {
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.stat-card-button:hover {
  border-color: var(--app-accent);
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--app-border);
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.history-month {
  margin-bottom: 16px;
}

.history-month-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-weight: 700;
  border-bottom: 2px solid var(--app-border);
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--app-border);
  cursor: pointer;
}
.theme-widget {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 1050;
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background: var(--app-panel);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.theme-widget button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.theme-widget button.active {
  background: var(--app-code-bg);
  box-shadow: inset 0 0 0 2px var(--app-accent);
}
.footer-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--app-accent);
  font-size: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.admin-tabs {
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.form-error:empty {
  display: none;
}

.visit-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.visit-card { border: 1px solid var(--bs-border-color); border-radius: .75rem; padding: .75rem 1rem; }
.visit-label { font-size: .8rem; opacity: .7; }
.visit-number { font-size: 1.5rem; font-weight: 700; }
.visit-sub { font-size: .78rem; opacity: .75; }
.visit-row { display: grid; grid-template-columns: 3rem 1fr; gap: .5rem; align-items: center; margin-bottom: .35rem; font-size: .8rem; }
.visit-bar { height: .6rem; background: var(--bs-border-color); border-radius: 1rem; overflow: hidden; }
.visit-fill { display: block; height: 100%; background: var(--bs-primary); }
.visit-count { grid-column: 2; opacity: .75; font-size: .72rem; margin-top: -.2rem; }

.tip-previews { display: flex; gap: .5rem; flex-wrap: wrap; }
.tip-previews .report-preview { max-width: 31%; }
