:root {
    --bg: #faf8f5;
    --fg: #222;
    --muted: #777;
    --accent: #ff385c;
    --ok: #2b8a3e;
    --warn: #c92a2a;
    --card: #fff;
    --border: #e5e3dd;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    font-size: 14px;
}

header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 20px; font-weight: 600; }
.trip-info { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.hdr-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.info { color: var(--muted); font-size: 12px; }

.btn-primary, .btn-secondary {
    font: inherit;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { filter: brightness(0.95); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-secondary {
    background: var(--card);
    color: var(--fg);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px 20px;
    height: calc(100vh - 64px - 48px); /* minus header + footer */
}

@media (max-width: 900px) {
    main { grid-template-columns: 1fr; height: auto; }
    #map { height: 400px; }
}

#map-wrap { position: sticky; top: 16px; }
#map {
    height: 100%;
    min-height: 500px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

#table-wrap { overflow: auto; background: var(--card); border-radius: 12px; border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    position: sticky;
    top: 0;
    background: var(--card);
    text-align: left;
    padding: 10px 8px;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    z-index: 2;
}
thead th:hover { background: var(--bg); }
thead th.num { text-align: right; }
thead th .sub { font-weight: 400; color: var(--muted); font-size: 11px; }
thead th.sort-asc::after { content: " ▲"; color: var(--accent); }
thead th.sort-desc::after { content: " ▼"; color: var(--accent); }

tbody tr {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
tbody tr:hover { background: var(--bg); }
tbody tr.too-few { background: #fff5f5; }
tbody tr.too-few td:first-child { border-left: 3px solid var(--warn); }
tbody tr.highlight { background: #fff9db; }

tbody td { padding: 8px; vertical-align: middle; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.photo img {
    width: 70px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}
td.name a { color: var(--fg); text-decoration: none; font-weight: 500; }
td.name a:hover { text-decoration: underline; }
td.name .added-by { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
td.notes { color: var(--muted); font-size: 12px; max-width: 180px; }
td.num.warn { color: var(--warn); font-weight: 600; }
td.like { text-align: center; }
.like-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    opacity: 0.55;
    transition: opacity 0.1s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.like-btn.liked { opacity: 1; transform: scale(1.1); }
.like-btn:hover { opacity: 0.85; }
.vote-count {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.leaflet-popup-content { margin: 10px 12px; font-size: 13px; min-width: 180px; }
.leaflet-popup-content img { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; margin-bottom: 6px; }
.leaflet-popup-content .pop-title { font-weight: 600; margin-bottom: 4px; }
.leaflet-popup-content .pop-row { color: var(--muted); font-size: 12px; margin-top: 2px; }
.leaflet-popup-content a { color: var(--accent); text-decoration: none; }

.error-row { color: var(--warn); font-style: italic; }

/* --- Footer with current-person + switch button --- */
footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    background: var(--card);
    font-size: 13px;
}
.footer-label { color: var(--muted); }
#current-person { color: var(--fg); }
.footer-hint { color: var(--muted); font-size: 12px; margin-left: auto; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* --- Login modal --- */
dialog#login-modal {
    border: none;
    border-radius: 12px;
    padding: 24px;
    width: min(440px, 92vw);
    box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
dialog#login-modal::backdrop { background: rgba(0,0,0,.5); }
#login-form h2 { margin: 0 0 4px; font-size: 20px; }

.login-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 18px;
}
.login-choice {
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    padding: 16px 10px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color .12s, transform .08s;
}
.login-choice:hover { border-color: var(--accent); }
.login-choice:active { transform: scale(0.97); }
.login-choice.active {
    border-color: var(--accent);
    background: #fff0f3;
    color: var(--accent);
}

/* --- Modal --- */
dialog#add-modal {
    border: none;
    border-radius: 12px;
    padding: 24px;
    width: min(460px, 92vw);
    box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
dialog#add-modal::backdrop { background: rgba(0,0,0,.4); }
#add-form h2 { margin: 0 0 4px; font-size: 18px; }
.modal-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
#add-form label {
    display: block;
    margin-top: 12px;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 13px;
}
#add-form .req { color: var(--accent); }
#add-form .opt { color: var(--muted); font-weight: 400; font-size: 12px; }
#add-form input, #add-form textarea {
    font: inherit;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
}
#add-form input:focus, #add-form textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.modal-name-line {
    margin: 16px 0 8px;
    font-size: 12px;
    color: var(--fg);
}
.modal-name-line .muted { color: var(--muted); }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
.form-error {
    margin: 10px 0 0;
    padding: 8px 10px;
    background: #fff0f0;
    color: var(--warn);
    border-radius: 6px;
    font-size: 13px;
}

/* --- Gate (access-denied) screen --- */
#gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.gate-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 32px;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0,0,0,.06);
}
.gate-box h1 { margin: 0 0 8px; font-size: 22px; color: var(--accent); }
.gate-box p { margin: 0; color: var(--muted); line-height: 1.5; }

/* --- Comments modal --- */
dialog#comments-modal {
    border: none;
    border-radius: 12px;
    padding: 20px;
    width: min(520px, 94vw);
    max-height: 85vh;
    box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
dialog#comments-modal::backdrop { background: rgba(0,0,0,.4); }
#comments-form h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 600;
}
.comments-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    padding-right: 4px;
}
.comments-empty {
    color: var(--muted);
    font-style: italic;
    margin: 20px 0;
    text-align: center;
}
.comment {
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
}
.comment-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 2px;
    font-size: 12px;
}
.comment-head strong { color: var(--fg); }
.comment-date { color: var(--muted); }
.comment-body { font-size: 13px; color: var(--fg); white-space: pre-wrap; word-break: break-word; }
#comments-input {
    font: inherit;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    resize: vertical;
    min-height: 56px;
}
#comments-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.comment-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
    opacity: 0.55;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: opacity 0.1s;
}
.comment-btn:hover { opacity: 0.9; }

/* --- Toast --- */
#toast {
    position: fixed;
    left: 50%;
    bottom: 70px;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 6px 18px rgba(0,0,0,.2);
    z-index: 1000;
}
