/* Light is the default; dark applies either from the OS or an explicit choice.
   Every colour is a token so the two themes never drift apart. */
:root {
  --bg:        #ffffff;
  --panel:     #ffffff;
  --panel2:    #f6f7f9;
  --panel3:    #eceff3;
  --line:      #e5e8ec;
  --line2:     #d3d9e0;
  --text:      #151b23;
  --dim:       #59636f;
  --dim2:      #8b95a1;
  --accent:    #2563eb;
  --accent-sc: #ffffff;
  --accent-bg: rgba(37,99,235,.10);
  --armenia:   #d9583c;
  --georgia:   #2563eb;
  --optional:  #7c3aed;
  --idea:      #10804f;
  --banned:    #dc2626;
  --grey:      #94a3b8;
  --warn:      #b7690a;
  --warn-bg:   #fdf6ec;
  --warn-line: #f0dcb8;
  --ok:        #05875f;
  --ok-bg:     #f0faf5;
  --ok-line:   #cbe7db;
  --map-bg:    #eaeef2;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 10px 28px rgba(16,24,40,.10);
  --shadow-sm: 0 1px 2px rgba(16,24,40,.09);
  --r:         9px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1216;
    --panel:     #151920;
    --panel2:    #1b202a;
    --panel3:    #232936;
    --line:      #262d38;
    --line2:     #333c4a;
    --text:      #e7ecf2;
    --dim:       #9aa5b2;
    --dim2:      #6f7b89;
    --accent:    #5b9bf8;
    --accent-sc: #0b1220;
    --accent-bg: rgba(91,155,248,.16);
    --armenia:   #ef7757;
    --georgia:   #5b9bf8;
    --optional:  #a684ee;
    --idea:      #35b07a;
    --banned:    #f2607a;
    --grey:      #8494a6;
    --warn:      #e0a63c;
    --warn-bg:   #241d10;
    --warn-line: #4a3a18;
    --ok:        #35b07a;
    --ok-bg:     #0f2119;
    --ok-line:   #1f4536;
    --map-bg:    #1b202a;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.45);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
  }
}

:root[data-theme="dark"] {
  --bg:        #0f1216;
  --panel:     #151920;
  --panel2:    #1b202a;
  --panel3:    #232936;
  --line:      #262d38;
  --line2:     #333c4a;
  --text:      #e7ecf2;
  --dim:       #9aa5b2;
  --dim2:      #6f7b89;
  --accent:    #5b9bf8;
  --accent-sc: #0b1220;
  --accent-bg: rgba(91,155,248,.16);
  --armenia:   #ef7757;
  --georgia:   #5b9bf8;
  --optional:  #a684ee;
  --idea:      #35b07a;
  --banned:    #f2607a;
  --grey:      #8494a6;
  --warn:      #e0a63c;
  --warn-bg:   #241d10;
  --warn-line: #4a3a18;
  --ok:        #35b07a;
  --ok-bg:     #0f2119;
  --ok-line:   #1f4536;
  --map-bg:    #1b202a;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.45);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--accent-bg); }

#app { display: flex; height: 100vh; }
#map { flex: 1; height: 100%; background: var(--map-bg); }

/* ---------- panel ---------- */
#side {
  width: 376px; flex: 0 0 376px; height: 100%;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 500;
}
#side.hidden { display: none; }

#topbar { display: flex; align-items: flex-start; gap: 10px; padding: 17px 18px 13px; }
.brand { flex: 1; min-width: 0; }
#side h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.021em; }
#side .sub { margin: 3px 0 0; color: var(--dim); font-size: 12px; }
#side .stats { margin: 2px 0 0; color: var(--dim2); font-size: 11.5px; }
.headbtns { display: flex; gap: 6px; flex: 0 0 auto; }

.icon-btn {
  background: transparent; color: var(--dim2); border: 1px solid var(--line);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer;
  font-size: 14px; line-height: 1; flex: 0 0 auto; transition: .13s;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); background: var(--panel2); border-color: var(--line2); }
#expand {
  position: fixed; top: 16px; left: 16px; z-index: 900; width: 36px; height: 36px;
  background: var(--panel); box-shadow: var(--shadow-sm); border-color: var(--line2);
}
#expand.hidden { display: none; }

