/* --------------------------------------------------------------------------
   HexMex - stylesheet
   -------------------------------------------------------------------------- */

:root {
    /* The whole site - and with it the OpenStreetMap background - is light
       only: this keeps the browser from applying a dark treatment to form
       controls or scrollbars when the visitor's system is in dark mode. */
    color-scheme: light;

    --bg: #eef1f4;
    --panel: #ffffff;
    --ink: #16191d;
    --muted: #6b7480;
    --line: #d8dee5;
    --accent: #1d6fd6;
    --accent-ink: #ffffff;
    --danger: #c0392b;
    --ok: #17794c;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(16, 20, 25, 0.10), 0 6px 20px rgba(16, 20, 25, 0.05);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .6rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
code { background: #eceff3; padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }

/* --- top bar ------------------------------------------------------------ */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .55rem 1rem;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--ink);
    letter-spacing: .01em;
}

.brand img { display: block; border-radius: 6px; }

.nav, .session {
    display: flex;
    align-items: center;
    gap: .3rem;
    flex-wrap: wrap;
}

.session { margin-left: auto; }

.nav-link {
    padding: .35rem .6rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--ink);
    font-size: .92rem;
}

.nav-link:hover { background: #eef2f7; }
.nav-link.active { background: #e4ecf7; color: var(--accent); font-weight: 600; }
.nav-link.primary { background: var(--accent); color: var(--accent-ink); }
.nav-link.primary:hover { background: #175bb0; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .25rem .55rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: .85rem;
}

.chip-admin { background: #fdf1d6; border-color: #e9d5a1; }

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, .25);
    flex: none;
}

/* --- layout ------------------------------------------------------------- */
.main {
    flex: 1;
    padding: 1.2rem;
    display: block;
}

.map-page .main { padding: 0; display: flex; min-height: 0; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.2rem 1.4rem;
    max-width: 1100px;
    margin: 0 auto;
}

.card.narrow { max-width: 520px; }
.page-narrow { padding: 2rem 1rem; display: block; }
.page-narrow .card { max-width: 640px; margin: 0 auto; }

.footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .6rem 1rem;
    font-size: .82rem;
    color: var(--muted);
    border-top: 1px solid var(--line);
    background: var(--panel);
}

/* --- notices ------------------------------------------------------------ */
.flashes { padding: .8rem 1.2rem 0; }

.notice {
    padding: .6rem .8rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #f2f5f9;
    margin: 0 0 .7rem;
    font-size: .93rem;
}

.notice.error { background: #fdeceb; border-color: #f2c3bf; color: #8c2019; }
.notice.success { background: #e8f6ee; border-color: #b7e0c9; color: var(--ok); }

.setup-log { list-style: none; padding: 0; margin: 0 0 1rem; }
.setup-log li { padding: .3rem 0 .3rem 1.4rem; position: relative; }
.setup-log li::before { position: absolute; left: 0; }
.setup-log li.ok::before { content: "\2713"; color: var(--ok); }
.setup-log li.bad::before { content: "\2717"; color: var(--danger); }

/* --- forms -------------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: .8rem; max-width: 420px; }
.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; font-weight: 600; }
.form label .muted { font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="file"], select {
    padding: .5rem .6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font: inherit;
    color: inherit;
    width: 100%;
}

input[type="color"] {
    width: 56px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.color-row { flex-direction: row !important; align-items: center; gap: .7rem !important; }

.button {
    display: inline-block;
    padding: .5rem .9rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.button:hover { background: #175bb0; }
.button.small { padding: .3rem .6rem; font-size: .85rem; }
.button.ghost { background: #eef2f7; color: var(--ink); border-color: var(--line); }
.button.ghost:hover { background: #e2e8f0; }
.button.danger { background: var(--danger); }
.button.danger:hover { background: #9d2c20; }

.inline-form { display: flex; gap: .35rem; align-items: center; margin: 0; }
.inline-form input[type="text"] { min-width: 8rem; }

/* --- tables ------------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    margin: .6rem 0 1rem;
    font-size: .92rem;
}

.table th, .table td {
    text-align: left;
    padding: .45rem .5rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table th { color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #f7f9fb; }
.table-scroll { overflow-x: auto; }
.table input[type="text"], .table input[type="email"], .table input[type="password"], .table select { min-width: 8rem; }
.nowrap { white-space: nowrap; }
.tiny { width: 5.5rem !important; min-width: 0 !important; }

/* --- admin -------------------------------------------------------------- */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: 0 0 1rem; border-bottom: 1px solid var(--line); }

.tab {
    padding: .45rem .8rem;
    text-decoration: none;
    color: var(--muted);
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-size: .9rem;
}

.tab:hover { background: #f2f5f9; }
.tab.active { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 600; margin-bottom: -1px; }

.row-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .6rem;
    max-width: none;
    margin: 0 0 1rem;
}

.row-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; font-weight: 600; }
.row-form label.check { flex-direction: row; align-items: center; margin: 0 0 .35rem; }
.row-form input[type="text"], .row-form input[type="email"], .row-form input[type="password"] { width: 11rem; }

.pager { display: flex; gap: .25rem; flex-wrap: wrap; }
.page { padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; font-size: .85rem; }
.page.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- map ---------------------------------------------------------------- */
.map-layout {
    display: flex;
    width: 100%;
    min-height: 0;
    flex: 1;
}

.map-sidebar {
    width: 290px;
    flex: none;
    padding: 1rem;
    background: var(--panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.panel { margin-bottom: 1.4rem; }
.panel h2 { margin: 0 0 .5rem; font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.check { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; font-size: .92rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.hint { font-size: .82rem; color: var(--muted); margin: .6rem 0 0; }

.legend { display: flex; flex-direction: column; gap: .15rem; }

.legend-row {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .2rem .25rem;
    border-radius: 6px;
    font-size: .9rem;
    cursor: pointer;
}

.legend-row:hover { background: #f2f5f9; }
.legend-rank { width: 1.5rem; text-align: right; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-name.is-me { font-weight: 700; }
.legend-count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; }
.legend-actions { display: flex; gap: .35rem; margin-top: .5rem; }

.map-stage { position: relative; flex: 1; min-width: 0; }

#hexmap {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    background: #f4f6f8;
    touch-action: none;
    /* Never invert or dim the OpenStreetMap tiles drawn onto the canvas. */
    filter: none;
}

#hexmap.dragging { cursor: grabbing; }

.map-tooltip {
    position: absolute;
    z-index: 5;
    pointer-events: none;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: .4rem .55rem;
    font-size: .82rem;
    max-width: 240px;
}

.map-status, .map-attribution {
    position: absolute;
    background: rgba(255, 255, 255, .9);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .25rem .7rem;
    font-size: .78rem;
    color: var(--muted);
}

.map-status { top: .7rem; left: .7rem; }
.map-attribution { bottom: .7rem; right: .7rem; }

/* --- small screens ------------------------------------------------------ */
@media (max-width: 800px) {
    .map-layout { flex-direction: column; }
    .map-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); max-height: 45vh; }
    .map-stage { min-height: 55vh; }
    .session { margin-left: 0; }
}
