/* ===== Baseball League Manager — Complete Design System ===== */

/* --- CSS Custom Properties --- */
:root {
  /* Sidebar */
  --sidebar-bg: #1e1b2e;
  --sidebar-hover: #2a2640;
  --sidebar-active: #363258;
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 60px;

  /* Content */
  --bg: #f4f6fa;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);

  /* Accent */
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #dbeafe;
  --red: #dc2626;
  --green: #16a34a;
  --orange: #ea580c;
  --yellow: #ca8a04;
  --purple: #9333ea;

  /* Text */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-sidebar: #c7c2d8;
  --text-sidebar-heading: #8b83a0;

  /* Borders */
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* Baseball themed */
  --baseball-brown: #8B4513;
  --baseball-seam: #dc2626;

  /* Sizing */
  --header-height: 56px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
}

/* --- Reset & Base --- */
*,*::before,*::after{box-sizing:border-box}
html{font-size:16px;scroll-behavior:smooth}
body{
  margin:0;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;
  background:var(--bg);
  color:var(--text-primary);
  line-height:1.6;
  display:flex;
  min-height:100vh;
}
a{color:var(--blue);text-decoration:none}
a:hover{text-decoration:underline}
ul,ol{padding-left:1.25rem}
img{max-width:100%}
h1,h2,h3,h4,h5,h6{margin-top:0;color:var(--text-primary);font-weight:600;line-height:1.3}
h1{font-size:1.5rem}
h2{font-size:1.25rem}
h3{font-size:1.125rem}
p{margin:0 0 0.75rem}

/* --- Layout --- */
.app-layout{display:flex;width:100%;min-height:100vh}

/* Sidebar */
.sidebar{
  width:var(--sidebar-width);
  background:var(--sidebar-bg);
  display:flex;
  flex-direction:column;
  position:fixed;
  top:0;
  left:0;
  bottom:0;
  z-index:100;
  transition:width 0.25s ease,transform 0.25s ease;
  overflow-y:auto;
  overflow-x:hidden;
}
.sidebar-brand{
  display:flex;
  align-items:center;
  gap:0.625rem;
  padding:1rem 1.25rem;
  color:#fff;
  font-weight:700;
  font-size:1.1rem;
  border-bottom:1px solid rgba(255,255,255,0.06);
  min-height:var(--header-height);
}
.sidebar-brand .logo-icon{font-size:1.5rem}
.sidebar-brand span{white-space:nowrap}

.sidebar-nav{padding:0.5rem 0;flex:1}
.sidebar-section{
  padding:0.5rem 1.25rem 0.25rem;
  font-size:0.7rem;
  text-transform:uppercase;
  letter-spacing:0.05em;
  color:var(--text-sidebar-heading);
  font-weight:600;
}
.sidebar-nav a{
  display:flex;
  align-items:center;
  gap:0.75rem;
  padding:0.55rem 1.25rem;
  color:var(--text-sidebar);
  font-size:0.875rem;
  transition:all 0.15s ease;
  border-left:3px solid transparent;
  text-decoration:none;
}
.sidebar-nav a:hover{
  background:var(--sidebar-hover);
  color:#fff;
  text-decoration:none;
}
.sidebar-nav a.active{
  background:var(--sidebar-active);
  border-left-color:var(--blue);
  color:#fff;
}
.sidebar-nav a .nav-icon{width:20px;text-align:center;font-size:1rem}
.sidebar-nav a .nav-label{white-space:nowrap}

.sidebar-footer{
  padding:0.75rem 1.25rem;
  border-top:1px solid rgba(255,255,255,0.06);
}
.sidebar-footer .user-info{
  display:flex;
  align-items:center;
  gap:0.625rem;
  color:var(--text-sidebar);
  font-size:0.8rem;
}
.sidebar-footer .user-avatar{
  width:32px;height:32px;border-radius:50%;
  background:var(--blue);
  display:flex;align-items:center;justify-content:center;
  color:#fff;font-weight:700;font-size:0.85rem;
}
.sidebar-footer .logout-btn{
  margin-top:0.5rem;
  font-size:0.75rem;
  color:var(--text-sidebar-heading);
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  gap:0.375rem;
  padding:0.25rem 0;
  border:none;
  background:none;
}
.sidebar-footer .logout-btn:hover{color:var(--red)}

