/* CRITICAL: Ensure Battle Formation tab displays when active */
#battle-formation-tab {
    display: none !important;
}

#battle-formation-tab.active {
    display: flex !important;
    flex-direction: column;
    height: calc(100vh - 60px);
    overflow: auto;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
    font-family: 'Orbitron', monospace;
    color: #fff;
}
/* Battle Formation - Scoped Styles for Tab Integration */
/* All selectors scoped under #battle-formation-tab */

/* Base styles applied to all states */
#battle-formation-tab {
    font-family: 'Orbitron', monospace;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
    color: #fff;
}

#battle-formation-tab * {
    box-sizing: border-box;
}

/* Header (Battle Formation controls) */
#battle-formation-tab .header {
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
    padding: 1rem 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid #e94560;
    flex-shrink: 0;
    /* styles.css gives every <header> z-index:200 (meant for the app header);
       keep this one below the side menu (z-index:150). */
    z-index: 1;
}

#battle-formation-tab .title {
    font-size: 2rem;
    font-weight: 900;
    color: #e94560;
    text-align: center;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
    letter-spacing: 4px;
}

#battle-formation-tab .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    align-items: center;
}

#battle-formation-tab .match-id-input {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 2px solid #533483;
    background: rgba(83, 52, 131, 0.2);
    color: #fff;
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    min-width: 200px;
}

#battle-formation-tab .match-id-input:focus {
    outline: none;
    border-color: #e94560;
    box-shadow: 0 0 10px rgba(233, 69, 96, 0.3);
}

#battle-formation-tab .btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

#battle-formation-tab .btn-primary {
    background: linear-gradient(135deg, #533483 0%, #7b4397 100%);
    color: #fff;
}

#battle-formation-tab .btn-secondary {
    background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
    color: #fff;
}

#battle-formation-tab .btn-info {
    background: linear-gradient(135deg, #0f3460 0%, #533483 100%);
    color: #fff;
}

#battle-formation-tab .btn-danger {
    background: linear-gradient(135deg, #e94560 0%, #0f3460 100%);
    color: #fff;
}

#battle-formation-tab .btn-warning {
    background: linear-gradient(135deg, #f39c12 0%, #d35400 100%);
    color: #fff;
}

#battle-formation-tab .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

#battle-formation-tab .btn-record {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: #fff;
}

#battle-formation-tab .btn-success {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
    color: #fff;
}

#battle-formation-tab .recording-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#battle-formation-tab .timeline-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#battle-formation-tab .timeline-slider {
    width: 200px;
}

/* Main content area */
#battle-formation-tab .main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Hero Panel */
#battle-formation-tab .hero-panel {
    width: 300px;
    background: rgba(15, 52, 96, 0.9);
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 2px solid #e94560;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#battle-formation-tab .hero-panel h3 {
    color: #e94560;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    text-align: center;
    flex: 0 0 auto;
}

#battle-formation-tab .search-container {
    flex: 0 0 auto;
}

#battle-formation-tab .search-input {
    width: 100%;
    padding: 0.7rem;
    border-radius: 6px;
    border: 2px solid #533483;
    background: rgba(83, 52, 131, 0.3);
    color: #fff;
    font-family: 'Orbitron', monospace;
    margin-bottom: 1rem;
}

#battle-formation-tab .search-input:focus {
    outline: none;
    border-color: #e94560;
}

#battle-formation-tab .hero-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
    flex: 0 0 auto;
}

#battle-formation-tab .hero-item {
    cursor: grab;
    text-align: center;
    padding: 0.5rem;
    background: rgba(83, 52, 131, 0.2);
    border-radius: 8px;
    transition: all 0.3s ease;
}

#battle-formation-tab .hero-item:hover {
    background: rgba(233, 69, 96, 0.3);
    transform: scale(1.05);
}

#battle-formation-tab .hero-item img {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    margin-bottom: 0.3rem;
    object-fit: cover;
    object-position: center;
}

#battle-formation-tab .hero-name {
    font-size: 0.7rem;
    color: #fff;
}

/* Map Container */
#battle-formation-tab .map-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #000;
}

