/**
 * FitFileFixer — Custom Styles & CSS Variables
 * Design-System: Komoot-Farbschema
 * Ansatz: Mobile-First
 */

/* ===== Alpine.js Cloak (prevent FOUC) ===== */
[x-cloak] { display: none !important; }

/* ===== CSS Custom Properties (Komoot Brand) ===== */
:root {
    /* Primary Colors */
    --color-primary: #6AA127;
    --color-primary-light: #8FCE3C;
    --color-primary-bright: #9CDE4E;
    --color-primary-dark: #33582F;

    /* Neutral Colors */
    --color-white: #FFFFFF;
    --color-gray-50: #F9FAFB;
    --color-gray-100: #F3F4F6;
    --color-gray-200: #E5E7EB;
    --color-gray-300: #D1D5DB;
    --color-gray-400: #9CA3AF;
    --color-gray-500: #6B7280;
    --color-gray-600: #4B5563;
    --color-gray-700: #374151;
    --color-gray-800: #1F2937;
    --color-gray-900: #111827;
    --color-black: #000000;

    /* Semantic Colors */
    --color-success: #6AA127;
    --color-warning: #F59E0B;
    --color-danger: #EF4444;
    --color-info: #3B82F6;

    /* Gradient */
    --gradient-primary: linear-gradient(180deg, #8FCE3C 0%, #6AA127 100%);

    /* Typography */
    --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Layout */
    --header-height: 64px;
    --bottom-nav-height: 64px;
    --sidebar-width: 260px;
}

/* ===== Base ===== */
* {
    box-sizing: border-box;
}

html {
    font-family: var(--font-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--color-gray-50);
    color: var(--color-gray-900);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Platz fuer Bottom-Navigation auf Mobile */
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 1024px) {
    body {
        padding-bottom: 0;
    }
}

/* ===== Focus Styles (Primary Green Ring) ===== */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(106, 161, 39, 0.2);
    outline: none;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.5;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    min-height: 44px;
    min-width: 44px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: var(--color-white);
}

.btn-primary:hover {
    background: var(--color-primary-light);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-white);
    color: var(--color-gray-700);
    border: 1px solid var(--color-gray-300);
}

.btn-secondary:hover {
    background: var(--color-gray-50);
    border-color: var(--color-gray-400);
}

.btn-danger {
    background: var(--color-danger);
    color: var(--color-white);
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1.0625rem;
}

/* ===== Cards ===== */
.card {
    background: var(--color-white);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-body {
    padding: 1.25rem;
}

@media (min-width: 768px) {
    .card-body {
        padding: 1.5rem;
    }
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray-200);
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

@media (min-width: 1024px) {
    .header {
        padding: 0 2rem;
    }
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
}

.header-logo svg {
    width: 32px;
    height: 32px;
}

/* ===== Bottom Navigation (Mobile) ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--color-white);
    border-top: 1px solid var(--color-gray-200);
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bottom-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (min-width: 1024px) {
    .bottom-nav {
        display: none;
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.375rem 0.75rem;
    min-width: 44px;
    min-height: 44px;
    color: var(--color-gray-500);
    text-decoration: none;
    font-size: 0.6875rem;
    font-weight: 500;
    transition: color 0.15s;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
    color: var(--color-primary);
}

.bottom-nav-item svg {
    width: 24px;
    height: 24px;
}

/* ===== Desktop Sidebar ===== */
.sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        background: var(--color-white);
        border-right: 1px solid var(--color-gray-200);
        padding: 1.5rem 0;
        overflow-y: auto;
        z-index: 30;
    }
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: var(--color-gray-600);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: all 0.15s;
    min-height: 44px;
}

.sidebar-item:hover {
    background: var(--color-gray-50);
    color: var(--color-primary);
}

.sidebar-item.active {
    color: var(--color-primary);
    background: rgba(106, 161, 39, 0.08);
    border-right: 3px solid var(--color-primary);
}

.sidebar-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ===== Main Content ===== */
.main-content {
    padding: 1.25rem 1rem;
    flex: 1;
}

@media (min-width: 1024px) {
    .main-content {
        margin-left: var(--sidebar-width);
        padding: 2rem;
    }
}

