/* addicted Canvas CSS - Минимальные стили без конфликтов */

/* Базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000000;
    color: #ffffff;
    min-height: 100vh;
    font-weight: 300;
    line-height: 1.4;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    position: relative;
}

/* VSCO-style layout: preview on top, editing panel on bottom */
.mobile-container {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Preview area - как в VSCO */
.preview-area {
    position: fixed;
    top: 64px; /* Обновлено с 48px до 64px */
    left: 0;
    right: 0;
    bottom: 180px;
    width: 100%;
    height: calc(100vh - 64px - 180px); /* Обновлено с 48px до 64px */
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
    overflow: hidden;
    z-index: 1;
    box-sizing: border-box;
    padding: 16px 0; /* Внутренние отступы вместо margin у дочернего контейнера */
    /* Шашечки для пустого превью */
    background-image: 
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-repeat: repeat;
}

/* Ratio classes удалены: соотношение применяется только к #route-canvas */

/* Точное соответствие канваса соотношению сторон */
.ratio-9-16 #route-canvas {
    aspect-ratio: 0.5625;
    max-height: 100%; /* Возвращаем ограничение по высоте, чтобы вмещаться в контейнер */
}

.ratio-4-5 #route-canvas {
    aspect-ratio: 0.8;
}

/* Подход как в polymer-workshop: обертка + canvas */
#viewport {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Stage для масштабирования */
#stage {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Обертка как в polymer-workshop */
#connected,
.connected-state {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0; /* Вертикальные отступы в .preview-area, по бокам без доп. отступов */
    overflow: hidden;
}

/* Canvas стили управляются JavaScript - убираем конфликтующие CSS */
#connected canvas {
    /* Размеры управляются JavaScript */
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    transition: height 0.3s ease-out, transform 0.3s ease-out;
}

/* Canvas для превью - размеры управляются JavaScript */
#route-canvas {
    /* Размеры управляются JavaScript */
    display: block;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    padding: 0;
    border: none;
    outline: none;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    object-fit: contain;
    width: auto;
    height: auto;
    /* Сохраняем пропорции канваса */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    transition: height 0.3s ease-out, transform 0.3s ease-out;
    /* Исправление для Safari iOS: принудительное масштабирование */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Улучшение рендеринга в Safari iOS */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Шашечки как в фоторедакторах - показываются только когда нет фона */
    background: 
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-repeat: repeat;
    background-attachment: local;
}

/* Скрыть шашечки когда есть фоновая картинка */
#route-canvas.has-background {
    background: transparent;
}

/* Navigation Bar */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #333333;
    z-index: 100;
    padding: 0;
    margin: 0;
    height: 64px;
}

.nav-container {
    display: flex;
    align-items: center;
    width: 100% !important; /* Растягиваем на всю ширину */
    max-width: 100%;
    height: 100%;
    margin: 0 !important; /* Убираем margin принудительно */
    padding: 0 16px; /* Внутренние отступы по 16px */
}

.nav-brand h1 {
    font-size: 18px;
    font-weight: 300;
    color: #ffffff;
    margin: 0;
}

.nav-logo-text {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', sans-serif;
    font-weight: 900;
    font-style: italic;
    font-size: 20px;
    color: #ffffff;
    cursor: pointer;
    transition: opacity 0.2s ease;
    letter-spacing: -0.5px;
}

.nav-logo-text:hover {
    opacity: 0.8;
}

/* Context Menu Styles */
.context-menu {
    position: fixed;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    min-width: 200px;
    padding: 8px 0;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.2s ease;
    pointer-events: none;
}

.context-menu:not(.hidden) {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #ffffff;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    font-weight: 500;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.context-menu-item svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.context-menu-item span {
    white-space: nowrap;
}

.nav-center {
    display: none; /* Скрываем по умолчанию, показываем только когда авторизован */
    align-items: center;
    gap: 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.nav-center.visible {
    display: flex; /* Показываем когда пользователь авторизован */
}

/* Hide logout button by default, show only when logged in */
#logout-btn {
    display: none;
}

#logout-btn.visible {
    display: flex;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* Перемещает кнопки вправо */
}

.nav-actions .btn {
    height: 36px;
    padding: 6px 12px;
    font-size: 11px;
    white-space: nowrap;
    min-width: auto;
}

.nav-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    transition: stroke 0.2s ease;
}

/* Editing Panel */
.editing-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 180px;
    background: #000000;
    border-top: 1px solid #333333;
    padding: 0;
    margin: 0;
    overflow: hidden;
    z-index: 90;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background: #111111;
    border-bottom: 1px solid #333333;
    padding: 0;
    margin: 0;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #888888;
    padding: 8px 8px; /* Уменьшили padding для высоты 32px */
    cursor: pointer;
    font-size: 11px; /* Изменили размер текста на 11px */
    font-weight: 300;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 32px; /* Явно задали высоту 32px */
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-btn.active {
    color: #ffffff;
    background: #000000;
    border-bottom: 2px solid #ffffff;
}

.tab-btn:hover {
    color: #ffffff;
    background: #222222;
}

/* Tab Panels */
.tab-panel {
    display: none;
    padding: 20px;
    height: calc(180px - 50px);
    overflow-y: auto;
}

.tab-panel.active {
    display: block;
}

/* Data Buttons Container */
.data-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; /* 3 колонки */
    grid-template-rows: auto auto; /* 2 ряда с автоматической высотой */
    gap: 8px;
    width: 100%;
}

/* Первый ряд всегда занимает полную ширину */
.data-buttons .data-btn[data-metric="distance"],
.data-buttons .data-btn[data-metric="elevation"], 
.data-buttons .data-btn[data-metric="time"] {
    grid-row: 1;
}

/* Второй ряд только для Speed */
.data-buttons .data-btn[data-metric="speed"] {
    grid-row: 2;
    grid-column: 2; /* Центр средней колонки */
}

/* Data Buttons */
.data-buttons .data-btn {
    height: 36px;
    padding: 0 12px;
    background: transparent;
    border: 1px solid #ffffff;
    color: #ffffff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    border-radius: 4px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.data-buttons .data-btn:not(.active) {
    background: transparent;
    color: #ffffff;
    border: 1px solid #ffffff;
}

.data-buttons .data-btn.active {
    background: #ffffff;
    color: #000000;
    border: 1px solid #ffffff;
}

.data-buttons .data-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.data-buttons .data-btn:hover.active {
    background: #ffffff;
    color: #000000;
}

/* Ratio Controls */
.ratio-controls,
.club-controls {
    display: flex;
    gap: 8px;
    justify-content: stretch;
    width: 100%;
}

/* Ratio Buttons */
.ratio-btn {
    height: 36px;
    padding: 0 16px;
    background: transparent;
    border: 1px solid #ffffff;
    color: #ffffff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    border-radius: 4px;
    white-space: nowrap;
    flex: 1; /* Растягиваем кнопки на ширину контейнера */
}

.ratio-btn.active {
    background: #ffffff;
    color: #000000;
}

.ratio-btn:hover {
    background: #ffffff;
    color: #000000;
}

/* Club Buttons */
.club-btn {
    height: 36px;
    padding: 0 16px;
    background: transparent;
    border: 1px solid #ffffff;
    color: #ffffff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    border-radius: 4px;
    white-space: nowrap;
    flex: 1; /* Растягиваем кнопки на ширину контейнера */
}

.club-btn.active {
    background: #ffffff;
    color: #000000;
}

.club-btn:hover {
    background: #ffffff;
    color: #000000;
}

/* Position Controls */
.position-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* Position Buttons */
.position-btn {
    height: 36px;
    padding: 0 12px;
    background: transparent;
    border: 1px solid #ffffff;
    color: #ffffff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    border-radius: 4px;
    white-space: nowrap;
}

