* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #e7eaf0;
  --text: #172033;
  --muted: #748096;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --sidebar: #111827;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 245px;
  background: var(--sidebar);
  color: white;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 28px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--primary);
  font-size: 20px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: #9ca3af;
  text-align: left;
  padding: 12px 13px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  gap: 11px;
}

.nav-item:hover,
.nav-item.active {
  background: #1f2937;
  color: white;
}

.nav-item span {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  color: #9ca3af;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  height: 86px;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 18px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.refresh-btn,
.primary-btn,
.secondary-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 15px;
  font-weight: 600;
}

.refresh-btn {
  background: #eef2ff;
  color: var(--primary);
}

.primary-btn {
  background: var(--primary);
  color: white;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  background: #eef0f4;
  color: var(--text);
}

.section {
  display: none;
  padding: 28px 30px;
}

.section.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.stat-icon {
  width: 45px;
  height: 45px;
  border-radius: 11px;
  background: #eff6ff;
  display: grid;
  place-items: center;
  font-size: 19px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.stat-card strong {
  font-size: 21px;
}

.content-grid,
.settings-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
}

.panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
}

.panel-header {
  padding: 19px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.customer-list {
  padding: 8px 20px 16px;
}

.customer-row {
  padding: 14px 0;
  border-bottom: 1px solid #f0f1f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.customer-row:last-child {
  border-bottom: 0;
}

.customer-name {
  font-weight: 600;
  font-size: 13px;
}

.customer-email {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.points {
  font-weight: 700;
  color: #d97706;
}

.tier-summary {
  padding: 15px 20px;
}

.tier-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.tier-card:last-child {
  margin-bottom: 0;
}

.tier-card strong {
  display: block;
  margin-bottom: 5px;
}

.tier-meta {
  color: var(--muted);
  font-size: 12px;
}

.search {
  width: 240px;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.search:focus,
.settings-form input:focus,
.modal-box input:focus {
  border-color: var(--primary);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  text-align: left;
  padding: 14px 18px;
  border-bottom: 1px solid #f0f1f4;
  font-size: 12px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #fafbfc;
}

.badge {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 10px;
  font-weight: 700;
}

.badge.success {
  background: #dcfce7;
  color: #15803d;
}

.badge.warning {
  background: #fef3c7;
  color: #b45309;
}

.small-btn {
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  background: #eff6ff;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}

.reward-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.reward-item {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 18px;
}

.reward-points {
  color: #d97706;
  font-weight: 800;
  font-size: 22px;
}

.reward-name {
  font-weight: 700;
  margin: 8px 0;
}

.reward-info {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.reward-actions {
  display: flex;
  gap: 7px;
  margin-top: 14px;
}

.delete-btn {
  border: 0;
  background: #fee2e2;
  color: var(--danger);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 700;
}

.settings-form {
  padding: 22px;
}

.settings-form label,
.modal-box label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 15px;
}

.settings-form input,
.modal-box input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  margin: -4px 0 18px;
}

.system-status {
  padding: 12px 20px;
}

.system-status div {
  padding: 14px 0;
  border-bottom: 1px solid #f0f1f4;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.system-status div:last-child {
  border: 0;
}

.online {
  color: var(--success);
  font-size: 11px;
}

.loading {
  display: none;
  padding: 15px 30px;
  color: var(--muted);
  font-size: 12px;
}

.error {
  margin: 15px 30px 0;
  padding: 12px 15px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.empty {
  padding: 30px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal-box {
  width: 440px;
  max-width: 100%;
  background: white;
  border-radius: 13px;
  padding: 22px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-header button {
  border: 0;
  background: transparent;
  font-size: 25px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

@media (max-width: 1050px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .reward-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 720px) {
  .app {
    display: block;
  }

  .sidebar {
    width: 100%;
    padding: 12px;
  }

  .brand {
    padding-bottom: 12px;
  }

  nav {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
    width: auto;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    height: auto;
    padding: 18px;
  }

  .section {
    padding: 18px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .reward-grid {
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }
}

/* Dashboard authentication */
.hidden {
  display: none !important;
}

.login-mode {
  min-height: 100vh;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
}

.login-card .brand {
  margin-bottom: 28px;
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-subtitle {
  margin: 0 0 24px;
  opacity: 0.7;
}

.login-card form {
  display: grid;
  gap: 16px;
}

.login-card label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

.login-card input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  font: inherit;
}

.primary-btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

#dashboardLoginError {
  margin: 0;
}