/* ===== Flash Messages ===== */
.flash {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flash-success {
    background: rgba(106, 161, 39, 0.1);
    color: var(--color-primary-dark);
    border: 1px solid rgba(106, 161, 39, 0.3);
}

.flash-error {
    background: rgba(239, 68, 68, 0.1);
    color: #991B1B;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.flash-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #92400E;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.flash-info {
    background: rgba(59, 130, 246, 0.1);
    color: #1E40AF;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-gray-700);
    margin-bottom: 0.375rem;
}

.form-input {
    display: block;
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-gray-900);
    background: var(--color-white);
    border: 1px solid var(--color-gray-300);
    border-radius: 0.5rem;
    min-height: 44px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input::placeholder {
    color: var(--color-gray-400);
}

/* ===== Language Switcher ===== */
.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
}

.lang-switch a {
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    text-decoration: none;
    color: var(--color-gray-500);
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
    min-height: 32px;
    min-width: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.lang-switch a:hover {
    color: var(--color-primary);
}

.lang-switch a.active {
    color: var(--color-primary);
    background: rgba(106, 161, 39, 0.1);
}

/* ===== Utility ===== */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1rem;
}

@media (min-width: 768px) {
    .container {
        padding: 0 1.5rem;
    }
}

.text-primary { color: var(--color-primary); }
.text-muted { color: var(--color-gray-500); }
.bg-primary { background: var(--color-primary); }
.bg-gradient { background: var(--gradient-primary); }

/* ===== Upload Dropzone ===== */
.dropzone {
    border: 2px dashed var(--color-gray-300);
    border-radius: 1rem;
    padding: 2.5rem 1.5rem;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--color-white);
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.dropzone:hover {
    border-color: var(--color-primary);
    background: rgba(106, 161, 39, 0.03);
}

.dropzone.dragging {
    border-color: var(--color-primary);
    background: rgba(106, 161, 39, 0.08);
    border-style: solid;
    transform: scale(1.01);
}

.dropzone.uploading {
    pointer-events: none;
    opacity: 0.8;
}

.dropzone-icon {
    width: 48px;
    height: 48px;
    color: var(--color-gray-400);
    transition: color 0.2s;
}

.dropzone:hover .dropzone-icon,
.dropzone.dragging .dropzone-icon {
    color: var(--color-primary);
}

@media (min-width: 768px) {
    .dropzone {
        padding: 3rem 2rem;
        min-height: 280px;
    }

    .dropzone-icon {
        width: 56px;
        height: 56px;
    }
}

/* ===== Upload Progress ===== */
.progress-bar {
    width: 100%;
    max-width: 300px;
    height: 6px;
    background: var(--color-gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ===== Activity Card (Upload-Liste) ===== */
.activity-card {
    background: var(--color-white);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
}

.activity-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.activity-card-body {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.activity-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.activity-card-info {
    flex: 1;
    min-width: 0;
}

.activity-card-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-card-meta {
    font-size: 0.8125rem;
    color: var(--color-gray-500);
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.125rem;
}

/* ===== Viewer: Summary Metric Cards ===== */
.metric-card {
    background: var(--color-white);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.metric-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.metric-card-icon svg {
    width: 18px;
    height: 18px;
}

.metric-card-content {
    flex: 1;
    min-width: 0;
}

.metric-card-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-gray-900);
    line-height: 1.2;
}

.metric-card-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-gray-500);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-top: 0.125rem;
}

.metric-card-sub {
    font-size: 0.75rem;
    color: var(--color-gray-400);
    margin-top: 0.125rem;
}

/* ===== Viewer: Map Container ===== */
.map-container {
    width: 100%;
    height: 250px;
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: var(--color-gray-100);
}

@media (min-width: 768px) {
    .map-container {
        height: 350px;
    }
}

@media (min-width: 1024px) {
    .map-container {
        height: 400px;
    }
}

/* ===== Viewer: Chart Container ===== */
.chart-container {
    background: var(--color-white);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    height: 200px;
}

@media (min-width: 768px) {
    .chart-container {
        height: 250px;
        padding: 1.25rem;
    }
}

