/* Ensure proper scrolling on mobile and PWA */
html {
  height: 100%;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* PWA-specific fixes */
  position: relative;
  overscroll-behavior: none;
}

/* PWA-specific scrolling fixes */
@media (display-mode: standalone) {
  html {
    height: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
  }
  
  body {
    height: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    position: relative;
  }
  
  .dashboard {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
  }
}

/* ============================================
   GLOBAL THEME SYSTEM
   ============================================ */

/* CSS Variables for Theme System */
/* Blue Theme (Default) */
:root,
[data-theme="blue"] {
  --primary-color: #007bff;
  --secondary-color: #0056b3;
  --accent-color: #007bff;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #28a745;
  --info-color: #17a2b8;
  
  --bg-primary: linear-gradient(135deg, #f8fafc 0%, #e0e7ef 100%);
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f4f8;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #e2e8f0;
  --shadow: 0 2px 4px rgba(0,123,255,0.1);
  --shadow-color: rgba(0,123,255,0.1);
  --shadow-hover: 0 4px 8px rgba(0,123,255,0.15);
  --transition: all 0.3s ease;
}

/* Pink Theme */
[data-theme="pink"] {
  --primary-color: #ff4b91;
  --secondary-color: #ff6b9d;
  --accent-color: #ff4b91;
  --danger-color: #ff6b6b;
  --warning-color: #ffd93d;
  --success-color: #51cf66;
  --info-color: #ff9ec5;
  
  --bg-primary: linear-gradient(135deg, #fffdee 0%, #fff5f5 100%);
  --bg-secondary: #ffffff;
  --bg-card: #fff5f5;
  --bg-hover: #ffeef0;
  
  --text: #333333;
  --text-color: #333333;
  --text-muted: #666666;
  --text-inverse: #ffffff;
  
  --border-color: #ffd6e0;
  --shadow: 0 2px 4px rgba(255,75,145,0.2);
  --shadow-color: rgba(255,75,145,0.2);
  --shadow-hover: 0 4px 8px rgba(255,75,145,0.3);
  --transition: all 0.3s ease;
}

/* Green Theme */
[data-theme="green"] {
  --primary-color: #28a745;
  --secondary-color: #20c997;
  --accent-color: #28a745;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #28a745;
  --info-color: #17a2b8;
  
  --bg-primary: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  --bg-secondary: #ffffff;
  --bg-card: #f0fdf4;
  --bg-hover: #dcfce7;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #bbf7d0;
  --shadow: 0 2px 4px rgba(40,167,69,0.15);
  --shadow-color: rgba(40,167,69,0.15);
  --shadow-hover: 0 4px 8px rgba(40,167,69,0.25);
  --transition: all 0.3s ease;
}

/* Purple Theme */
[data-theme="purple"] {
  --primary-color: #6f42c1;
  --secondary-color: #8b5cf6;
  --accent-color: #6f42c1;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #28a745;
  --info-color: #a78bfa;
  
  --bg-primary: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
  --bg-secondary: #ffffff;
  --bg-card: #faf5ff;
  --bg-hover: #f3e8ff;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #e9d5ff;
  --shadow: 0 2px 4px rgba(111,66,193,0.15);
  --shadow-color: rgba(111,66,193,0.15);
  --shadow-hover: 0 4px 8px rgba(111,66,193,0.25);
  --transition: all 0.3s ease;
}

/* Orange Theme */
[data-theme="orange"] {
  --primary-color: #fd7e14;
  --secondary-color: #ff9500;
  --accent-color: #fd7e14;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #28a745;
  --info-color: #ffb84d;
  
  --bg-primary: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  --bg-secondary: #ffffff;
  --bg-card: #fff7ed;
  --bg-hover: #ffedd5;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #fed7aa;
  --shadow: 0 2px 4px rgba(253,126,20,0.15);
  --shadow-color: rgba(253,126,20,0.15);
  --shadow-hover: 0 4px 8px rgba(253,126,20,0.25);
  --transition: all 0.3s ease;
}

/* Teal Theme */
[data-theme="teal"] {
  --primary-color: #20c997;
  --secondary-color: #14b8a6;
  --accent-color: #20c997;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #20c997;
  --info-color: #5eead4;
  
  --bg-primary: linear-gradient(135deg, #f0fdfa 0%, #ccfbf1 100%);
  --bg-secondary: #ffffff;
  --bg-card: #f0fdfa;
  --bg-hover: #ccfbf1;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #99f6e4;
  --shadow: 0 2px 4px rgba(32,201,151,0.15);
  --shadow-color: rgba(32,201,151,0.15);
  --shadow-hover: 0 4px 8px rgba(32,201,151,0.25);
  --transition: all 0.3s ease;
}

/* Red Theme */
[data-theme="red"] {
  --primary-color: #dc3545;
  --secondary-color: #c82333;
  --accent-color: #dc3545;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --success-color: #28a745;
  --info-color: #e4606d;
  
  --bg-primary: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  --bg-secondary: #ffffff;
  --bg-card: #fef2f2;
  --bg-hover: #fee2e2;
  
  --text: #1e293b;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #fecaca;
  --shadow: 0 2px 4px rgba(220,53,69,0.15);
  --shadow-color: rgba(220,53,69,0.15);
  --shadow-hover: 0 4px 8px rgba(220,53,69,0.25);
  --transition: all 0.3s ease;
}

/* Blue Dark Theme (for auto mode) */
[data-theme="blue-dark"] {
  --primary-color: #4da3ff;
  --secondary-color: #20c997;
  --accent-color: #4da3ff;
  --danger-color: #ff6b6b;
  --warning-color: #ffd93d;
  --success-color: #51cf66;
  --info-color: #74c0fc;
  
  --bg-primary: linear-gradient(135deg, #1a1a1a 0%, #232946 100%);
  --bg-secondary: #2b2b2b;
  --bg-card: #2b2b2b;
  --bg-hover: #3a3a3a;
  
  --text: #f4f4f9;
  --text-color: #f4f4f9;
  --text-muted: #a0a0a0;
  --text-inverse: #1e293b;
  
  --border-color: #404040;
  --shadow: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-color: rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 8px rgba(0,0,0,0.4);
  --transition: all 0.3s ease;
}

/* Light mode (default) */
body {
  font-family: 'Poppins', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  margin: 0;
  padding: 0;
  letter-spacing: 0.01em;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 1rem;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  h1 {
    font-size: 1.5em;
  }
  .container {
    width: 100%;
    padding: 1rem;
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  body {
    padding: 5px;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  h1 {
    font-size: 1.2em;
  }
  .container {
    padding: 5px;
    justify-content: flex-start;
  }
}

/* Flexible Layouts */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 1200px;
  margin: auto;
}

/* Responsive Images */
img {
  max-width: 100%;
  height: auto;
}

/* Base styles - Use theme variables */
:root {
  /* Map old variables to new theme system */
  --primary: var(--primary-color);
  --secondary: var(--secondary-color);
  --success: var(--success-color);
  --warning: var(--warning-color);
  --danger: var(--danger-color);
  --background: var(--bg-secondary);
  --card: var(--bg-card);
  --text: var(--text-color);
  --muted: var(--text-muted);
  --shadow: var(--shadow);
  --radius: 1.25rem;
  --transition: var(--transition);
  
  /* Additional compatibility variables */
  --card-background: var(--bg-card);
  --text-color: var(--text);
}

/* Loading indicators */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Notifications */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 5px;
    background: var(--card-background);
    color: var(--text-color);
    box-shadow: var(--shadow);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    border-left: 4px solid var(--secondary-color);
}

.notification.error {
    border-left: 4px solid var(--danger-color);
}

.notification.warning {
    border-left: 4px solid var(--warning-color);
}

/* Form elements */
input, select, textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--bg-card);
    color: var(--text-color);
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* Cards */
.card, .dashboard-tile {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin: 10px;
  display: inline-block;
  min-width: 180px;
  font-weight: bold;
  border-left: 5px solid var(--primary-color);
  transition: var(--transition);
  color: var(--text-color);
}

.card:hover, .dashboard-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  background: var(--bg-hover);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--primary-color);
    color: white;
}

tr:hover {
    background: rgba(52, 152, 219, 0.1);
}

/* Responsive design */
@media (max-width: 768px) {
    .card {
        padding: 15px;
    }
    
    button {
        width: 100%;
        margin: 5px 0;
    }
    
    table {
        display: block;
        overflow-x: auto;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

/* Buttons */
button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  background: var(--primary-color);
  color: white;
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
}

button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin: 3rem auto;
  max-width: 1200px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-background);
  color: var(--text-color);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
  min-height: 200px;
}

