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

:root {
    --bg: #e8f0fe;
    --surface: #ffffff;
    --border: #c5d5e8;
    --text: #1e293b;
    --text-muted: #546478;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --green: #16a34a;
    --blue: #2563eb;
    --orange: #d97706;
    --red: #dc2626;
    --yellow: #ca8a04;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

header {
    text-align: center;
    padding: 2.5rem 1rem 1rem;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-muted);
    margin-top: 0.3rem;
}

main {
    max-width: 500px;
    margin: 1.5rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    margin-top: 0.8rem;
}

label:first-of-type {
    margin-top: 0;
}

.optional {
    font-weight: 400;
    font-style: italic;
}

input, textarea, select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

button {
    display: block;
    width: 100%;
    padding: 0.7rem;
    margin-top: 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

button:hover {
    background: var(--accent-hover);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.result .code {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-align: center;
    color: var(--accent);
    margin: 0.5rem 0;
}

.result a {
    color: var(--accent);
    text-decoration: none;
}

.hidden {
    display: none;
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Event Map Page ---- */

#map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 60px);
}

#map {
    width: 100%;
    height: 100%;
}

#event-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: 60px;
}

#event-header h1 {
    font-size: 1.1rem;
}

#event-header .meta {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-riders {
    background: rgba(37, 99, 235, 0.12);
    color: var(--blue);
}

.badge-distress {
    background: rgba(220, 38, 38, 0.12);
    color: var(--red);
}

#sidebar {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 280px;
    max-height: calc(100% - 1rem);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    z-index: 1000;
}

#sidebar h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.distress-item {
    padding: 0.6rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
    border-left: 3px solid var(--red);
}

.distress-item .name {
    font-weight: 600;
    color: var(--red);
}

.distress-item .type {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.distress-item .time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Interval color legend */
.legend {
    display: flex;
    gap: 0.8rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.legend-dot.green { background: var(--green); }
.legend-dot.blue { background: var(--blue); }
.legend-dot.orange { background: var(--orange); }

/* Pulsing distress marker — use outline to avoid transform shift */
@keyframes pulse {
    0%, 100% { outline-width: 2px; outline-offset: 1px; }
    50% { outline-width: 5px; outline-offset: 3px; }
}

.marker-distress {
    outline: 2px solid #dc2626;
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
}

/* Bounce on hover from sidebar */
.marker-bounce {
    outline: 3px solid #dc2626;
    outline-offset: 2px;
    border-radius: 50%;
    z-index: 9999 !important;
}

/* ---- Landing page ---- */

.about p {
    margin-bottom: 0.8rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.about p:last-of-type {
    margin-bottom: 0;
}

.cta-row {
    margin-top: 1.2rem;
    text-align: center;
}

.btn {
    display: inline-block;
    padding: 0.7rem 2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}

.btn:hover {
    background: var(--accent-hover);
}

.home-link {
    text-decoration: none;
    color: inherit;
}

.muted {
    color: var(--text-muted);
}

.small {
    font-size: 0.8rem;
}

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

/* Event listing */
.event-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s;
}

.event-row:hover {
    border-color: var(--accent);
}

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

.event-name {
    font-weight: 600;
    font-size: 1rem;
}

.event-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.event-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-code {
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.15em;
    flex-shrink: 0;
    margin-left: 1rem;
}

/* Create result links */
.result-links {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.8rem;
}

.result-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.result-links a:hover {
    text-decoration: underline;
}

/* ---- Director page ---- */

.director-sidebar {
    width: 320px;
}

.distress-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #fff;
}

.btn-ack {
    background: var(--yellow);
    color: #000;
}

.btn-resolve {
    background: var(--green);
}

.btn-locate {
    background: var(--blue);
}

.btn-dispatch {
    background: #a855f7;
}

.btn-sm:hover {
    opacity: 0.85;
}

.sag-assigned {
    font-size: 0.75rem;
    color: var(--yellow);
    font-weight: 600;
    margin-top: 0.2rem;
}

.rider-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.3rem;
    background: var(--bg);
    border-radius: 6px;
    font-size: 0.85rem;
}

.rider-row.distressed {
    border-left: 3px solid var(--red);
}

.rider-row.sag-row {
    border-left: 3px solid var(--yellow);
}

.rider-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.rider-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rider-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}