#battle-formation-tab .map-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#battle-formation-tab .map-area {
    position: relative;
    width: 100%;
    height: 100%;
}

#battle-formation-tab .map-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#battle-formation-tab .drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#battle-formation-tab .drawing-canvas.drawing-mode,
#battle-formation-tab .drawing-canvas.erasing-mode {
    pointer-events: all;
    cursor: crosshair;
}

#battle-formation-tab .formation-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
}

#battle-formation-tab .placed-hero {
    position: absolute;
    cursor: grab;
    transform: translate(-50%, -50%);
    z-index: 100;
}

#battle-formation-tab .placed-hero img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid #00ff00;
    box-shadow: 0 0 12px rgba(0, 255, 0, 0.8);
    object-fit: cover;
    object-position: center;
}

#battle-formation-tab .placed-hero.enemy img {
    border-color: #ff0000;
    box-shadow: 0 0 12px rgba(255, 0, 0, 0.8);
}

/* Hide hero labels on map */
#battle-formation-tab .hero-label {
    display: none !important;
}

/* Placed Wards */
#battle-formation-tab .placed-ward {
    position: absolute;
    width: 24px;
    height: 24px;
    cursor: grab;
    pointer-events: all;
    transform: translate(-50%, -50%);
    z-index: 95;
    transition: none;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

#battle-formation-tab .placed-ward:hover {
    transform: translate(-50%, -50%) scale(1.2);
}

#battle-formation-tab .placed-ward.dragging {
    transition: none !important;
    will-change: left, top;
}

#battle-formation-tab .placed-ward img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 6px rgba(0, 255, 0, 0.9));
}

#battle-formation-tab .placed-ward.enemy img {
    filter: drop-shadow(0 0 6px rgba(255, 0, 0, 0.9));
}

/* Vision Radius Circles */
#battle-formation-tab .vision-radius {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 90;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    will-change: left, top;
}

#battle-formation-tab .vision-radius.observer {
    border: 2px solid #00ff00;
    background: radial-gradient(circle, rgba(0, 255, 0, 0.4) 0%, rgba(0, 255, 0, 0.25) 40%, rgba(0, 255, 0, 0.1) 70%, rgba(0, 255, 0, 0.02) 100%);
}

#battle-formation-tab .vision-radius.sentry {
    border: 2px solid #4dd0e1;
    background: radial-gradient(circle, rgba(77, 208, 225, 0.4) 0%, rgba(77, 208, 225, 0.25) 40%, rgba(77, 208, 225, 0.1) 70%, rgba(77, 208, 225, 0.02) 100%);
}

#battle-formation-tab .vision-radius.enemy {
    border: 2px solid #ff0000;
    background: radial-gradient(circle, rgba(255, 0, 0, 0.4) 0%, rgba(255, 0, 0, 0.25) 40%, rgba(255, 0, 0, 0.1) 70%, rgba(255, 0, 0, 0.02) 100%);
}

#battle-formation-tab .placed-ward:hover + .vision-radius {
    opacity: 0.75;
}

/* Drawing Controls */
#battle-formation-tab .drawing-controls {
    position: absolute;
    top: 44px;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.8);
    padding: 0.5rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid #533483;
    z-index: 20;
}

#battle-formation-tab .drawing-btn {
    padding: 0.5rem 1rem;
    border: 2px solid #533483;
    background: rgba(83, 52, 131, 0.3);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Orbitron', monospace;
    transition: all 0.3s ease;
    white-space: nowrap;
}

#battle-formation-tab .drawing-btn:hover {
    background: rgba(83, 52, 131, 0.5);
    transform: scale(1.05);
}

#battle-formation-tab .drawing-btn.active {
    background: #e94560;
    border-color: #e94560;
    box-shadow: 0 0 10px #e94560;
}

#battle-formation-tab .color-palette {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

#battle-formation-tab .color-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #fff;
    cursor: pointer;
}

#battle-formation-tab .color-btn.active {
    border-width: 3px;
    box-shadow: 0 0 10px currentColor;
}

/* Team toggle */
#battle-formation-tab .team-toggle-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex: 0 0 auto;
}

#battle-formation-tab .team-toggle-btn {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid #533483;
    background: rgba(83, 52, 131, 0.2);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Orbitron', monospace;
    font-size: 0.8rem;
}

#battle-formation-tab .team-toggle-btn.active {
    background: #e94560;
    border-color: #e94560;
}

/* Wards */
#battle-formation-tab .wards-section {
    margin: 1rem 0;
    padding: 1rem;
    background: rgba(83, 52, 131, 0.1);
    border-radius: 8px;
    flex: 0 0 auto;
}

#battle-formation-tab .wards-section h4 {
    color: #e94560;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

#battle-formation-tab .wards-container {
    display: flex;
    gap: 0.5rem;
}

#battle-formation-tab .ward-item {
    cursor: grab;
    padding: 0.5rem;
    background: rgba(83, 52, 131, 0.3);
    border-radius: 6px;
    text-align: center;
    flex: 1;
}

#battle-formation-tab .ward-item img {
    width: 40px;
    height: 40px;
}

#battle-formation-tab .ward-name {
    display: block;
    font-size: 0.7rem;
    margin-top: 0.3rem;
}

/* Modals */
#battle-formation-tab .save-modal,
#battle-formation-tab .note-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

#battle-formation-tab .save-modal.active,
#battle-formation-tab .note-modal.active {
    display: flex;
}

#battle-formation-tab .save-modal-content,
#battle-formation-tab .note-modal-content {
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
    padding: 2rem;
    border-radius: 12px;
    border: 2px solid #e94560;
    max-width: 500px;
    width: 90%;
}

#battle-formation-tab .save-form input,
#battle-formation-tab .note-form textarea,
#battle-formation-tab .note-form select {
    width: 100%;
    padding: 0.7rem;
    margin: 0.5rem 0;
    border-radius: 6px;
    border: 2px solid #533483;
    background: rgba(83, 52, 131, 0.3);
    color: #fff;
    font-family: 'Orbitron', monospace;
}

/* Formation info */
#battle-formation-tab .formation-info {
    background: rgba(15, 52, 96, 0.9);
    padding: 1rem;
    border-top: 2px solid #533483;
}

#battle-formation-tab .composition-stats {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

#battle-formation-tab .stat {
    font-size: 0.9rem;
}

/* Tooltip */
#battle-formation-tab .hero-tooltip {
    position: fixed;
    background: rgba(15, 52, 96, 0.95);
    padding: 1rem;
    border-radius: 8px;
    border: 2px solid #e94560;
    pointer-events: none;
    z-index: 10001;
    display: none;
}

/* Sidebar toggle */
#battle-formation-tab .sidebar-toggle-btn {
    position: absolute;
    left: 300px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    background: #e94560;
    border: none;
    padding: 1rem 0.5rem;
    cursor: pointer;
    border-radius: 0 6px 6px 0;
}

#battle-formation-tab .hero-panel.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
}

#battle-formation-tab .hero-panel.collapsed + .sidebar-toggle-btn {
    left: 0;
}

/* Responsive drawing controls for smaller screens */
@media (max-width: 900px) {
    #battle-formation-tab .drawing-controls {
        top: auto;
        bottom: 1rem;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: row;
        width: auto;
    }

    #battle-formation-tab .drawing-controls .color-palette {
        margin-top: 0;
        margin-left: 0.5rem;
    }
}

#battle-formation-tab .bf-time-ruler {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 38px;
    z-index: 5;
    pointer-events: none;
    user-select: none;
}

#battle-formation-tab .bf-time-ruler::before {
    content: "";
    position: absolute;
    bottom: 6px;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(0, 255, 0, 0.5);
}

#battle-formation-tab .bf-tick {
    position: absolute;
    bottom: 2px;
    height: 10px;
    width: 2px;
    background: #00ff00;
    transform: translateX(-1px);
    box-shadow: 0 0 4px rgba(0, 255, 0, 0.8);
}

#battle-formation-tab .bf-tick-label {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    font-weight: 700;
    color: #00ff00;
    font-family: 'Orbitron', monospace, sans-serif;
    line-height: 1;
    white-space: nowrap;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
}