.tile::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  opacity: 0.8;
}

.tile:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.tile-icon {
  font-size: 2.75rem;
  margin-bottom: 1.25rem;
  display: block;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.tile-title {
  font-size: 1.35rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.tile-description {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

.subtitle {
  font-size: 1.25rem;
  color: var(--text-muted);
  margin: 1rem 0 2rem;
  font-weight: 500;
  margin: 0.5rem 0;
  opacity: 0.8;
}

header h1 {
  font-size: 2.75rem;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.dashboard-tile h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-color);
}

.dashboard-tile p {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.recent-activity {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--card-background);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: 0 2px 4px var(--shadow-color);
}

.recent-activity h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-color);
}

#activityList {
  display: grid;
  gap: 1rem;
}

.dashboard {
  max-width: 1050px;
  margin: 0 auto;
  padding: 1.5rem 0.5rem 2rem 0.5rem;
  overflow-x: hidden;
}

header {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  border-radius: 1.5rem;
  box-shadow: 0 8px 32px rgba(37,99,235,0.10);
  padding: 1.2rem 2rem 1rem 2rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.3s;
}

.header-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

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

.control-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.control-btn:hover {
  background: rgba(255,255,255,0.25);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  color: var(--text-color);
  font-weight: 500;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin-bottom: 2rem;
}

