/* ==========================================================================
   Ranimate Style Sheet - Fixed Layout with Mobile Top/Bottom Locking
   ========================================================================== */

/* --- 1. ROOT VARIABLES & GLOBAL RESET --- */
:root {
  --primary-orange: #ff5722;
  --primary-blue: #0066cc;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height to account for mobile browser bars */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  overflow: hidden; /* Prevents outer window body scrolling; locks layout */
}

/* --- NEW! STYLE FOR INDEPENDANT AUTH --- */
/* Full-page centering container when logged out */
        .full-page-auth {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            width: 100vw;
            box-sizing: border-box;
        }
        .auth-card-container {
            background: #ffffff;
            padding: 32px;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            width: 100%;
            max-width: 400px;
            box-sizing: border-box;
        }
        .auth-tabs {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        .auth-tabs button {
            flex: 1;
            padding: 8px;
            cursor: pointer;
            border: 1px solid #cbd5e1;
            background: #f8fafc;
            border-radius: 6px;
            font-weight: 600;
        }
        .auth-form input {
            width: 100%;
            padding: 10px 12px;
            margin-bottom: 12px;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            box-sizing: border-box;
        }
        .auth-form .btn {
            width: 100%;
            padding: 10px;
            background-color: #3b82f6;
            color: white;
            border: none;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
        }
        .full-page-gpx {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            width: 100%;
            box-sizing: border-box;
        }

/* --- 2. BASE APP CONTAINER (DESKTOP FLEX LAYOUT) --- */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}


/* --- 3. LEFT MENU PANEL (NAVIGATION & LOGO) --- */
.menu-left {
  width: 240px;
  height: 100%;
  background-color: var(--card-bg);
  border-right: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.menu-left h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 15px 0 8px 0;
  color: var(--text-dark);
}

.menu-left ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-left li {
  margin-bottom: 6px;
}

.menu-left a {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.menu-left a:hover {
  background-color: #f1f5f9;
  color: var(--primary-blue);
}


/* --- 4. RIGHT MENU PANEL & #RACE-MODE-MENU (COMPARISON CONTROLS) ---
.menu-right {
  width: 280px;
  height: 100%;
  background-color: var(--card-bg);
  border-left: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
*/
/* Styling for the dynamic comparison mode container activated upon track selection */
#race-mode-menu {
  margin-top: 15px;
  display: none; /* Hidden by default until a track is selected */
}

#race-mode-menu hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 12px 0;
}

#race-mode-menu h4 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 10px 0;
  color: var(--text-dark);
}


/* --- 5. CENTRAL CONTENT PANEL (MAP & TRACK TABLE WORKSPACE) --- */
.content-panel {
  flex: 1;
  height: 100%;
  padding: 20px;
  overflow-y: auto; /* ONLY this center area scrolls independently */
  background-color: var(--bg-main);
}

.top-bar {
  margin-bottom: 16px;
}

.top-bar h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  color: var(--text-dark);
}


/* --- 6. CARDS, MAP & TRACK TABLE STYLING --- */
.card {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card h3 {
  margin-top: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
}

#map {
  width: 100%;
  height: 380px;
  border-radius: 8px;
  z-index: 1;
}

.track-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.track-table th, .track-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.track-table th {
  background-color: #f8fafc;
  color: var(--text-dark);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.track-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* Crucial for text ellipsis to work on table cells */
    font-family: inherit;
    font-size: 14px;
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.track-table th, 
.track-table td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid #e2e8f0;
}

