/* ==========================================================================
   Lucky Wheel - shared design tokens and components
   ========================================================================== */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e2e6f0;
  --border-strong: #cbd3e4;
  --text: #101426;
  --muted: #626b85;
  --faint: #8b93aa;

  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --accent: #f59e0b;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --info: #0284c7;
  --info-soft: #f0f9ff;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 20, 38, .06), 0 1px 3px rgba(16, 20, 38, .04);
  --shadow: 0 4px 14px rgba(16, 20, 38, .08);
  --shadow-lg: 0 18px 48px rgba(16, 20, 38, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; line-height: 1.55; }
a { color: var(--brand); }

/* --- Layout helpers ------------------------------------------------------ */
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: .5rem; }
.row { display: flex; gap: .75rem; align-items: center; }
.row-between { display: flex; gap: .75rem; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hidden { display: none !important; }
.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); font-size: .85rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  margin: -1.15rem -1.15rem 1rem;
  padding: .9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-header h2, .card-header h3 { margin: 0; }
.card-tight { padding: 0; }

/* --- Stats --------------------------------------------------------------- */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; }
.stat-value { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; margin-top: .25rem; }
.stat-sub { font-size: .82rem; color: var(--muted); margin-top: .2rem; }

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: .6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(.94); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.94); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .35rem .6rem; font-size: .82rem; }
.btn-lg { padding: .95rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* --- Forms --------------------------------------------------------------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: .95rem;
  padding: .58rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input[type=color] { width: 46px; height: 38px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: .9rem; }
.field-row { display: flex; gap: .75rem; }
.field-row > * { flex: 1; }
.checkbox { display: flex; align-items: flex-start; gap: .6rem; font-weight: 500; color: var(--text); font-size: .92rem; margin-bottom: 0; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--brand); }
.help { font-size: .8rem; color: var(--faint); margin-top: .25rem; }

/* --- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 700;
  padding: .6rem .75rem; border-bottom: 1px solid var(--border); background: var(--surface-2);
  position: sticky; top: 0; white-space: nowrap;
}
td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--faint); }

/* --- Badges -------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  padding: .2rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  text-transform: uppercase;
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn);    border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.badge-brand   { background: var(--brand-soft);   color: var(--brand);   border-color: color-mix(in srgb, var(--brand) 25%, transparent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot-live { background: var(--success); box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* --- Alerts -------------------------------------------------------------- */
.alert { padding: .75rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid; line-height: 1.45; }
.alert-error   { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent);  color: #991b1b; }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: #065f46; }
.alert-warn    { background: var(--warn-soft);    border-color: color-mix(in srgb, var(--warn) 30%, transparent);    color: #92400e; }
.alert-info    { background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 30%, transparent);    color: #075985; }

/* --- Toasts -------------------------------------------------------------- */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; max-width: min(380px, calc(100vw - 2rem)); }
.toast {
  background: #101426; color: #fff; padding: .7rem .9rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: .9rem; line-height: 1.4;
  animation: toast-in .2s ease-out;
}
.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Modal --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11, 16, 32, .55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 500;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }

/* --- Utility bars -------------------------------------------------------- */
.meter { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block;
}
.spinner-dark { border-color: rgba(16, 20, 38, .2); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
