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

:root {
    --primary-color: #1a5f7a;
    --primary-dark: #0d3d4d;
    --secondary-color: #57c5b6;
    --text-color: #333;
    --bg-color: #f5f5f5;
    --card-bg: #fff;
    --border-radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --focus-outline: 3px solid #ff6b35;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    z-index: 1000;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
    outline: var(--focus-outline);
}

header {
    background: var(--primary-color);
    color: white;
    padding: 1rem;
}

header nav ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

header nav a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    transition: background 0.3s;
}

header nav a:hover,
header nav a:focus {
    background: var(--secondary-color);
    color: var(--primary-dark);
    outline: var(--focus-outline);
}

header nav a[aria-current="page"] {
    background: var(--secondary-color);
    color: var(--primary-dark);
}

main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

h1, h2, h3 {
    margin-bottom: 1rem;
    color: var(--primary-dark);
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

.search-container {
    margin: 2rem 0;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.search-form input[type="text"] {
    flex: 1;
    min-width: 250px;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1rem;
}

.search-form input[type="text"]:focus {
    outline: var(--focus-outline);
    border-color: var(--primary-color);
}

.search-form button {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

.search-form button:hover,
.search-form button:focus {
    background: var(--primary-dark);
    outline: var(--focus-outline);
}

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.sala-link {
    display: block;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.5rem;
    margin-bottom: 0.75rem;
    text-decoration: none;
    color: var(--text-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

.sala-link:hover,
.sala-link:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    outline: var(--focus-outline);
}

.sala-link strong {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.sala-info {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.mapa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.admin-auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 220px);
    padding: 1rem;
}

.admin-auth-card {
    width: min(100%, 520px);
    background: linear-gradient(180deg, #ffffff 0%, #f7fbfc 100%);
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(13, 61, 77, 0.12);
    padding: 2rem;
    border: 1px solid rgba(26, 95, 122, 0.08);
}

.admin-auth-kicker {
    display: inline-block;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: rgba(87, 197, 182, 0.15);
    color: var(--primary-dark);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.admin-auth-card form {
    margin-top: 1.25rem;
}

.admin-auth-field {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 1rem;
}

.admin-auth-field label {
    font-weight: 700;
    color: var(--primary-dark);
}

.admin-auth-field input {
    width: 100%;
    padding: 0.85rem 0.95rem;
    border: 2px solid #d7e5ea;
    border-radius: 12px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.admin-auth-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(26, 95, 122, 0.12);
}

.admin-auth-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
}

.admin-auth-actions button,
.admin-auth-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0.75rem 1.2rem;
    border-radius: 12px;
    font-weight: 700;
    text-decoration: none;
}

.admin-auth-primary {
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
}

.admin-auth-primary:hover,
.admin-auth-primary:focus {
    background: var(--primary-dark);
    outline: var(--focus-outline);
}

.admin-auth-secondary {
    background: rgba(26, 95, 122, 0.08);
    color: var(--primary-dark);
}

.admin-auth-secondary:hover,
.admin-auth-secondary:focus {
    background: rgba(26, 95, 122, 0.14);
    outline: var(--focus-outline);
}

.admin-auth-note {
    margin-top: 1rem;
    color: #5b6870;
    font-size: 0.95rem;
}

.admin-auth-alert {
    margin-top: 1rem;
}

/* Mapa interativo: container responsivo e controles */
#mapa-container {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: auto;
    background: #ffffff;
    border-radius: var(--border-radius);
}

#mapa-container img#mapa-imagem {
    display: block;
    max-width: 100%;
    height: auto;
}

#mapa-container svg#mapa-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* enable per-element pointer via explicit attributes */
}

.map-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

.map-controls button {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
}

.map-controls button[aria-disabled="true"]{
    opacity:0.5; cursor:not-allowed;
}

/* Accessible controls larger targets for users with low mobility */
.accessible-control {
    padding: 0.75rem 1rem !important;
    font-size: 1rem !important;
}

.map-controls button:focus {
    outline: var(--focus-outline);
}

/* Print: ajustar mapa para caber em página A4/Letter */
@media print {
    #mapa-container {
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        page-break-inside: avoid;
    }
    #mapa-container img#mapa-imagem,
    #mapa-container svg#mapa-svg {
        max-width: 100% !important;
        height: auto !important;
        position: static !important;
    }
    .map-controls { display: none !important; }
}

.sala-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    text-align: center;
    transition: transform 0.2s;
}

.sala-card:hover {
    transform: scale(1.02);
}

/* Posicionar salas: foco e contraste para marcações acessíveis */
.sala-marker:focus {
    outline: 4px solid #ff6b35;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.sala-marker[aria-pressed="true"] {
    box-shadow: 0 0 0 4px rgba(26,95,122,0.18);
}

/* Nudge step controls: visual highlighting for selected step */
fieldset {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
}

fieldset legend {
    padding: 0 0.25rem;
    font-weight: 600;
    color: var(--primary-dark);
}

fieldset label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
}

fieldset label:hover,
fieldset label:focus-within {
    background: #f0fbff;
    border-color: rgba(26,95,122,0.12);
}

/* Use :has to highlight the label containing the checked radio (modern browsers) */
fieldset label:has(input[type="radio"]:checked) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-dark);
    box-shadow: 0 4px 10px rgba(26,95,122,0.12);
}

/* Fallback class for browsers without :has support */
.nudge-selected {
    background: var(--primary-color) !important;
    color: white !important;
    border-color: var(--primary-dark) !important;
    box-shadow: 0 4px 10px rgba(26,95,122,0.12) !important;
    animation: pulse 1.6s ease-out infinite;
}

/* Fallback: make checked radio itself more visible via accent-color */
input[type="radio"] {
    accent-color: var(--primary-color);
}

