/* ===========================================================
   World Cup Predictor — shadcn-inspired dark theme
   Mobile-first, card-based, football themed
   =========================================================== */

:root {
  --background: 222 47% 6%;
  --foreground: 210 40% 98%;
  --card: 222 40% 9%;
  --card-foreground: 210 40% 98%;
  --popover: 222 40% 9%;
  --popover-foreground: 210 40% 98%;
  --primary: 142 71% 45%;
  --primary-foreground: 222 47% 6%;
  --secondary: 222 30% 16%;
  --secondary-foreground: 210 40% 98%;
  --muted: 222 30% 14%;
  --muted-foreground: 215 20% 65%;
  --accent: 38 92% 50%;
  --accent-foreground: 222 47% 6%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 210 40% 98%;
  --border: 222 30% 18%;
  --input: 222 30% 16%;
  --ring: 142 71% 45%;
  --radius: 0.75rem;

  --success: 142 71% 45%;
  --warning: 38 92% 50%;

  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: hsl(var(--primary));
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

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

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

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1rem;
}

main.page {
  flex: 1;
  padding: 1.25rem 0 4rem;
}

/* ----------------------------- Nav ----------------------------- */

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: hsla(222, 47%, 6%, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid hsl(var(--border));
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: hsl(var(--foreground));
  text-decoration: none;
}

.brand .ball {
  font-size: 1.25rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.nav-link:hover {
  color: hsl(var(--foreground));
  background-color: hsl(var(--secondary));
  text-decoration: none;
}
.nav-link.active {
  color: hsl(var(--primary-foreground));
  background-color: hsl(var(--primary));
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
}

.nav-toggle {
  display: none;
}

@media (max-width: 720px) {
  .nav-links {
    display: none;
    position: absolute;
    top: 3.5rem;
    left: 0;
    right: 0;
    flex-direction: column;
    background-color: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--border));
    padding: 0.5rem;
    gap: 0.25rem;
  }
  .nav-links.open {
    display: flex;
  }
  .nav-toggle {
    display: inline-flex;
  }
  .nav-link {
    width: 100%;
  }
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
  user-select: none;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-primary:hover:not(:disabled) {
  background-color: hsl(142 71% 40%);
}

.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}
.btn-secondary:hover:not(:disabled) {
  background-color: hsl(222 30% 20%);
}

.btn-destructive {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}
.btn-destructive:hover:not(:disabled) {
  background-color: hsl(0 72% 45%);
}

.btn-ghost {
  background-color: transparent;
  color: hsl(var(--foreground));
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background-color: hsl(var(--secondary));
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

/* ----------------------------- Cards ----------------------------- */

.card {
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1rem;
}

.card + .card {
  margin-top: 0.75rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
}

.card-subtitle {
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  margin: 0.15rem 0 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.stat-card .stat-label {
  font-size: 0.72rem;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.3rem;
}
.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0;
  line-height: 1.1;
}
.stat-card .stat-meta {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin: 0.25rem 0 0;
}

/* ----------------------------- Forms ----------------------------- */

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: hsl(var(--muted-foreground));
}

input, select, textarea {
  width: 100%;
  background-color: hsl(var(--input));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsla(142, 71%, 45%, 0.25);
}
input:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input[type="number"].score-input {
  width: 3.2rem;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.4rem 0.25rem;
}

.field {
  margin-bottom: 0.75rem;
}

.field-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.field-row > .field {
  flex: 1;
  min-width: 120px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-field input[type="checkbox"] {
  width: auto;
}
.checkbox-field label {
  margin-bottom: 0;
}

/* ----------------------------- Score row ----------------------------- */

.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.score-row .team-name {
  flex: 1;
  text-align: right;
  font-weight: 600;
  font-size: 0.85rem;
}
.score-row .team-name.away {
  text-align: left;
}
.score-vs {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  font-weight: 700;
}

/* ----------------------------- Match card ----------------------------- */

.match-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
}

.match-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.4rem;
}

.match-status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.match-status.upcoming {
  background-color: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
}
.match-status.locked {
  background-color: hsla(38, 92%, 50%, 0.15);
  color: hsl(var(--accent));
}
.match-status.completed {
  background-color: hsla(142, 71%, 45%, 0.15);
  color: hsl(var(--primary));
}
.match-status.live {
  background-color: hsla(0, 72%, 51%, 0.15);
  color: hsl(0 80% 65%);
}
.match-status.live .live-dot {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background-color: hsl(0 80% 60%);
  animation: live-pulse 1.4s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.live-match-card .table-scroll table {
  font-size: 0.78rem;
}
.live-match-card .no-prediction {
  color: hsl(var(--muted-foreground));
  font-style: italic;
}

/* ----------------------------- Tables ----------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
th, td {
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}
th {
  color: hsl(var(--muted-foreground));
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr.highlight {
  background-color: hsla(142, 71%, 45%, 0.07);
}
.table-scroll {
  overflow-x: auto;
}

/* ----------------------------- Badges ----------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.badge-primary {
  background-color: hsla(142, 71%, 45%, 0.15);
  color: hsl(var(--primary));
}
.badge-accent {
  background-color: hsla(38, 92%, 50%, 0.15);
  color: hsl(var(--accent));
}
.badge-muted {
  background-color: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
}

/* ----------------------------- Tabs / group nav ----------------------------- */

.tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background-color: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.tab-btn.active {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

/* ----------------------------- Toasts ----------------------------- */

#toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: calc(100% - 2rem);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px hsla(0,0%,0%,0.35);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: toast-in 0.2s ease-out;
}
.toast.toast-success { border-color: hsl(var(--primary)); }
.toast.toast-error { border-color: hsl(var(--destructive)); }
.toast.toast-out {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(10px); }
}

/* ----------------------------- Autosave indicator ----------------------------- */

.autosave-indicator {
  font-size: 0.72rem;
  color: hsl(var(--muted-foreground));
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 1rem;
}
.autosave-indicator.saving { color: hsl(var(--accent)); }
.autosave-indicator.saved { color: hsl(var(--primary)); }
.autosave-indicator.error { color: hsl(var(--destructive)); }

/* ----------------------------- Spinner ----------------------------- */

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid hsla(0,0%,100%,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 0;
  color: hsl(var(--muted-foreground));
}
.spinner-page .spinner {
  width: 1.75rem;
  height: 1.75rem;
  border-width: 3px;
}

/* ----------------------------- Skeletons ----------------------------- */

.skeleton {
  background: linear-gradient(90deg, hsl(var(--secondary)) 25%, hsl(222 30% 22%) 37%, hsl(var(--secondary)) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius);
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.skeleton-text {
  height: 0.85rem;
  margin-bottom: 0.4rem;
  border-radius: 0.25rem;
}
.skeleton-card {
  height: 5rem;
}

/* ----------------------------- Login ----------------------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .ball-big {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}
.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 0.25rem;
}
.login-card p.subtitle {
  color: hsl(var(--muted-foreground));
  font-size: 0.85rem;
  margin: 0 0 1.25rem;
}

/* ----------------------------- Empty / error states ----------------------------- */

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: hsl(var(--muted-foreground));
}
.empty-state .icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.alert {
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  font-size: 0.83rem;
  margin-bottom: 0.75rem;
  border: 1px solid;
}
.alert-error {
  background-color: hsla(0, 72%, 51%, 0.1);
  border-color: hsla(0, 72%, 51%, 0.4);
  color: hsl(0 90% 75%);
}
.alert-info {
  background-color: hsla(38, 92%, 50%, 0.1);
  border-color: hsla(38, 92%, 50%, 0.4);
  color: hsl(38 92% 70%);
}
.alert-success {
  background-color: hsla(142, 71%, 45%, 0.1);
  border-color: hsla(142, 71%, 45%, 0.4);
  color: hsl(142 71% 70%);
}

/* ----------------------------- Bracket ----------------------------- */

.bracket-round {
  margin-bottom: 1.25rem;
}
.bracket-round h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  margin: 0 0 0.6rem;
}
.bracket-row {
  display: flex;
}
.bracket-scroll {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}
.bracket-col {
  min-width: 220px;
  flex-shrink: 0;
}
.bracket-match {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
}
.bracket-match .b-team {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
}
.bracket-match .b-team.winner {
  font-weight: 800;
  color: hsl(var(--primary));
}

/* Bracket advancement picker */
.pick-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  margin: 0.2rem 0;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  background-color: hsl(var(--secondary));
  color: hsl(var(--foreground));
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.pick-team:hover:not(:disabled) {
  border-color: hsl(var(--ring));
}
.pick-team:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.pick-team.selected {
  background-color: hsla(142, 71%, 45%, 0.15);
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
}
.pick-team .check {
  opacity: 0;
}
.pick-team.selected .check {
  opacity: 1;
}
.bracket-match.unresolved {
  opacity: 0.5;
}

/* ----------------------------- Utility ----------------------------- */

.text-muted { color: hsl(var(--muted-foreground)); }
.text-center { text-align: center; }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }

.fade-in {
  animation: fade-in 0.25s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
