/* ==========================================================================
   CSS Design System: School Sports Competition System
   ========================================================================== */

/* Theme Variables */
:root {
  --font-primary: 'Prompt', 'Sarabun', sans-serif;
  --font-display: 'Kanit', sans-serif;
  
  /* Light Theme Colors (Default) */
  --bg-app: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
  --bg-card: rgba(255, 255, 255, 0.7);
  --bg-card-hover: rgba(255, 255, 255, 0.85);
  --border-glass: rgba(255, 255, 255, 0.4);
  --border-dim: #cbd5e1;
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.06);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-dim: rgba(79, 70, 229, 0.1);
  
  --success: #10b981;
  --success-dim: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.1);
  
  --gold: #f59e0b;
  --silver: #94a3b8;
  --bronze: #b45309;
}

[data-theme="dark"] {
  /* Dark Theme Colors */
  --bg-app: radial-gradient(circle at top right, #0f172a 0%, #020617 100%);
  --bg-card: rgba(15, 23, 42, 0.45);
  --bg-card-hover: rgba(30, 41, 59, 0.55);
  --border-glass: rgba(255, 255, 255, 0.05);
  --border-dim: #334155;
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-inverse: #020617;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-dim: rgba(99, 102, 241, 0.15);
  
  --success: #34d399;
  --success-dim: rgba(52, 211, 153, 0.15);
  --warning: #fbbf24;
  --warning-dim: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.15);
}

/* Base Resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  width: 100%;
  max-width: 1280px;
  min-height: 100vh;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Glassmorphism Common Style */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  box-shadow: var(--shadow-glass);
  padding: 1.5rem;
}

/* Header Styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  box-shadow: var(--shadow-glass);
}

.header-logo-container {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.school-logo {
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.header-text h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--primary), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Tab Navigation */
.app-nav {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  border: 1px solid var(--border-glass);
}

[data-theme="dark"] .app-nav {
  background: rgba(255, 255, 255, 0.02);
}

.nav-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .nav-tab:hover {
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.nav-tab i {
  width: 18px;
  height: 18px;
}

/* Content Views */
.app-content {
  flex: 1;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Sections Header */
.section-header, .panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.section-header h2, .panel-header h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-header i, .panel-header i {
  width: 24px;
  height: 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  font-family: var(--font-primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  outline: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-dim);
  color: var(--text-main);
}

.btn-outline:hover {
  background: rgba(0, 0, 0, 0.02);
  border-color: var(--text-main);
}

[data-theme="dark"] .btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--text-main);
  border: 1px solid var(--border-glass);
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .btn-icon:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Icon Toggle states */
.sun-icon { display: none; }
.moon-icon { display: block; }
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }

/* Filter Bars */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-width: 200px;
}

.filter-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Forms input styles */
input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-dim);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text-main);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  outline: none;
}

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] select {
  background: rgba(15, 23, 42, 0.6);
  border-color: var(--border-dim);
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

/* Input Icon Wrapper */
.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.input-icon-wrapper input {
  padding-left: 2.5rem;
}

/* Form Helper Text */
.form-help {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th, td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-glass);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(0, 0, 0, 0.01);
}

[data-theme="dark"] tbody tr:hover {
  background: rgba(255, 255, 255, 0.01);
}

/* Medal Table specifics */
.medal-table th, .medal-table td {
  padding: 1.1rem 1rem;
}

/* Dashboards and Grid layouts */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.5rem;
}

.master-data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .master-data-grid {
    grid-template-columns: 1fr;
  }
}

/* Cards layout */
.sport-result-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sport-card-header {
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 0.75rem;
}

.sport-card-header h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}

.sport-card-header .sport-badge-container {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.badge {
  display: inline-flex;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
}

.badge-info { background: var(--primary-dim); color: var(--primary); }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }

/* Medals Display in Cards */
.medal-winners-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.medal-winner-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .medal-winner-row {
  background: rgba(255, 255, 255, 0.02);
}

.medal-winner-row.gold { border-left: 4px solid var(--gold); }
.medal-winner-row.silver { border-left: 4px solid var(--silver); }
.medal-winner-row.bronze { border-left: 4px solid var(--bronze); }

.medal-icon-badge {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.winner-details {
  flex: 1;
}

.winner-team-title {
  font-weight: 600;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.winner-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.winner-names {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* Master Data Cards */
.card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.card-title-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bg-red-dim { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.bg-indigo-dim { background: rgba(99, 102, 241, 0.1); color: #6366f1; }

.card-title-text h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.card-title-text p {
  font-size: 0.775rem;
  color: var(--text-muted);
}

.small-table td, .small-table th {
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
}

/* Color indicator square */
.color-swatch-preview {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.color-box {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Alerts */
.alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin: 1rem 0;
  border: 1px solid transparent;
}

.alert-danger {
  background: var(--danger-dim);
  border-color: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.alert-info {
  background: var(--primary-dim);
  border-color: rgba(99, 102, 241, 0.2);
  color: var(--primary);
}

.alert-success {
  background: var(--success-dim);
  border-color: rgba(52, 211, 153, 0.2);
  color: var(--success);
}

/* Admin forms panels styling */
.admin-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--success-dim);
  color: var(--success);
  padding: 0.4rem 0.85rem;
  border-radius: 30px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.admin-form-container {
  max-width: 480px;
  margin: 2rem auto;
}

.form-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.form-icon {
  width: 56px;
  height: 56px;
  background: var(--primary-dim);
  color: var(--primary);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.form-header h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.form-header p {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-group-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

/* Modals Overlay & Content */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  width: 100%;
  max-width: 600px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-glass);
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

#form-athlete, #form-color, #form-sport {
  padding: 1.5rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

@media (max-width: 576px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-glass);
}

/* Radio groups styling */
.radio-group-container {
  display: flex;
  gap: 1.5rem;
  padding: 0.65rem 0;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.radio-label input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Color Picker input customize */
.color-picker-wrapper {
  display: flex;
  gap: 0.5rem;
}

.color-picker-wrapper input[type="color"] {
  border: none;
  width: 50px;
  height: 42px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  background: transparent;
}

/* Utilities classes */
.hide {
  display: none !important;
}

.text-gold { color: var(--gold); }
.text-indigo { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.bg-success-dim { background: var(--success-dim); }

.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Footer layout */
.app-footer-bar {
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-glass);
  margin-top: auto;
}

/* Animations */
.animate-fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

.animate-zoom-in {
  animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