/* ---------- controls ---------- */
.controls { padding: 0 18px 13px; }
.searchwrap { position: relative; }
#search {
  width: 100%; padding: 9px 12px; border-radius: var(--r); font-size: 13px;
  border: 1px solid var(--line2); background: var(--panel); color: var(--text);
  transition: .13s;
}
#search::placeholder { color: var(--dim2); }
#search:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}

#results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1100;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; padding: 5px 0;
}
.rgroup {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dim2); padding: 8px 13px 5px; font-weight: 500;
}
.ritem { display: flex; align-items: flex-start; gap: 10px; padding: 7px 13px; cursor: pointer; }
.ritem:hover { background: var(--panel2); }
.ritem .rmark {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff; margin-top: 1px;
}
.ritem .rmark.add { background: var(--accent); color: var(--accent-sc); }
.ritem .rbody { min-width: 0; flex: 1; }
.ritem .rname { font-size: 13px; }
.ritem .rdetail {
  font-size: 11px; color: var(--dim2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rnote { padding: 9px 13px; font-size: 12px; color: var(--dim2); line-height: 1.5; }

.toolbar { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
.pill {
  font-size: 12px; padding: 4.5px 11px; border-radius: 16px; cursor: pointer;
  background: var(--panel); color: var(--dim); border: 1px solid var(--line2);
  transition: .13s; white-space: nowrap;
}
.pill:hover { color: var(--text); border-color: var(--dim2); }
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-sc); }
.pill.alert { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); }
.pill.alert.on { background: var(--warn); border-color: var(--warn); color: #fff; }

.tgl { font-size: 12px; color: var(--dim); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tgl:hover { color: var(--text); }
.tgl input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; margin: 0; }
.tgl.big { font-size: 13.5px; color: var(--text); font-weight: 500; }
.tgl.big input { width: 16px; height: 16px; }
.link-btn {
  background: none; border: none; color: var(--dim2); font-size: 12px;
  cursor: pointer; padding: 0; margin-left: auto; white-space: nowrap;
}
.link-btn:hover { color: var(--accent); }

#filterPanel {
  margin-top: 11px; padding: 12px 13px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 10px;
}
.fgroup { margin-bottom: 11px; }
.flabel {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dim2); margin-bottom: 6px; font-weight: 500;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 4px 9px; border-radius: 14px; cursor: pointer;
  background: var(--panel); color: var(--dim2); border: 1px solid var(--line2); transition: .13s;
}
.chip:hover { color: var(--text); }
.chip.on { color: var(--text); border-color: var(--dim2); }
.sw { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.sw-am { background: var(--armenia); }
.sw-ge { background: var(--georgia); }

.dayctl {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--panel2);
}
.muted { font-size: 11.5px; color: var(--dim2); }

/* ---------- day list ---------- */
#list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
#list::-webkit-scrollbar { width: 10px; }
#list::-webkit-scrollbar-thumb {
  background: var(--line2); border-radius: 5px; border: 3px solid var(--panel);
}

.day { border-bottom: 1px solid var(--line); }
.day.off { background: var(--panel2); }
.day.off .dtitle, .day.off .dlabel, .day.off .dmeta, .day.off .bed { opacity: .42; }

