/* -------------------------------------------------------------
 * IPL Performance Tracker - Core Design System & Layout
 * Theme: Premium Glassmorphism and Neon Accents
 * ------------------------------------------------------------- */

:root {
  /* Colors - Premium Light Theme */
  --bg-primary: #f4f6fa;
  --bg-secondary: #ffffff;
  --bg-panel: rgba(255, 255, 255, 0.85);
  --bg-card: rgba(255, 255, 255, 0.65);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-glow: rgba(108, 92, 231, 0.1);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #6c5ce7;
  --accent-primary-rgb: 108, 92, 231;
  --accent-secondary: #0ea5e9;
  --accent-success: #10b981;
  --accent-success-rgb: 16, 185, 129;
  --accent-danger: #ef4444;
  --accent-danger-rgb: 239, 68, 68;
  --accent-warning: #f59e0b;
  --accent-gold: #d97706;

  /* Font Families */
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;

  /* Borders & Shadows */
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-main: 0 8px 30px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 15px rgba(108, 92, 231, 0.12);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
  height: 100vh;
}

body.light-theme {
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(108, 92, 231, 0.06) 0%, transparent 45%),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, 0.06) 0%, transparent 45%);
  background-attachment: fixed;
}

body.dark-theme {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-panel: rgba(30, 41, 59, 0.85);
  --bg-card: rgba(30, 41, 59, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(108, 92, 231, 0.2);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  --accent-primary: #a29bfe;
  --accent-primary-rgb: 162, 155, 254;
  --accent-secondary: #38bdf8;

  background-image: 
    radial-gradient(circle at 10% 20%, rgba(108, 92, 231, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, 0.12) 0%, transparent 45%);
  background-attachment: fixed;
}

/* Theme Switching Smooth Transitions */
body,
.top-header,
.card,
.form-control,
.btn-secondary,
.modal-card,
table,
th,
td {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Dark Theme specific component overrides */
body.dark-theme .btn-secondary {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-color: var(--border-color);
}

body.dark-theme .btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.12);
}


/* Helper Utilities */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }

/* Grid Layouts */
.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

/* Prevent grid items from stretching the container width when contents (like tables) overflow */
.grid-1 > *, .grid-2 > *, .grid-3 > *, .grid-4 > * {
  min-width: 0;
}

/* Responsive Grid Adaptation taking the 260px sidebar into account */
@media (max-width: 1200px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: 1fr; /* Forms and tables stack for cleaner breathing room */
  }
}