/* Mobile hamburger */
.sidebar-toggle{
  display:none;
  position:fixed;
  top:0.625rem;
  left:0.625rem;
  z-index:200;
  background:var(--sidebar-bg);
  color:#fff;
  border:none;
  border-radius:var(--radius-sm);
  padding:0.5rem 0.625rem;
  font-size:1.25rem;
  cursor:pointer;
  line-height:1;
}
.sidebar-overlay{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.4);
  z-index:99;
}

/* Main content area */
.main-content{
  flex:1;
  margin-left:var(--sidebar-width);
  min-height:100vh;
  transition:margin-left 0.25s ease;
}
.page-header{
  background:var(--card-bg);
  padding:1rem 1.5rem;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  min-height:var(--header-height);
  position:sticky;
  top:0;
  z-index:50;
}
.page-header h1{margin:0;font-size:1.25rem;display:flex;align-items:center;gap:0.5rem}
.page-header .header-actions{display:flex;gap:0.5rem;align-items:center}
.page-body{padding:1.5rem;max-width:1400px}

/* Mobile responsiveness */
@media(max-width:768px){
  .sidebar{
    transform:translateX(-100%);
    width:260px;
  }
  .sidebar.open{transform:translateX(0)}
  .sidebar-overlay.open{display:block}
  .sidebar-toggle{display:block}
  .main-content{margin-left:0}
  .page-body{padding:1rem}
  .page-header{padding:0.75rem 1rem;padding-left:3.25rem}
}