.dayhead {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px 11px 15px; cursor: pointer; user-select: none;
  border-left: 3px solid transparent; transition: background .13s;
}
.dayhead:hover { background: var(--panel2); }
.day.armenia .dayhead { border-left-color: var(--armenia); }
.day.georgia .dayhead { border-left-color: var(--georgia); }
.dayhead input {
  accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer;
  margin: 0; flex: 0 0 auto;
}
.dh-main { flex: 1; min-width: 0; }
.dtitle { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.dlabel {
  font-size: 11.5px; color: var(--dim); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dright {
  text-align: right; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
}
.dmeta { font-size: 11px; color: var(--dim2); white-space: nowrap; }
.dmeta .km { color: var(--dim); font-weight: 500; }
.dmeta .walk { color: var(--idea); }
.bed {
  font-size: 11px; white-space: nowrap; max-width: 132px;
  overflow: hidden; text-overflow: ellipsis;
}
.bed .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
}
.bed.booked  { color: var(--ok); }
.bed.tobook  { color: var(--warn); font-weight: 500; }
.bed.neutral { color: var(--dim2); }
.caret {
  color: var(--dim2); font-size: 9px; width: 9px; text-align: center;
  transition: transform .16s; flex: 0 0 auto;
}
.day.collapsed .caret { transform: rotate(-90deg); }
.day.collapsed .stops { display: none; }

.stops { padding: 1px 0 9px; }
.item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 5px 18px 5px 22px; cursor: pointer; border-left: 3px solid transparent;
  transition: background .12s;
}
.item:hover { background: var(--panel2); }
.item.sel { background: var(--accent-bg); border-left-color: var(--accent); }
.num {
  flex: 0 0 auto; width: 19px; height: 19px; border-radius: 50%;
  font-size: 10px; font-weight: 600; color: #fff;
  display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.item .body { min-width: 0; flex: 1; }
.item .nm { font-size: 13px; }
.item.done .nm { text-decoration: line-through; color: var(--dim2); }
.item .meta { font-size: 11px; color: var(--dim2); margin-top: 1px; }
.item .flag { color: var(--warn); }
.empty { padding: 30px 18px; color: var(--dim2); text-align: center; font-size: 13px; line-height: 1.6; }

.stayrow {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 7px 18px 2px 22px; padding: 9px 11px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; transition: .13s;
}
.stayrow:hover { border-color: var(--dim2); }
.stayrow.tobook { background: var(--warn-bg); border-color: var(--warn-line); }
.stayrow.booked { background: var(--ok-bg); border-color: var(--ok-line); }
.stayrow .sicon {
  flex: 0 0 auto; width: 17px; height: 17px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff; background: var(--grey); margin-top: 1px;
}
.stayrow.tobook .sicon { background: var(--warn); }
.stayrow.booked .sicon { background: var(--ok); }
.stayrow .sbody { flex: 1; min-width: 0; }
.stayrow .swhere { font-size: 12.5px; font-weight: 500; }
.stayrow .sstate { font-size: 11px; margin-top: 1px; color: var(--dim2); }
.stayrow.tobook .sstate { color: var(--warn); }
.stayrow.booked .sstate { color: var(--ok); }
.stayrow .snote { font-size: 11px; color: var(--dim); margin-top: 4px; line-height: 1.45; }
.gmaps { font-size: 11.5px; color: var(--accent); text-decoration: none; }
.gmaps:hover { text-decoration: underline; }

/* ---------- footer ---------- */
#side footer { border-top: 1px solid var(--line); padding: 12px 18px; background: var(--panel); }
.row { display: flex; gap: 7px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.row:last-child { margin-bottom: 0; }
.btn {
  font-size: 12.5px; font-weight: 500; padding: 6.5px 12px; border-radius: 8px; cursor: pointer;
  background: var(--panel); color: var(--text); border: 1px solid var(--line2);
  text-decoration: none; display: inline-block; transition: .13s;
}
.btn:hover { background: var(--panel2); border-color: var(--dim2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-sc); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--banned); color: var(--banned); background: transparent; }
.btn.danger:hover { background: var(--banned); color: #fff; }
.btn.small { font-size: 11.5px; padding: 4.5px 9px; }
.btn.active { background: var(--warn); border-color: var(--warn); color: #fff; }
.state { font-size: 11.5px; color: var(--dim2); }
.state.on { color: var(--ok); }
.foot-note { font-size: 10.5px; color: var(--dim2); }
.hidden { display: none !important; }

/* ---------- drawers ---------- */
#editor, #stayEditor {
  position: fixed; top: 0; right: 0; width: 358px; height: 100%;
  background: var(--panel); border-left: 1px solid var(--line);
  z-index: 1200; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.ed-head {
  padding: 16px 18px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.ed-head strong { font-size: 14px; font-weight: 600; }
.ed-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.ed-body label {
  display: block; font-size: 10.5px; color: var(--dim2); margin-bottom: 13px;
  text-transform: uppercase; letter-spacing: .05em; font-weight: 500;
}
.ed-body label.inline {
  display: flex; gap: 8px; align-items: center; font-size: 12.5px;
  text-transform: none; letter-spacing: 0; color: var(--dim); font-weight: 400;
}
.ed-body input, .ed-body select, .ed-body textarea {
  width: 100%; margin-top: 5px; padding: 8px 10px; font-size: 13px;
  background: var(--panel); text-transform: none; letter-spacing: 0; font-weight: 400;
  border: 1px solid var(--line2); border-radius: 8px; transition: .13s;
}
.ed-body input:focus, .ed-body select:focus, .ed-body textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
.ed-body textarea { resize: vertical; line-height: 1.5; }
.two { display: flex; gap: 10px; }
.two label { flex: 1; }
.ed-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 9px; }
.ed-foot .btn { flex: 1; text-align: center; }

/* ---------- map ---------- */
.pin {
  width: 24px; height: 24px; border-radius: 50% 50% 50% 3px;
  transform: rotate(-45deg); border: 2px solid var(--panel);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin span { transform: rotate(45deg); font-size: 11px; line-height: 1; color: #fff; font-weight: 600; }
.pin.needs { box-shadow: 0 0 0 3px var(--warn), 0 1px 4px rgba(0,0,0,.35); }
.pin.done { opacity: .4; }
.pin.sel {
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 6px var(--accent-bg), 0 2px 6px rgba(0,0,0,.4);
  z-index: 1000;
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.leaflet-popup-content-wrapper { border-radius: 11px; }
.leaflet-popup-content { margin: 13px 15px; font-size: 13px; min-width: 210px; }
.pop-t { font-weight: 600; font-size: 14px; margin-bottom: 3px; letter-spacing: -.01em; }
.pop-m { color: var(--dim2); font-size: 10.5px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .05em; }
.pop-warn { color: var(--warn); font-size: 11.5px; margin-bottom: 7px; }
.pop-n { font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; color: var(--dim); }
.pop-b { margin-top: 11px; display: flex; gap: 6px; flex-wrap: wrap; }
.pop-b .btn { font-size: 11.5px; padding: 4px 9px; }
.leaflet-container { font-family: inherit; background: var(--map-bg); }
.leaflet-container a.leaflet-popup-close-button { color: var(--dim2); }
.leaflet-bar a, .leaflet-control-layers {
  background: var(--panel); color: var(--text);
}
.leaflet-bar a:hover { background: var(--panel2); color: var(--text); }
.leaflet-bar a.leaflet-disabled { background: var(--panel2); color: var(--dim2); }
.leaflet-control-layers, .leaflet-bar {
  border: 1px solid var(--line) !important; box-shadow: var(--shadow-sm) !important;
  border-radius: 9px !important; overflow: hidden;
}
.leaflet-bar a { border-bottom-color: var(--line); }
.leaflet-control-layers-expanded { padding: 10px 13px; font-size: 12.5px; }
.leaflet-control-layers label { margin-bottom: 3px; }
.leaflet-control-attribution {
  background: var(--panel) !important; color: var(--dim2) !important;
  font-size: 10px; border-top-left-radius: 6px;
}
.leaflet-control-attribution a { color: var(--dim) !important; }
.route-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow-sm); font-size: 11.5px; padding: 7px 10px;
}
.route-tip::before { display: none; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--panel); padding: 10px 18px; border-radius: 9px;
  z-index: 2000; font-size: 12.5px; box-shadow: var(--shadow);
}
#toast.err { background: var(--banned); color: #fff; }

body.adding #map { cursor: crosshair; }

/* ---------- mobile ---------- */
@media (max-width: 780px) {
  #app { flex-direction: column; }
  /* Everything in the panel must fit its own height or the footer bleeds over
     the map and swallows the zoom control. */
  #side {
    width: 100%; flex: 0 0 56vh; height: 56vh; overflow: hidden;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  #topbar { padding: 12px 15px 10px; }
  #side h1 { font-size: 16px; }
  .controls { padding: 0 15px 10px; }
  .dayctl { padding: 8px 15px; }
  #list { min-height: 0; }
  #side footer { padding: 10px 15px; }
  #side footer .row { margin-bottom: 6px; }
  .foot-note { display: none; }
  #filterPanel { max-height: 32vh; overflow-y: auto; }
  #map { flex: 1 1 auto; min-height: 0; }
  #editor, #stayEditor { width: 100%; }
  #expand { top: auto; bottom: 18px; left: 18px; }
}