.chart-container canvas {
    max-height: 100%;
}

/* Chart.js canvas inside viewer card containers */
.card-body canvas[id^="chart-"] {
    width: 100% !important;
    height: 100% !important;
    position: absolute;
    top: 0;
    left: 0;
}

/* ===== Smart Edit: Field Row ===== */
.edit-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-gray-100);
}

.edit-field:last-child {
    border-bottom: none;
}

.edit-field-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-gray-600);
}

.edit-field-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.edit-field-original {
    flex: 1;
    font-size: 0.875rem;
    color: var(--color-gray-400);
    background: var(--color-gray-50);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    min-height: 38px;
    display: flex;
    align-items: center;
}

.edit-field-input {
    flex: 1;
    font-size: 0.875rem;
    color: var(--color-gray-900);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid var(--color-primary);
    background: var(--color-white);
    min-height: 38px;
    transition: box-shadow 0.15s;
}

.edit-field-input:focus {
    box-shadow: 0 0 0 3px rgba(106, 161, 39, 0.15);
    outline: none;
}

.edit-field-arrow {
    color: var(--color-gray-300);
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .edit-field {
        flex-direction: row;
        align-items: center;
    }

    .edit-field-label {
        width: 140px;
        flex-shrink: 0;
    }

    .edit-field-row {
        flex: 1;
    }
}

/* ===== Swim Info Box ===== */
.swim-info {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 0.75rem;
    padding: 1rem;
}

.swim-formula {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--color-info);
    text-align: center;
    padding: 0.5rem 0;
}

/* ===== Laps/Lengths Table ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th {
    background: var(--color-gray-50);
    color: var(--color-gray-600);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    font-size: 0.6875rem;
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--color-gray-200);
    white-space: nowrap;
}

.data-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-gray-100);
    color: var(--color-gray-700);
}

.data-table tr:hover td {
    background: var(--color-gray-50);
}

.data-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.75rem;
    border: 1px solid var(--color-gray-200);
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 1rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
}

.toast-success {
    background: var(--color-primary-dark);
    color: var(--color-white);
}

.toast-error {
    background: var(--color-danger);
    color: var(--color-white);
}

@media (min-width: 1024px) {
    .toast {
        bottom: 2rem;
    }
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
}

/* ===== Section Headers ===== */
.section-header {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-gray-900);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-header svg {
    width: 20px;
    height: 20px;
    color: var(--color-primary);
}

/* ===== Badge ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-green {
    background: rgba(106, 161, 39, 0.1);
    color: var(--color-primary-dark);
}

.badge-blue {
    background: rgba(59, 130, 246, 0.1);
    color: #1E40AF;
}

.badge-gray {
    background: var(--color-gray-100);
    color: var(--color-gray-600);
}

/* ===== Skeleton Loading ===== */
.skeleton {
    background: linear-gradient(90deg, var(--color-gray-100) 25%, var(--color-gray-200) 50%, var(--color-gray-100) 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 0.375rem;
}

@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Viewer Header Bar ===== */
.viewer-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .viewer-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.viewer-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.viewer-header-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    color: var(--color-white);
    flex-shrink: 0;
}

.viewer-header-icon svg {
    width: 24px;
    height: 24px;
}

.viewer-header-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--color-gray-900);
    line-height: 1.2;
}

.viewer-header-subtitle {
    font-size: 0.8125rem;
    color: var(--color-gray-500);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.viewer-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ===== Route Completer: Pulsing last-point marker ===== */
@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
    }
    70% {
        box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.pulse-marker {
    animation: pulse-ring 2s ease-out infinite;
    border-radius: 50%;
}

/* Leaflet circle markers don't natively animate,
   so we target the SVG circle path via the class */
.leaflet-interactive.pulse-marker {
    animation: pulse-ring 2s ease-out infinite;
}

/* ===== Route Completer: Waypoint & flag marker icons ===== */
.route-wp-icon,
.route-end-flag {
    background: transparent !important;
    border: none !important;
}

/* ===== Route Completer: BETA badge in tool card ===== */
.badge-beta {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(245, 158, 11, 0.15);
    color: #B45309;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