.position-btn.active {
    background: #ffffff;
    color: #000000;
}

.position-btn:hover {
    background: #ffffff;
    color: #000000;
}

/* State Container */
.state-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
    color: #ffffff;
}

/* Not Connected: заполняет видимую область, с отступами и скруглением */
#not-connected {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: calc(100% - 32px);
    height: calc(100% - 32px);
    margin: 16px;
    border-radius: 8px;
    overflow: hidden;
}

.state-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    text-align: center;
}

.state-card h2 {
    margin-bottom: 10px; /* Отступ между заголовком и подписью 10px */
}

.state-card p {
    margin-bottom: 20px; /* Отступ между подписью и кнопкой 20px */
}

.support-info {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.strava-powered {
    font-size: 13px;
    color: #666666;
    font-weight: 400;
}

.support-link {
    font-size: 13px;
    color: #666666;
    font-weight: 400;
}

.support-link a {
    color: #999999;
    text-decoration: none;
    transition: color 0.2s ease;
}

.support-link a:hover {
    color: #cccccc;
}

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
    color: #ffffff;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #333333;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.connected {
    display: none;
}

.connected.show {
    display: block;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    background: #ffffff;
    color: #000000;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: #cccccc;
}

.btn-primary {
    background: #ffffff;
    color: #000000;
}

.btn-primary:hover {
    background: #cccccc;
}

/* Action Buttons */
.action-btn {
    width: 100%;
    background: transparent;
    color: #ffffff;
    border: 1px solid #ffffff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.action-btn:hover {
    background: #ffffff;
    color: #000000;
}

/* Mono toggle button specific styles */
#mono-toggle-btn {
    margin-top: 8px;
}

#mono-toggle-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: #ffffff;
}

/* Stats Overlay - скрываем, так как статистики рисуются в canvas */
.stats-overlay {
    display: none;
}

/* Bottom Stats Overlay - скрываем, так как статистики рисуются в canvas */
.bottom-stats-overlay {
    display: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000 !important;
    display: none;
}

.modal:not(.hidden) {
    display: flex !important;
}

/* Workout Selector Modal */
.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #000000;
    border: 1px solid #333333;
    border-radius: 8px;
    width: calc(100% - 48px); /* Учитываем margin 24px с каждой стороны */
    height: calc(100% - 48px); /* Учитываем margin 24px сверху и снизу */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1001;
    margin: 24px; /* Отступы 24px с каждой стороны */
    box-sizing: border-box; /* Включаем margin в расчет размеров */
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #333333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 18px;
    font-weight: 300;
    color: #ffffff;
}

.strava-link {
    color: #FC5200;
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: opacity 0.2s;
}

.strava-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.modal-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px 20px 40px 20px; /* Добавляем больше отступа снизу */
    overflow-y: auto;
    flex: 1;
}

.workout-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.workout-item {
    padding: 16px;
    border-bottom: 1px solid #333333;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
    margin-bottom: 4px;
}

.workout-item:hover {
    background: #111111;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.workout-item.active {
    background: #222222;
    border: 1px solid #444444;
}

.workout-name {
    font-size: 16px;
    font-weight: 300;
    color: #ffffff;
    margin-bottom: 8px;
}

.workout-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: #888888;
}

.workout-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.workout-stat-label {
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.workout-stat-value {
    font-weight: 400;
    color: #ffffff;
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-container {
        margin: 0 16px;
    }
    
    .tab-panel {
        padding: 16px;
    }
    
    .modal-backdrop {
        padding: 16px;
    }
}

/* Utility Classes */
.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.text-center {
    text-align: center;
}

.mb-4 {
    margin-bottom: 16px;
}

.mt-4 {
    margin-top: 16px;
}

.p-4 {
    padding: 16px;
}

.rounded {
    border-radius: 8px;
}

.shadow-lg {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}