.stat-tile {
  background: var(--bg-card);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
  padding: 1.2rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  border-left: 5px solid var(--primary);
  min-height: 90px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(4px);
  color: var(--text-color);
}
.stat-tile[data-type="success"] { border-left-color: var(--success); }
.stat-tile[data-type="warning"] { border-left-color: var(--warning); }
.stat-tile[data-type="danger"] { border-left-color: var(--danger); }
.stat-tile:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px) scale(1.015);
  background: var(--bg-hover);
}
.stat-icon {
  font-size: 1.7rem;
  color: var(--primary-color);
  background: var(--bg-hover);
  border-radius: 50%;
  padding: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.stat-content h3 {
  margin: 0 0 0.2rem 0;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}
.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin-bottom: 2.2rem;
}
.tool-card {
  background: var(--bg-card);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text-color);
  padding: 1.2rem 1.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: var(--transition);
  border: none;
  min-height: 120px;
  overflow: hidden;
  backdrop-filter: blur(4px);
}
.tool-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px) scale(1.015);
  background: var(--bg-hover);
}
.tool-icon {
  font-size: 1.5rem;
  margin-bottom: 0.7rem;
  color: var(--primary-color);
  background: var(--bg-hover);
  border-radius: 50%;
  padding: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.tool-card h3 {
  margin: 0 0 0.2rem 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.tool-card p {
  margin: 0;
  font-size: 0.98rem;
  color: var(--muted);
}

/* Microinteractions */
.control-btn, .tool-card, .stat-tile {
  transition: box-shadow 0.2s, transform 0.2s, background 0.2s;
}

/* Responsive Tweaks */
@media (max-width: 900px) {
  .dashboard-stats, .tools-grid {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 600px) {
  .dashboard {
    padding: 0.5rem 0.1rem;
  }
  header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem 0.7rem 0.7rem 0.7rem;
  }
  .dashboard-stats, .tools-grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }
}

.session-timeout {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--card);
  padding: 1.25rem 2rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(37,99,235,0.12);
  z-index: 1000;
  border: 1px solid #e0e7ff;
}
.timeout-content {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.timeout-content p {
  margin: 0;
  font-weight: 500;
}