@media (max-width: 992px) {
  .grid-4, .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Sidebar hidden below 768px, giving more width to content */
@media (max-width: 768px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Extra small / Phone viewports */
@media (max-width: 576px) {
  .grid-1, .grid-2, .grid-3, .grid-4,
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 768px) {
  body { font-size: 14px; }
}
@media (max-width: 576px) {
  body { font-size: 13px; }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Main Layout Shell */
.app-layout {
  display: grid;
  grid-template-columns: 1fr; /* Full content width by default */
  height: 100vh;
  width: 100vw;
}

/* Sidebar Navigation Drawer (Dynamic Slide-out on all screen sizes) */
.sidebar {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  transform: translateX(-100%);
  padding: calc(1.5rem + env(safe-area-inset-top, 0px)) 0 calc(1.5rem + env(safe-area-inset-bottom, 0px)) 0;
  z-index: 1000;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.15);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar.show {
  transform: translateX(0);
}

.sidebar-header {
  margin-bottom: 2rem;
  padding: 0 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

.logo-text {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-primary);
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-sub {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-top: -4px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
  padding: 0 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all 0.2s ease;
  cursor: pointer;
  background: transparent;
  width: 100%;
  box-sizing: border-box;
}

.nav-item:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
  color: var(--text-primary);
  background-color: rgba(125, 95, 255, 0.15);
  border-color: rgba(125, 95, 255, 0.3);
  box-shadow: 0 0 10px rgba(125, 95, 255, 0.05);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

.nav-item.active svg {
  opacity: 1;
  color: var(--accent-primary);
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 1.25rem 1.5rem calc(0.25rem + env(safe-area-inset-bottom, 0px)) 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 38px;
  height: 38px;
  background-color: var(--accent-primary);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-heading);
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Workspace Container */
.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.top-header {
  height: calc(70px + env(safe-area-inset-top, 0px));
  min-height: calc(70px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) 2rem 0 2rem;
  background-color: var(--bg-panel);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  margin-right: 1rem;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.date-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.date-selector label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.content-container {
  padding: 2rem;
  flex: 1;
}

@media (max-width: 768px) {
  .top-header {
    height: auto !important;
    min-height: auto !important;
    padding: calc(env(safe-area-inset-top, 0px) + 0.75rem) 1rem 0.75rem 1rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }
  .header-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    gap: 0.5rem;
  }
  .header-right {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .date-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
  }
  .date-selector input {
    flex: 1;
    min-width: 100px;
    width: 100%;
  }
  .page-title {
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 48px);
  }
  .content-container {
    padding: 1rem 1rem calc(2.5rem + env(safe-area-inset-bottom, 0px)) 1rem;
  }

  /* Block layout for overflow: visible tables inside main view content on mobile */
  #view-content .table-wrapper[style*="overflow: visible"],
  #view-content .table-wrapper[style*="overflow: visible"] table,
  #view-content .table-wrapper[style*="overflow: visible"] thead,
  #view-content .table-wrapper[style*="overflow: visible"] tbody,
  #view-content .table-wrapper[style*="overflow: visible"] tr,
  #view-content .table-wrapper[style*="overflow: visible"] th,
  #view-content .table-wrapper[style*="overflow: visible"] td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box;
  }
  
  #view-content .table-wrapper[style*="overflow: visible"] thead {
    display: none !important;
  }
  
  #view-content .table-wrapper[style*="overflow: visible"] tr {
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    background: var(--bg-panel);
    box-shadow: var(--shadow-sm);
  }
  
  #view-content .table-wrapper[style*="overflow: visible"] td {
    border-bottom: none !important;
    padding: 0.35rem 0 !important;
  }
  
  #view-content .table-wrapper[style*="overflow: visible"] td strong {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--accent-secondary);
    font-size: 0.95rem;
  }
  

  .sidebar-nav {
    flex: 1 0 auto;
    overflow-y: visible;
    padding: 0 1.5rem;
    width: 100%;
    box-sizing: border-box;
  }
  .sidebar-footer {
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom, 0px)) 1.5rem;
    width: 100%;
    box-sizing: border-box;
  }
}

@media (max-width: 576px) {
  .hidden-xs {
    display: none !important;
  }
  .modal {
    padding: 0.75rem;
  }
  .modal-card {
    max-height: 92vh;
  }
  .modal-header {
    padding: 1rem;
  }
  .modal-body {
    padding: 1rem;
  }
  .card {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
  }
}

/* Login Panel */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-primary);
  z-index: 1000;
  padding: 1rem;
}

@media (max-width: 480px) {
  .login-overlay {
    align-items: flex-start; /* Prevent vertical centering clipping on short keyboard viewports */
    overflow-y: auto;
    padding: 2rem 1rem;
    -webkit-overflow-scrolling: touch;
  }
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(15px);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-main);
  animation: fadeIn 0.4s ease-out;
}

@media (max-width: 480px) {
  .login-card {
    padding: 1.5rem 1.25rem;
    margin-top: 1rem;
    margin-bottom: 1rem;
  }
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.logo-badge {
  display: inline-block;
  background: var(--accent-primary);
  color: #ffffff;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.25rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-glow);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.login-header h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Modal Popup Window */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1.5rem;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  box-shadow: var(--shadow-main);
  position: relative;
  z-index: 10;
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.15s ease;
}

.modal-close:hover {
  color: var(--accent-danger);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

/* Keyframe Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Robust selection prevention for Login Overlay to avoid browser highlighting on rapid clicking/tapping */
.login-overlay, .login-overlay * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
}

.login-overlay input,
.login-overlay select,
.login-overlay textarea,
.login-overlay input *,
.login-overlay select *,
.login-overlay textarea * {
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
}