/* --- Cards --- */
.card{
  background:var(--card-bg);
  border-radius:var(--radius-lg);
  box-shadow:var(--card-shadow);
  border:1px solid var(--border);
  overflow:hidden;
}
.card-header{
  padding:1rem 1.25rem;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.card-header h2,.card-header h3{margin:0}
.card-body{padding:1.25rem}
.card-footer{
  padding:0.75rem 1.25rem;
  border-top:1px solid var(--border);
  background:var(--border-light);
  font-size:0.85rem;
  color:var(--text-secondary);
}

/* Stat cards (dashboard) */
.stat-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:1rem;margin-bottom:1.5rem}
.stat-card{
  background:var(--card-bg);
  border-radius:var(--radius-lg);
  box-shadow:var(--card-shadow);
  border:1px solid var(--border);
  padding:1.25rem;
  display:flex;
  align-items:center;
  gap:1rem;
}
.stat-card .stat-icon{
  width:48px;height:48px;border-radius:var(--radius);
  display:flex;align-items:center;justify-content:center;
  font-size:1.5rem;
  flex-shrink:0;
}
.stat-card .stat-icon.blue{background:var(--blue-light);color:var(--blue)}
.stat-card .stat-icon.green{background:#dcfce7;color:var(--green)}
.stat-card .stat-icon.orange{background:#ffedd5;color:var(--orange)}
.stat-card .stat-icon.purple{background:#f3e8ff;color:var(--purple)}
.stat-card .stat-icon.red{background:#fee2e2;color:var(--red)}
.stat-card .stat-info h3{margin:0;font-size:0.8rem;color:var(--text-secondary);font-weight:500}
.stat-card .stat-info .stat-value{margin:0;font-size:1.5rem;font-weight:700;color:var(--text-primary)}
.stat-card .stat-info .stat-delta{font-size:0.75rem;color:var(--green)}

/* --- Buttons --- */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:0.375rem;
  padding:0.5rem 1rem;
  border-radius:var(--radius-sm);
  font-size:0.875rem;
  font-weight:500;
  cursor:pointer;
  transition:all 0.15s ease;
  border:1px solid transparent;
  line-height:1.4;
  white-space:nowrap;
  text-decoration:none;
}
.btn:focus{outline:2px solid var(--blue);outline-offset:2px}
.btn-primary{background:var(--blue);color:#fff}
.btn-primary:hover{background:var(--blue-dark)}
.btn-secondary{background:var(--card-bg);color:var(--text-primary);border-color:var(--border)}
.btn-secondary:hover{background:var(--border-light);border-color:var(--text-muted)}
.btn-danger{background:var(--red);color:#fff}
.btn-danger:hover{background:#b91c1c}
.btn-success{background:var(--green);color:#fff}
.btn-success:hover{background:#15803d}
.btn-warning{background:var(--orange);color:#fff}
.btn-warning:hover{background:#c2410c}
.btn-ghost{background:transparent;color:var(--text-secondary)}
.btn-ghost:hover{background:var(--border-light);color:var(--text-primary)}
.btn-sm{padding:0.3rem 0.625rem;font-size:0.8rem}
.btn-lg{padding:0.75rem 1.5rem;font-size:1rem}
.btn-icon{padding:0.5rem;min-width:36px}

/* --- Forms --- */
.form-group{margin-bottom:1rem}
.form-group label{display:block;font-size:0.85rem;font-weight:500;margin-bottom:0.375rem;color:var(--text-primary)}
.form-control{
  width:100%;
  padding:0.5rem 0.75rem;
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  font-size:0.875rem;
  color:var(--text-primary);
  background:var(--card-bg);
  transition:border-color 0.15s;
  line-height:1.5;
}
.form-control:focus{
  outline:none;
  border-color:var(--blue);
  box-shadow:0 0 0 3px rgba(37,99,235,0.1);
}
.form-control::placeholder{color:var(--text-muted)}
select.form-control{cursor:pointer}
textarea.form-control{resize:vertical;min-height:80px}

.form-row{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.form-actions{
  display:flex;gap:0.5rem;
  justify-content:flex-end;
  margin-top:1.5rem;
  padding-top:1rem;
  border-top:1px solid var(--border);
}

/* --- Tables --- */
.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:0.875rem}
thead{background:var(--border-light)}
th{
  padding:0.625rem 0.75rem;
  text-align:left;
  font-weight:600;
  font-size:0.8rem;
  text-transform:uppercase;
  letter-spacing:0.03em;
  color:var(--text-secondary);
  border-bottom:2px solid var(--border);
  white-space:nowrap;
}
td{
  padding:0.625rem 0.75rem;
  border-bottom:1px solid var(--border);
  vertical-align:middle;
}
tr:hover{background:var(--border-light)}
tr:last-child td{border-bottom:none}

/* --- Badges / Tags --- */
.badge{
  display:inline-flex;
  align-items:center;
  gap:0.25rem;
  padding:0.125rem 0.5rem;
  border-radius:999px;
  font-size:0.75rem;
  font-weight:500;
}
.badge-blue{background:var(--blue-light);color:var(--blue)}
.badge-green{background:#dcfce7;color:var(--green)}
.badge-red{background:#fee2e2;color:var(--red)}
.badge-orange{background:#ffedd5;color:var(--orange)}
.badge-purple{background:#f3e8ff;color:var(--purple)}
.badge-gray{background:var(--border-light);color:var(--text-secondary)}

.player-avatar{
  width:32px;height:32px;border-radius:50%;
  display:inline-flex;align-items:center;justify-content:center;
  font-size:0.8rem;font-weight:700;color:#fff;
  flex-shrink:0;
}

/* --- Grid Layouts --- */
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.grid-3{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:1rem}
.grid-4{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:1rem}

/* --- Modals --- */
.modal-overlay{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.5);
  z-index:1000;
  align-items:center;
  justify-content:center;
  padding:1rem;
}
.modal-overlay.open{display:flex}
.modal{
  background:var(--card-bg);
  border-radius:var(--radius-lg);
  width:100%;
  max-width:560px;
  max-height:85vh;
  overflow-y:auto;
  box-shadow:0 20px 60px rgba(0,0,0,0.2);
  animation:modalIn 0.2s ease;
}
.modal-sm{max-width:420px}
.modal-lg{max-width:720px}
.modal-header{
  padding:1rem 1.25rem;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.modal-header h2{margin:0;font-size:1.125rem}
.modal-close{
  background:none;border:none;
  font-size:1.25rem;cursor:pointer;
  color:var(--text-muted);padding:0.25rem;line-height:1;
}
.modal-close:hover{color:var(--text-primary)}
.modal-body{padding:1.25rem}
.modal-footer{
  padding:0.75rem 1.25rem;
  border-top:1px solid var(--border);
  display:flex;justify-content:flex-end;gap:0.5rem;
}
@keyframes modalIn{from{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}

/* --- Loading & Alerts --- */
.loading-dots{display:inline-flex;gap:4px}
.loading-dots span{
  width:8px;height:8px;border-radius:50%;
  background:var(--text-muted);animation:dance 0.6s infinite alternate;
}
.loading-dots span:nth-child(2){animation-delay:0.2s}
.loading-dots span:nth-child(3){animation-delay:0.4s}
@keyframes dance{from{opacity:0.3;transform:translateY(0)}to{opacity:1;transform:translateY(-4px)}}

.alert{
  padding:0.75rem 1rem;
  border-radius:var(--radius-sm);
  font-size:0.875rem;
  margin-bottom:1rem;
  display:flex;
  align-items:center;
  gap:0.5rem;
}
.alert-info{background:var(--blue-light);color:var(--blue);border:1px solid #bfdbfe}
.alert-success{background:#dcfce7;color:var(--green);border:1px solid #bbf7d0}
.alert-danger{background:#fee2e2;color:var(--red);border:1px solid #fecaca}
.alert-warning{background:#ffedd5;color:var(--orange);border:1px solid #fed7aa}

.empty-state{
  text-align:center;
  padding:3rem 1rem;
  color:var(--text-muted);
}
.empty-state .empty-icon{font-size:3rem;margin-bottom:1rem;opacity:0.5}
.empty-state h3{color:var(--text-secondary);margin-bottom:0.5rem}

/* --- Toast notifications --- */
.toast-container{
  position:fixed;
  top:1rem;
  right:1rem;
  z-index:9999;
  display:flex;
  flex-direction:column;
  gap:0.5rem;
  pointer-events:none;
}
.toast{
  padding:0.75rem 1rem;
  border-radius:var(--radius-sm);
  font-size:0.875rem;
  box-shadow:0 4px 12px rgba(0,0,0,0.15);
  display:flex;
  align-items:center;
  gap:0.5rem;
  pointer-events:auto;
  animation:slideIn 0.2s ease;
  max-width:380px;
}
.toast-success{background:var(--green);color:#fff}
.toast-error{background:var(--red);color:#fff}
.toast-info{background:var(--blue);color:#fff}
@keyframes slideIn{from{transform:translateX(100%);opacity:0}to{transform:translateX(0);opacity:1}}

/* --- Evaluation Grid --- */
.eval-grid{overflow-x:auto}
.eval-grid table{font-size:0.8rem}
.eval-grid th,.eval-grid td{padding:0.375rem;text-align:center;min-width:48px}
.eval-grid td input[type="number"]{
  width:48px;padding:0.25rem;
  border:1px solid var(--border);
  border-radius:4px;
  text-align:center;
  font-size:0.8rem;
}
.eval-grid td input:focus{border-color:var(--blue);outline:none}

/* --- Team Cards --- */
.team-card{background:var(--card-bg);border-radius:var(--radius-lg);border:1px solid var(--border);overflow:hidden}
.team-card-header{
  padding:0.75rem 1rem;
  font-weight:600;
  display:flex;
  align-items:center;
  gap:0.5rem;
}
.team-card-body{padding:1rem}
.team-card-body .player-chip{
  display:flex;align-items:center;gap:0.5rem;
  padding:0.375rem 0.625rem;
  margin-bottom:0.375rem;
  background:var(--border-light);
  border-radius:var(--radius-sm);
  font-size:0.85rem;
}
.team-a .team-card-header{background:#dcfce7;color:var(--green)}
.team-b .team-card-header{background:#dbeafe;color:var(--blue)}

/* --- Pitch Count --- */
.pitch-bar{
  height:8px;
  background:var(--border-light);
  border-radius:4px;
  overflow:hidden;
  margin-top:0.25rem;
}
.pitch-bar-fill{
  height:100%;
  border-radius:4px;
  transition:width 0.3s ease;
}
.pitch-bar-fill.safe{background:var(--green)}
.pitch-bar-fill.caution{background:var(--orange)}
.pitch-bar-fill.danger{background:var(--red)}

/* --- Lineup / Drag & Drop --- */
.lineup-position{
  background:var(--card-bg);
  border:2px dashed var(--border);
  border-radius:var(--radius);
  padding:0.75rem;
  margin-bottom:0.5rem;
  min-height:48px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  transition:all 0.15s;
}
.lineup-position.dragover{border-color:var(--blue);background:var(--blue-light)}
.lineup-position.filled{border-style:solid;border-color:var(--border)}
.lineup-player{
  display:flex;align-items:center;gap:0.5rem;
  padding:0.375rem 0.75rem;
  background:var(--blue-light);
  border-radius:var(--radius-sm);
  font-size:0.85rem;
  cursor:grab;
}
.lineup-player:active{cursor:grabbing}

/* --- Login Page --- */
.login-page{
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:100vh;
  width:100%;
  background:linear-gradient(135deg,#1e1b2e 0%,#2a2640 50%,#1a1a2e 100%);
}
.login-card{
  background:var(--card-bg);
  padding:2.5rem 2rem;
  border-radius:var(--radius-lg);
  max-width:420px;
  width:100%;
  text-align:center;
  box-shadow:0 20px 60px rgba(0,0,0,0.3);
}
.login-card .login-logo{font-size:3rem;margin-bottom:1rem}
.login-card h1{font-size:1.5rem;margin-bottom:0.25rem}
.login-card .login-sub{color:var(--text-secondary);margin-bottom:1.5rem;font-size:0.9rem}
.login-card .btn{width:100%;justify-content:center;padding:0.75rem;font-size:1rem}

/* --- Player detail row --- */
.detail-row{
  display:flex;
  margin-bottom:0.5rem;
  font-size:0.875rem;
}
.detail-label{width:140px;color:var(--text-secondary);flex-shrink:0}
.detail-value{color:var(--text-primary)}

/* --- Filter bar --- */
.filter-bar{
  display:flex;
  gap:0.75rem;
  margin-bottom:1rem;
  flex-wrap:wrap;
  align-items:center;
}
.filter-bar .form-control{width:auto;min-width:140px}

/* --- Pills / tabs --- */
.tabs{
  display:flex;
  gap:0;
  margin-bottom:1rem;
  border-bottom:2px solid var(--border);
}
.tab{
  padding:0.5rem 1rem;
  font-size:0.85rem;
  font-weight:500;
  cursor:pointer;
  border-bottom:2px solid transparent;
  margin-bottom:-2px;
  color:var(--text-secondary);
  transition:all 0.15s;
}
.tab:hover{color:var(--text-primary)}
.tab.active{color:var(--blue);border-bottom-color:var(--blue)}

/* --- Responsive overrides --- */
@media(max-width:640px){
  .form-row{grid-template-columns:1fr}
  .grid-2{grid-template-columns:1fr}
  .stat-cards{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}
  .filter-bar .form-control{min-width:100%}
  .tabs{overflow-x:auto}
  .modal{padding:1rem;max-width:100%}
  .hide-mobile{display:none!important}
  .page-header .header-actions{gap:0.25rem}
  .page-header .header-actions .btn{padding:0.4rem 0.625rem;font-size:0.8rem}
}

/* --- Utilities --- */
.text-center{text-align:center}
.text-right{text-align:right}
.text-muted{color:var(--text-muted)}
.text-secondary{color:var(--text-secondary)}
.text-danger{color:var(--red)}
.text-success{color:var(--green)}
.mt-0{margin-top:0}
.mt-1{margin-top:0.5rem}
.mt-2{margin-top:1rem}
.mt-3{margin-top:1.5rem}
.mb-1{margin-bottom:0.5rem}
.mb-2{margin-bottom:1rem}
.mb-3{margin-bottom:1.5rem}
.flex{display:flex}
.flex-center{align-items:center}
.flex-between{display:flex;justify-content:space-between;align-items:center}
.flex-gap{gap:0.5rem}
.flex-wrap{flex-wrap:wrap}
.gap-sm{gap:0.5rem}
.gap-md{gap:1rem}
.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.w-full{width:100%}
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}

/* --- Print styles --- */
@media print{
  .sidebar{display:none}
  .main-content{margin-left:0}
  .page-header{display:none}
  .btn,.no-print{display:none!important}
}
