:root {
    color-scheme: light dark;
    --bg: #f5f5f4;
    --panel: #ffffff;
    --line: #dcdcd8;
    --text: #1c1c1a;
    --muted: #6b6b66;
    --accent: #1b6ef3;
    --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16161a;
        --panel: #1f1f24;
        --line: #33333a;
        --text: #ececee;
        --muted: #9a9aa2;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

button {
    font: inherit;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
}

button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 6px; }

input, select, textarea {
    font: inherit;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
}

#topbar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

#topbar strong { font-size: 16px; margin-right: 4px; }
#topbar form.inline { display: contents; }
#planName { min-width: 220px; flex: 0 1 280px; }
#topbar label { color: var(--muted); display: flex; gap: 4px; align-items: center; }
.spacer { flex: 1 1 auto; }
/* stała szerokość: inaczej zmiana tekstu przesuwa przyciski pod kursorem */
#status {
    color: var(--muted);
    flex: 0 0 auto;
    width: 170px;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#status.dirty { color: var(--danger); }

#layout {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 220px 1fr 420px;
    min-height: 0;
}

aside, section { min-height: 0; display: flex; flex-direction: column; }
#plansPanel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
#schedulePanel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }

.panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--panel);
}

.panel-head h2 { font-size: 14px; margin: 0; flex: 1 1 auto; }
.panel-head span { color: var(--muted); font-size: 12px; text-align: right; }

#plansList, #pointsList, #searchResults { list-style: none; margin: 0; padding: 0; }

#plansList li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
}

#plansList li.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
#plansList li .meta { color: var(--muted); font-size: 12px; }
#plansList li .row { display: flex; gap: 6px; align-items: center; }

#mapPanel { position: relative; }
#map { flex: 1 1 auto; }

#mapTools {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

#searchInput { flex: 1 1 240px; }
.toggle { display: flex; align-items: center; gap: 4px; color: var(--muted); }

#searchResults {
    position: absolute;
    top: 52px;
    left: 12px;
    right: 12px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    z-index: 900;
}

#searchResults li { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
#searchResults li:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
#searchResults .muted { color: var(--muted); font-size: 12px; }

#pointsList li {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
}

#pointsList li.dragging { opacity: 0.45; }
.point-head { display: flex; gap: 8px; align-items: center; }

.badge {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 12px;
    cursor: grab;
}

.badge.visited { background: #2e7d32; }
.point-head input[type="text"] { flex: 1 1 auto; }
.point-times { color: var(--muted); font-size: 12px; margin: 4px 0 0 34px; }
.point-travel { color: var(--muted); font-size: 12px; margin: 2px 0 0 34px; }
.point-travel.estimated { font-style: italic; }
.point-fields { display: flex; gap: 6px; align-items: center; margin: 6px 0 0 34px; flex-wrap: wrap; }
.point-fields input[type="number"] { width: 74px; }
.point-fields input[type="time"] { width: 110px; }
.point-fields label { color: var(--muted); display: flex; gap: 4px; align-items: center; font-size: 12px; }

.notes { display: block; padding: 12px; color: var(--muted); }
.notes textarea { width: 100%; margin-top: 4px; }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: grid;
    place-items: center;
    z-index: 1000;
}

.overlay.hidden, .hidden { display: none; }

.card {
    background: var(--panel);
    padding: 20px;
    border-radius: 14px;
    width: min(420px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card.wide { width: min(760px, 94vw); }
.card h1, .card h2 { margin: 0; }
.card pre {
    margin: 0;
    padding: 10px;
    border-radius: 8px;
    background: var(--bg);
    font-size: 12px;
    overflow-x: auto;
}
.card .hint { color: var(--muted); margin: 0; font-size: 12px; }
.card .error { color: var(--danger); margin: 0; min-height: 18px; }
.card .row { display: flex; gap: 8px; align-items: center; }

#modesTable { width: 100%; border-collapse: collapse; }
#modesTable th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px; }
#modesTable td { padding: 4px; }
#modesTable input[type="text"] { width: 100%; }
#modesTable input.emoji { width: 56px; text-align: center; }
#modesTable input[type="number"] { width: 70px; }

@media (max-width: 1100px) {
    #layout { grid-template-columns: 180px 1fr 340px; }
}

@media (max-width: 860px) {
    #layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; }
    #plansPanel, #schedulePanel { border: none; border-top: 1px solid var(--line); }
}
