/* ===== CSS Reset & Base Styles ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --background: #f8fafc;
  --surface: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --border: #e2e8f0;
  --error: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--background);
}

/* ===== Alpine.js x-cloak ===== */
[x-cloak] {
  display: none !important;
}

/* ===== App Container ===== */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.app-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0;
  color: var(--text-primary);
}

.btn-logout {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.main-nav {
  display: flex;
  gap: 0.5rem;
}

.main-nav button {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.main-nav button:hover {
  background: var(--background);
  color: var(--text-primary);
}

.main-nav button.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* ===== Main Content ===== */
.app-main {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: white;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  margin-top: 1rem;
  font-size: 1rem;
}

/* ===== Error Banner ===== */
.error-banner {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--error);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 400px;
}

.error-banner p {
  flex: 1;
  margin: 0;
}

.error-banner button {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.error-banner button:hover {
  opacity: 1;
}

/* ===== Filters ===== */
.filters {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  width: 300px;
  transition: border-color 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.status-filter {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.2s;
  min-width: 180px;
}

.status-filter:focus {
  outline: none;
  border-color: var(--primary-color);
}

.status-filter:hover {
  border-color: var(--secondary-color);
}

/* ===== Games Table ===== */
.games-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  border-collapse: collapse;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.games-table thead {
  background: var(--background);
}

.games-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.games-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s;
}

.games-table th.sortable:hover {
  background: var(--border);
}

.games-table .sort-indicator {
  margin-left: 0.25rem;
  font-size: 0.75rem;
  color: var(--primary-color);
}

.games-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.games-table tbody tr:last-child td {
  border-bottom: none;
}

.games-table tbody tr:hover {
  background: var(--background);
}

.games-table .game-name {
  font-weight: 500;
  color: var(--text-primary);
  max-width: 300px;
}

.games-table .status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--background);
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.games-table .bgg-link {
  font-size: 0.875rem;
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
  white-space: nowrap;
}

.games-table .bgg-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* ===== Plays Table ===== */
.plays-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  border-collapse: collapse;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.plays-table thead {
  background: var(--background);
}

.plays-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.plays-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s;
}

.plays-table th.sortable:hover {
  background: var(--border);
}

.plays-table .sort-indicator {
  margin-left: 0.25rem;
  font-size: 0.75rem;
  color: var(--primary-color);
}

.plays-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.plays-table tbody tr:last-child td {
  border-bottom: none;
}

.plays-table tbody tr:hover {
  background: var(--background);
}

.plays-table .play-notes {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plays-table .winner-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--success);
  color: white;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.plays-table .text-muted {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 0.75rem;
}

.btn-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.25rem;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.2s;
}

.btn-delete:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
  font-size: 1.125rem;
}

/* ===== Statistics ===== */
.stats-section {
  margin-bottom: 3rem;
}

.stats-section h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.stat-card h4 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--primary-color);
}

.stat-card p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.winners-list {
  list-style: none;
  padding: 0;
}

.winners-list li {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.winners-list li:last-child {
  border-bottom: none;
}

/* ===== Stats Table ===== */
.stats-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  border-collapse: collapse;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stats-table thead {
  background: var(--background);
}

.stats-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
}

.stats-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr:hover {
  background: var(--background);
}

/* ===== Buttons ===== */
.btn-primary {
  padding: 0.75rem 1.5rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 0.375rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  .app-header {
    padding: 1rem;
  }

  .app-header h1 {
    font-size: 1.5rem;
  }

  .main-nav {
    flex-wrap: wrap;
  }

  .app-main {
    padding: 1rem;
  }

  .view-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .filters {
    width: 100%;
    flex-direction: column;
    gap: 0.75rem;
  }

  .search-input,
  .status-filter {
    width: 100%;
  }

  .games-table,
  .plays-table {
    font-size: 0.75rem;
  }

  .games-table th,
  .games-table td,
  .plays-table th,
  .plays-table td {
    padding: 0.5rem;
  }

  .games-table .game-name,
  .plays-table .game-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .plays-table .play-notes {
    max-width: 100px;
  }

  .error-banner {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
}

/* ===== Forms ===== */
.compact-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.compact-form h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

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

.form-field {
  display: flex;
  flex-direction: column;
}

.form-field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 0.2s;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary-color);
}

.form-field.full-width {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.btn-submit {
  padding: 0.5rem 1.5rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-submit:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-error {
  background: #fee;
  border: 1px solid var(--error);
  border-radius: 0.375rem;
  padding: 0.75rem;
  margin-bottom: 1rem;
  color: var(--error);
  font-size: 0.875rem;
}

/* ===== Transitions ===== */
.x-transition-enter {
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.x-transition-enter-start {
  opacity: 0;
  transform: translateY(-10px);
}

.x-transition-enter-end {
  opacity: 1;
  transform: translateY(0);
}

.x-transition-leave {
  transition: opacity 0.2s ease-in, transform 0.2s ease-in;
}

.x-transition-leave-start {
  opacity: 1;
  transform: translateY(0);
}

.x-transition-leave-end {
  opacity: 0;
  transform: translateY(-10px);
}