.nudge-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary-dark);
    margin-left: 0.25rem;
}

/* UI refresh: posicionar_salas specific styles */
.posicionar-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.posicionar-panel .form-section {
    background: #ffffff;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}

.nudge-controls-container {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}
.nudge-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap; /* allow buttons to wrap instead of overflowing */
    width: 100%;
}

.nudge-btn {
    background: #fff;
    border: 2px solid #d0d7da;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-dark);
    transition: all 0.12s ease-in-out;
    min-width: 120px;
    flex: 1 1 140px; /* grow/shrink to available space but keep reasonable base */
    box-sizing: border-box;
    text-align: center;
}

.nudge-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(26,95,122,0.2);
    box-shadow: 0 6px 18px rgba(26,95,122,0.06);
}

.nudge-btn:active {
    transform: translateY(0);
}

.nudge-btn .small {
    display:block; font-size:0.8rem; color:#666; font-weight:500;
}

/* Make the current selected radio label more prominent */
.nudge-selected {
    background: var(--primary-color) !important;
    color: white !important;
    border-color: var(--primary-dark) !important;
    box-shadow: 0 6px 20px rgba(26,95,122,0.12) !important;
}

/* stronger contrast for accessibility */
.nudge-selected {
    background: #0b4a5a !important; /* darker primary */
    color: #fff !important;
    border-color: #06323f !important;
}

.nudge-btn svg {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    margin-right: 0.5rem;
    fill: currentColor;
}

/* preview overlay */
.nudge-preview {
    position: absolute;
    right: 1rem;
    bottom: 6.5rem;
    background: rgba(11,74,90,0.95);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    font-weight: 700;
    z-index: 1200;
    display: none;
}

@media (max-width: 900px) {
    .nudge-preview { right: auto; left: 50%; transform: translateX(-50%); bottom: 7rem; }
}

    /* rota pulse animation */
    @keyframes rotaPulse {
        0% { transform: scale(0.6); opacity: 0.9; }
        50% { transform: scale(1.2); opacity: 0.6; }
        100% { transform: scale(1.0); opacity: 0; }
    }
    .rota-pulse {
        transform-origin: center center;
        animation: rotaPulse 1.2s ease-out forwards;
    }

/* Slightly larger, rounded save button */
.save-positions {
    background: var(--primary-color);
    color: white;
    border-radius: 10px;
    padding: 0.85rem 1rem;
    border: none;
    font-size: 1rem;
    box-shadow: 0 8px 22px rgba(26,95,122,0.12);
}

@media (max-width: 900px) {
    .nudge-controls-container { justify-content: center; }
    .nudge-buttons { flex-wrap: wrap; }
    .nudge-btn { min-width: 44%; flex: 1 1 44%; }
}

/* Pulse animation for visibility */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(26,95,122,0.18);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(26,95,122,0.0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(26,95,122,0.0);
    }
}

/* apply subtle pulse to selected nudge label */
fieldset label:has(input[type="radio"]:checked) {
    animation: pulse 1.6s ease-out infinite;
}

/* also pulse the selected marker for clarity */
.sala-marker[aria-pressed="true"] {
    animation: pulse 1.6s ease-out infinite;
}

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
    fieldset label:has(input[type="radio"]:checked),
    .sala-marker[aria-pressed="true"] {
        animation: none !important;
    }
    .rota-pulse { animation: none !important; }
}

/* Also allow an explicit DOM-level class to force reduced motion
   (used when user toggles animations in the UI). */
.force-reduced-motion fieldset label:has(input[type="radio"]:checked),
.force-reduced-motion .sala-marker[aria-pressed="true"],
.force-reduced-motion .rota-pulse {
    animation: none !important;
}

.sala-card a {
    text-decoration: none;
    color: var(--text-color);
}

.sala-card strong {
    color: var(--primary-color);
    font-size: 1.25rem;
    display: block;
    margin-bottom: 0.25rem;
}

.horario-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.horario-table th,
.horario-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.horario-table th {
    background: var(--primary-color);
    color: white;
}

.horario-table tr:hover {
    background: #f0f8ff;
}

.horario-table tr:focus-within {
    outline: var(--focus-outline);
}

.dia-section {
    margin-bottom: 2rem;
}

.dia-section h3 {
    background: var(--secondary-color);
    color: var(--primary-dark);
    padding: 0.75rem;
    border-radius: var(--border-radius);
}

.horario-item {
    background: var(--card-bg);
    border-left: 4px solid var(--primary-color);
    padding: 1rem;
    margin: 0.5rem 0;
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
}

.horario-item .horario {
    font-weight: bold;
    color: var(--primary-color);
}

.horario-item .disciplina {
    font-size: 1.1rem;
    margin: 0.25rem 0;
}

.horario-item .professor {
    color: #666;
}

.resultados-busca {
    margin-top: 2rem;
}

.resultado-item {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}

.resultado-item strong {
    color: var(--primary-color);
}

footer {
    background: var(--primary-dark);
    color: white;
    text-align: center;
    padding: 1rem;
    margin-top: auto;
}

#search-live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.sr-only {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

:focus-visible {
    outline: var(--focus-outline);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: var(--focus-outline);
}

@media (max-width: 768px) {
    header nav ul {
        flex-direction: column;
        gap: 0.5rem;
    }

    main {
        padding: 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .mapa-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .horario-table {
        font-size: 0.9rem;
    }

    .horario-table th,
    .horario-table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .search-form {
        flex-direction: column;
    }

    .search-form input[type="text"],
    .search-form button {
        width: 100%;
    }

    .mapa-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Origin marker styling for admin map */
#origin-marker {
    cursor: grab;
    touch-action: none;
}

@media (max-width: 900px) {
    #origin-marker { width: 16px; height: 16px; }
}
