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

/* ── Design Tokens ── */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(99, 102, 241, 0.4);

  --text-primary: #f0f0f5;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --text-accent: #818cf8;

  --accent-indigo: #6366f1;
  --accent-indigo-light: #818cf8;
  --accent-violet: #8b5cf6;
  --accent-emerald: #34d399;
  --accent-amber: #fbbf24;
  --accent-rose: #fb7185;
  --accent-sky: #38bdf8;

  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
  --gradient-card: linear-gradient(145deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
  --gradient-glow: radial-gradient(600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(99, 102, 241, 0.06), transparent 40%);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', 'Noto Sans TC', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Background decoration */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(56, 189, 248, 0.04) 0%, transparent 50%);
  z-index: 0;
  pointer-events: none;
}

/* ── Layout ── */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── Header ── */
.app-header {
  text-align: center;
  padding: 40px 0 32px;
}

.app-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.app-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 300;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: stretch;
}

.search-box {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 14px 16px 14px 46px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
  backdrop-filter: blur(12px);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), var(--shadow-glow);
}

.filter-select {
  padding: 14px 36px 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition-base);
  backdrop-filter: blur(12px);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  min-width: 140px;
}

.filter-select:focus {
  outline: none;
  border-color: var(--accent-indigo);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: var(--shadow-sm), 0 0 20px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), 0 0 30px rgba(99, 102, 241, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
}

.btn-ghost:hover {
  border-color: var(--border-accent);
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.08);
}

.btn-danger {
  background: rgba(251, 113, 133, 0.1);
  color: var(--accent-rose);
  border: 1px solid rgba(251, 113, 133, 0.2);
}

.btn-danger:hover {
  background: rgba(251, 113, 133, 0.2);
  border-color: rgba(251, 113, 133, 0.4);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 10px;
  min-width: 42px;
  justify-content: center;
}

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 100px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
}

.stat-chip .stat-value {
  font-weight: 700;
  color: var(--text-accent);
}

/* ── Card Grid ── */
.rules-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 700px) {
  .rules-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Rule Card ── */
.rule-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  transition: all var(--transition-base);
  overflow: hidden;
}

.rule-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-card);
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.rule-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md), var(--shadow-glow);
  transform: translateY(-2px);
}

.rule-card:hover::before {
  opacity: 1;
}

/* ── Distinct Card Themes ── */
.rule-card.card-cube {
  border-left: 4px solid #fbbf24; /* Gold/Amber */
}
.rule-card.card-cube:hover {
  border-color: #fbbf24;
  box-shadow: 0 4px 16px rgba(251, 191, 36, 0.15), 0 0 30px rgba(251, 191, 36, 0.08);
}
.rule-card.card-cube .rule-card-title {
  color: #fbbf24;
}

.rule-card.card-unicard {
  border-left: 4px solid #34d399; /* Emerald/Green */
}
.rule-card.card-unicard:hover {
  border-color: #34d399;
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.15), 0 0 30px rgba(52, 211, 153, 0.08);
}
.rule-card.card-unicard .rule-card-title {
  color: #34d399;
}

.rule-card.card-jcard {
  border-left: 4px solid #38bdf8; /* Sky Blue */
}
.rule-card.card-jcard:hover {
  border-color: #38bdf8;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.15), 0 0 30px rgba(56, 189, 248, 0.08);
}
.rule-card.card-jcard .rule-card-title {
  color: #38bdf8;
}

.rule-card.card-kumamon {
  border-left: 4px solid #fb7185; /* Rose/Red */
}
.rule-card.card-kumamon:hover {
  border-color: #fb7185;
  box-shadow: 0 4px 16px rgba(251, 113, 133, 0.15), 0 0 30px rgba(251, 113, 133, 0.08);
}
.rule-card.card-kumamon .rule-card-title {
  color: #fb7185;
}


.rule-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  position: relative;
  z-index: 1;
}

.rule-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.rule-card-title .card-icon {
  font-size: 1.2rem;
}

.reward-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.15) 0%, rgba(52, 211, 153, 0.05) 100%);
  color: var(--accent-emerald);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.rule-card-body {
  position: relative;
  z-index: 1;
}

.rule-field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.88rem;
}

.rule-field:last-child {
  margin-bottom: 0;
}

.rule-field-label {
  color: var(--text-muted);
  min-width: 70px;
  flex-shrink: 0;
  font-weight: 500;
}

.rule-field-value {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Tag chips for stores */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.78rem;
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-indigo-light);
  border: 1px solid rgba(99, 102, 241, 0.15);
}

/* Switch badge */
.switch-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.78rem;
}

.switch-badge.yes {
  background: rgba(251, 191, 36, 0.12);
  color: var(--accent-amber);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.switch-badge.no {
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent-emerald);
  border: 1px solid rgba(52, 211, 153, 0.15);
}

/* Channel badge */
.channel-badge {
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-sky);
  border: 1px solid rgba(56, 189, 248, 0.15);
}

/* Card actions */
.rule-card-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.rule-card:hover .rule-card-actions {
  opacity: 1;
}

.rule-card-actions button {
  padding: 6px 8px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}

.rule-card-actions button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.rule-card-actions button.delete-btn:hover {
  background: rgba(251, 113, 133, 0.15);
  color: var(--accent-rose);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.88rem;
  max-width: 360px;
  margin: 0 auto;
}

/* ── Data Management Bar ── */
.data-bar {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Toast / Notification ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in 300ms ease-out;
  max-width: 360px;
}

.toast.success {
  border-color: rgba(52, 211, 153, 0.3);
}

.toast.error {
  border-color: rgba(251, 113, 133, 0.3);
}

@keyframes toast-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ── Notes text ── */
.notes-text {
  font-style: italic;
  color: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .app-header h1 {
    font-size: 1.6rem;
  }

  .toolbar {
    flex-direction: column;
  }

  .filter-select {
    min-width: unset;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

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

  .modal {
    border-radius: var(--radius-lg);
  }

  .modal-body {
    padding: 20px;
  }

  .rule-card-actions {
    opacity: 1;
  }

  .data-bar {
    justify-content: center;
  }

  .stats-bar {
    justify-content: center;
  }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Selection ── */
::selection {
  background: rgba(99, 102, 241, 0.3);
}