.track-table th {
    background-color: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Row hover effect */
.track-table tbody tr:hover {
    background-color: #f8fafc;
}

/* --- Column Width & Behavior Rules --- */

/* Column 1: Checkbox (Narrow & Centered) */
.track-table th:nth-child(1),
.track-table td:nth-child(1) {
    width: 45px;
    text-align: center;
    padding-left: 8px;
    padding-right: 8px;
}

.track-table td:nth-child(1) input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* Column 2: File Name (Limited width with ellipsis truncation) */
.track-table th:nth-child(2),
.track-table td:nth-child(2) {
    width: 17%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #334155;
    font-size: 9px;
}

/* Column 3: Username (Given plenty of wide space) */
.track-table th:nth-child(3),
.track-table td:nth-child(3) {
    width: 25%;
    font-weight: 500;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Column 4: km */
.track-table th:nth-child(4),
.track-table td:nth-child(4) {
    width: 13%;
    color: #64748b;
    white-space: nowrap;
    text-align: right;
    padding-right: 16px;
}
/* Column 5: time(as [h]:mm:ss, fixed comfortable width) */
.track-table th:nth-child(5),
.track-table td:nth-child(5) {
    width: 20%;
    color: #64748b;
    white-space: nowrap;
    text-align: right;
    padding-right: 16px;
}
/* Column 6: Date (Formatted as dd Mmm yy, fixed comfortable width) */
.track-table th:nth-child(6),
.track-table td:nth-child(6) {
    width: 20%;
    color: #64748b;
    white-space: nowrap;
    text-align: right;
    padding-right: 16px;
}
.location-header-row td {
  background-color: #f1f5f9;
  font-weight: bold;
  color: var(--text-dark);
}

.track-row {
  transition: background-color 0.15s ease;
}

.track-row:hover {
  background-color: #f8fafc;
}


/* --- 7. BUTTONS, FORMS & ANIMATION CONTROLS --- */
.btn {
  display: inline-block;
  background-color: var(--primary-blue);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  text-align: center;
  text-decoration: none;
}
.btn.ctrl{padding: 2px 4px;}
.btn:hover {
  background-color: #0052a3;
}

.logout-btn {
  background-color: #ef4444;
  color: #ffffff;
  width: 100%;
}

.logout-btn:hover {
  background-color: #dc2626;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.auth-tabs button {
  flex: 1;
  padding: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-main);
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.auth-form input {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 13px;
}

#animation-controls-card {
  position: sticky;
  top: 0;
  z-index: 500;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 16px;
}

.custom-runner-icon {
  background: transparent;
  border: none;
}


/* ==========================================================================
   8. MOBILE RESPONSIVE LAYOUT (< 1030px)
   Transforms Left Menu into a Fixed Top Bar & Right Menu into a Fixed Bottom Bar
   ========================================================================== */
@media (max-width: 1029px) {
  .app-container {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
  }

  /* Fixed Top Bar (Converted Left Menu) */
  .menu-left {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 56px;
    z-index: 1000;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    background: var(--card-bg);
    overflow: hidden;
  }
  .top-username {
    flex: 1;            /* Takes up all remaining space between logo and menu */
    min-width: 0;       /* CRITICAL: Allows flex item to shrink below content size */
    white-space: nowrap;/* Keeps text on a single line */
    overflow: hidden;   /* Hides text that exceeds the box */
    text-overflow: ellipsis; /* Adds the "..." at the end */
    text-align: center; /* Centers name if there's room, or left-aligns */
    font-size: 14px;
    color: #334155;
}
  /* Fixed Bottom Bar (Converted Right Menu / Race Mode Panel) 
  .menu-right {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 130px;
    z-index: 1000;
    padding: 8px 16px max(8px, env(safe-area-inset-bottom)) 16px;
    border-left: none;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
  }
*/
  #race-mode-menu {
    margin-top: 4px;
  }
  
  #race-mode-menu hr {
    display: none; /* Save space on mobile bottom bar */
  }

  /* Center Scrolling Workspace (Locked securely between top and bottom fixed bars) */
  .content-panel {
    position: absolute;
    top: 56px;    /* Matches top bar height */
    bottom: 130px; /* Matches bottom bar height */
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
  }

  .top-bar {
    display: none; /* Hide duplicate header in mobile view */
  }

  #map {
    height: 260px; /* Compact map height for mobile phones */
  }
}
.control-header-container {
        display: flex; 
        align-items: center; 
        gap: 10px; 
        margin-bottom: 10px;
    }
    
    /* On mobile screens (under 768px wide), stack the title above the buttons */
    @media (max-width: 768px) {
        .control-header-container {
            flex-wrap: wrap;
        }
        #list-title {
            flex: 0 0 100% !important;
            margin-bottom: 8px !important;
            text-align: left;
        }
    }
/* --- Desktop Layout (Vertical) --- */
.app-nav {
    position: relative;
    display: inline-block; /* Or flex/block depending on your layout container */
}

/* Hide the hamburger button on desktop */
.menu-toggle-btn {
    display: none; 
}

/* Make the list vertical on desktop */
.nav-links {
    display: flex;
    flex-direction: column; /* Stack items vertically */
    list-style: none;
    gap: 10px;              /* Spacing between items */
    margin: 0;
    padding: 12px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    width: 200px;           /* Fixed width for the vertical menu */
}

.nav-links li {
    width: 100%;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
}

.nav-links li:last-child {
    border-bottom: none;
}

.nav-links li a {
    text-decoration: none;
    color: #334155;
    font-weight: 500;
    display: block;
    width: 100%;
}


/* --- Mobile Layout (Small screens) --- */
@media (max-width: 768px) {
    .menu-toggle-btn {
        display: block; /* Show hamburger only on phones */
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        color: #1e293b;
        padding: 4px 8px;
    }
    .nav-links {
        display: none; 
        
        /* Switch from absolute to fixed to break out of the parent container */
        position: fixed !important;
        top: 60px;       /* Adjust top spacing to align just below your header/hamburger */
        right: 16px;     /* Spacing from the right edge of the screen */
        
        width: 200px;
        z-index: 99999 !important; /* Force top layer */
        background: #ffffff;
        border: 1px solid #cbd5e1;
        border-radius: 8px;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    }

    .nav-links.active {
        display: flex !important;
    }
}

/* Profile Container Card */
.profile-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}

.profile-header h2 {
    margin: 0 0 6px 0;
    font-size: 20px;
    color: #0f172a;
}

.profile-header p {
    margin: 0 0 20px 0;
    font-size: 13px;
    color: #64748b;
}

.form-group {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

.form-group input {
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    color: #1e293b;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.age-badge {
    font-size: 12px;
    font-weight: 600;
    color: #2563eb;
    background: #eff6ff;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
    margin-top: 2px;
}

.profile-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #f1f5f9;
}

.btn-primary {
    background-color: #3b82f6;
    color: #ffffff;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    padding: 10px 18px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.profile-alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }