* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #e5e7eb;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    background: white;
    padding: 16px 24px;
    border-radius: 12px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #1a1a2e;
    letter-spacing: -1px;
}

header h2 {
    font-size: 0.9rem;
    color: #6b7280;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 4px;
}

.main-content {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

/* Team Panel Styles */
.team-panel {
    width: 200px;
    min-width: 200px;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.team-panel h3 {
    margin-bottom: 12px;
    color: #1a1a2e;
    border-bottom: none;
    padding-bottom: 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-buttons {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background: #667eea;
    color: white;
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.help-content,
.settings-content {
    width: 320px;
}

.settings-list {
    padding: 10px 0;
}

.settings-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e5e7eb;
}

.help-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-list li {
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 13px;
    color: #4b5563;
}

.help-list li:last-child {
    border-bottom: none;
}

.team-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.team-actions .btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
    width: auto;
    margin: 0;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-option input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-secondary:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
}

.btn-danger {
    background: #fee2e2;
    color: #dc2626;
    width: 100%;
    margin-top: 8px;
}

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

.team-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.team-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 10px;
    cursor: grab;
    transition: all 0.2s;
    background: #f9fafb;
}

.team-item:hover {
    background: #f3f4f6;
    transform: translateX(2px);
}

.team-item.inactive {
    opacity: 0.4;
    cursor: not-allowed;
}

.team-item.inactive:hover {
    transform: none;
    background: #f9fafb;
}

.team-item.dragging {
    opacity: 0.5;
}

.team-color {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    margin-right: 8px;
    flex-shrink: 0;
}

.team-name {
    flex: 1;
    font-weight: 600;
    color: #1f2937;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.team-item.highlighted {
    background: #667eea;
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.team-item.highlighted .team-name {
    color: white;
}

.team-item.highlighted .session-count {
    color: rgba(255, 255, 255, 0.8);
}

.team-item.highlighted .session-count.high {
    color: #a7f3d0;
}

.session-count {
    font-size: 10px;
    color: #9ca3af;
    margin-right: 6px;
    min-width: 14px;
    text-align: center;
    font-weight: 500;
}

.session-count.high {
    font-weight: 700;
    color: #10b981;
}

.team-controls {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.team-controls button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    font-size: 12px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.team-controls button:hover {
    opacity: 1;
}

.legend {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e5e7eb;
}

.legend h4 {
    color: #6b7280;
    margin-bottom: 10px;
    font-size: 12px;
}

.legend ul {
    list-style: none;
    font-size: 11px;
    color: #9ca3af;
}

.legend li {
    margin-bottom: 5px;
    padding-left: 15px;
    position: relative;
}

.legend li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #667eea;
}

/* Schedule Grid Styles */
.schedule-container {
    flex: 1;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
}

.schedule-grid {
    display: grid;
    grid-template-columns: 50px repeat(10, 1fr);
    grid-auto-rows: 1fr;
    background: white;
    border-radius: 12px;
    min-width: 900px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex: 1;
    padding: 8px 8px 0 0;
}

.schedule-grid.with-f8 {
    grid-template-columns: 50px repeat(15, 1fr);
    min-width: 1200px;
}

.grid-header {
    background: #f8fafc;
    font-weight: 600;
    text-align: center;
    padding: 12px 4px;
    color: #1e293b;
    font-size: 12px;
    border-bottom: 1px solid #e2e8f0;
}

.grid-header.day-header {
    grid-column: span 2;
    background: #6b7280;
    color: white;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 4px;
    border: none;
    border-radius: 8px;
    margin: 0 4px 8px 4px;
}

.schedule-grid.with-f8 .grid-header.day-header {
    grid-column: span 3;
}

.grid-header.field-header {
    font-size: 10px;
    padding: 8px 4px;
    color: #64748b;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.time-slot {
    background: #f8fafc;
    font-weight: 600;
    font-size: 10px;
    padding: 4px;
    text-align: center;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #e2e8f0;
}

.grid-cell {
    min-height: 20px;
    border: 1px solid #e2e8f0;
    background: white;
    position: relative;
    transition: background-color 0.2s;
}

.grid-cell:hover {
    background: #f8fafc;
}

.grid-cell.drop-target {
    background: #dcfce7;
}

.grid-cell.occupied {
    cursor: pointer;
}

/* Session Block Styles */
.session-block {
    position: absolute;
    left: 4px;
    right: 4px;
    top: 4px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: rgba(0, 0, 0, 0.8);
    cursor: grab;
    z-index: 10;
    border: 2px solid rgba(0, 0, 0, 0.15);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.15s, box-shadow 0.15s;
}

.session-block:hover {
    transform: scale(1.01);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
}

.session-block.dragging {
    opacity: 0.7;
    z-index: 100;
}

.session-block.full-field {
    /* Extended styles handled by JS */
}

.session-block.midfield {
    top: auto;
    bottom: 4px;
    height: 20px !important;
    font-size: 13px;
    z-index: 15;
}

.session-block.dark-bg {
    color: rgba(255, 255, 255, 0.95);
}

.session-block.dark-bg .team-label-item[draggable="true"]:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.session-block.highlighted {
    border: 3px solid #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.4), 0 4px 12px rgba(102, 126, 234, 0.5);
    z-index: 20;
    transform: scale(1.02);
}

.schedule-grid.has-highlight .session-block:not(.highlighted) {
    opacity: 0.4;
}

/* Caution tape border for overcrowded slots */
.session-block.too-many-teams {
    padding: 6px;
}

.session-block.too-many-teams::before {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 4px;
    padding: 6px;
    background: repeating-linear-gradient(
        45deg,
        #000 0px,
        #000 8px,
        #f1c40f 8px,
        #f1c40f 16px
    );
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

/* Multiple teams in same slot */
.session-block .team-label {
    text-align: center;
    line-height: 1.2;
}

.session-block .team-label-item {
    text-align: center;
    line-height: 1.4;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.session-block .team-label-item[draggable="true"] {
    cursor: grab;
}

.session-block .team-label-item[draggable="true"]:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.session-block .team-label-item.dragging {
    opacity: 0.5;
}

.session-block .team-label-item.highlighted-team {
    font-weight: 800;
    font-size: 14px;
    color: #000;
    background-color: rgba(255, 255, 255, 0.5);
}

.session-block.drop-target {
    outline: 2px dashed rgba(0, 0, 0, 0.4);
    outline-offset: -4px;
}

/* Ensure team labels don't block drop events on session block */
.session-block .team-label-item {
    pointer-events: auto;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 360px;
    max-width: 90%;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin-bottom: 24px;
    color: #1f2937;
    font-size: 18px;
    font-weight: 700;
}

.close {
    position: absolute;
    top: 20px;
    right: 24px;
    font-size: 24px;
    cursor: pointer;
    color: #9ca3af;
    transition: color 0.2s;
}

.close:hover {
    color: #1f2937;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

.color-options {
    display: flex;
    gap: 12px;
}

.color-option {
    cursor: pointer;
}

.color-option input[type="radio"] {
    display: none;
}

.color-option .color-swatch {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.color-option .color-swatch:hover {
    transform: scale(1.1);
}

.color-option input[type="radio"]:checked + .color-swatch {
    border-color: #1f2937;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Context Menu */
.context-menu {
    display: none;
    position: fixed;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    overflow: hidden;
    min-width: 200px;
}

.context-menu.active {
    display: block;
}

.context-menu-item {
    padding: 12px 18px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    transition: background-color 0.15s;
}

.context-menu-item:hover {
    background-color: #f3f4f6;
}

.context-menu-item[data-action="remove"] {
    color: #dc2626;
}

/* Swap Mode */
body.swap-mode .session-block {
    cursor: pointer;
}

body.swap-mode .session-block:not(.swap-source):hover {
    box-shadow: 0 0 0 3px #3b82f6;
}

.session-block.swap-source {
    box-shadow: 0 0 0 3px #667eea;
    animation: pulse-swap 1.5s ease-in-out infinite;
}

@keyframes pulse-swap {
    0%, 100% {
        box-shadow: 0 0 0 3px #667eea;
    }
    50% {
        box-shadow: 0 0 0 6px rgba(102, 126, 234, 0.3);
    }
}

body.swap-mode::after {
    content: "Modo intercambio: haz click en otra sesión para intercambiar, o fuera para cancelar";
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

/* Responsive */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }

    .team-panel {
        width: 100%;
        position: static;
    }

    .team-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        max-height: none;
    }

    .team-item {
        flex: 0 0 auto;
    }
}
