:root {
    --bg: #f5f3ef; --surface: #fff; --text: #1f2328; --muted: #6b6f76; --line: #e3ded4;
    --accent: #e4572e; --ok: #2e9e5b; --warn: #d48a00; --danger: #c0392b;
    --radius: 10px; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #15171a; --surface: #1e2125; --text: #e8e6e3; --muted: #9aa0a6; --line: #30353b; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* class rules with display: … must not override the hidden attribute */
body { margin: 0; background: var(--bg); color: var(--text); height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
h1, h2 { margin: 0 0 .4em; } h2 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
button, .button, select, input, textarea { font: inherit; color: inherit; }
button, .button { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: none; color: var(--muted); }
input, select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; }
textarea { resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .25rem; }
label > input, label > textarea, label > select { margin-top: .25rem; color: var(--text); font-size: .95rem; }
label.check { display: flex; gap: .5rem; align-items: center; margin: 0; color: var(--text); }
label.check input { width: auto; }

.top { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-weight: 700; font-size: 1.1rem; }
.top-actions { display: flex; gap: .6rem; align-items: center; }

.layout { flex: 1; display: grid; grid-template-columns: 280px minmax(0, 1fr) 460px; min-height: 0; }
.sidebar, .day-pane, .editor-pane { overflow-y: auto; padding: 1rem; }
.sidebar { border-right: 1px solid var(--line); }
.editor-pane { border-left: 1px solid var(--line); background: var(--surface); }
@media (max-width: 1200px) { .layout { grid-template-columns: 240px minmax(0, 1fr) 380px; } }

.side-head { display: flex; justify-content: space-between; align-items: center; margin: .4rem 0; }
.side-head button { padding: .15rem .55rem; }
.trip-list, .day-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.trip-list li { display: flex; flex-direction: column; padding: .5rem .7rem; border-radius: 8px; cursor: pointer; }
.trip-list li .name { font-weight: 600; }
.trip-list li:hover, .day-list li:hover { background: var(--line); }
.trip-list li.active, .day-list li.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.day-list li { display: grid; grid-template-columns: 44px 1fr auto; gap: .6rem; align-items: center; padding: .35rem .5rem; border-radius: 8px; cursor: pointer; }
.day-thumb { width: 44px; height: 44px; border-radius: 6px; overflow: hidden; background: var(--line); }
.day-thumb img { width: 100%; height: 100%; object-fit: cover; }
.day-date { font-weight: 600; font-size: .9rem; }
.day-info .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.badge { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; }
.badge.ok { background: var(--ok); color: #fff; } .badge.draft { background: var(--warn); color: #fff; }

.empty { max-width: 520px; margin: 10vh auto; text-align: center; }
.howto { text-align: left; line-height: 2; }
.trip-title-row { display: flex; gap: .5rem; }
.title-input { font-size: 1.4rem; font-weight: 700; border-color: transparent; background: none; padding-left: 0; }
.title-input:focus { border-color: var(--line); background: var(--surface); }
#trip-summary { margin-bottom: 1rem; }
.day-header { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: baseline; margin-bottom: .6rem; }
.map { height: 260px; border-radius: var(--radius); overflow: hidden; background: var(--line); }
.photo-toolbar { display: flex; gap: .5rem; align-items: center; margin: .8rem 0 .5rem; }
.photo-toolbar #sel-count { flex: 1; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--line); outline: 3px solid transparent; outline-offset: -3px; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.selected { outline-color: var(--accent); }
.photo.selected img { opacity: .85; }
.photo .num { position: absolute; top: 5px; left: 5px; background: var(--accent); color: #fff; font-weight: 700; font-size: .75rem; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; }
.photo .fav { position: absolute; top: 4px; right: 6px; color: #ffd400; text-shadow: 0 0 3px #000; }
.photo .vid { position: absolute; bottom: 4px; left: 6px; color: #fff; text-shadow: 0 0 3px #000; }
.photo .insert { position: absolute; bottom: 4px; right: 4px; padding: .1rem .45rem; font-size: .8rem; opacity: 0; background: rgba(0,0,0,.65); color: #fff; border: 0; }
.photo:hover .insert { opacity: 1; }

.post-tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .4rem; }
.post-tab { font-size: .82rem; padding: .3rem .6rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.post-tab.active { border-color: var(--accent); color: var(--accent); }
.ai-row { display: flex; gap: .5rem; margin-top: .5rem; }
.ai-row select { width: auto; max-width: 45%; }
.busy { margin-top: .6rem; padding: .6rem .8rem; border-radius: 8px; background: color-mix(in srgb, var(--accent) 12%, transparent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.error { margin-top: .6rem; padding: .6rem .8rem; border-radius: 8px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); white-space: pre-wrap; }
.md-tabs { display: flex; gap: .3rem; margin: .8rem 0 .3rem; }
.md-tab { font-size: .85rem; padding: .25rem .7rem; }
.md-tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
#post-body { font: 14px/1.55 ui-monospace, "SF Mono", Menlo, monospace; }
.preview { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; max-height: 60vh; overflow-y: auto; font-size: 1rem; line-height: 1.65; }
.preview img { max-width: 100%; border-radius: 8px; }
.preview figure { margin: 1rem 0; }
.save-row { display: flex; gap: .6rem; align-items: center; margin-top: .8rem; }
.save-row .check { flex: 1; }

dialog { border: 0; border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-body { padding: 1.2rem 1.4rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 10px; z-index: 5000; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.title-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .5rem; }
.title-row label:first-child { grid-column: 1 / -1; }

dialog.wide { width: min(900px, 94vw); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .settings-grid { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .4rem 1rem 1rem; margin: 0; min-width: 0; }
legend { font-weight: 600; padding: 0 .3rem; }
legend.sub { margin-top: 1rem; padding: 0; }
.hint { color: var(--muted); font-size: .8rem; margin: .3rem 0; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.dialog-body.pw { border-top: 1px solid var(--line); }
.dialog-body.pw h3 { margin: 0 0 .3rem; font-size: 1rem; }
.dialog-actions .hint { flex: 1; align-self: center; }
.login-body { align-items: center; justify-content: center; }
.login-card { width: min(360px, 92vw); background: var(--surface); padding: 1.6rem; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.12); display: flex; flex-direction: column; gap: .8rem; }
.login-card .brand { font-size: 1.3rem; text-align: center; }
.track-box { border: 1px solid var(--line); border-radius: 10px; padding: .2rem .8rem .6rem; margin-bottom: 1rem; background: var(--surface); }
.track-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.track-row label { margin: .4rem 0 0; }
.track-row label[hidden] { display: none; }
.track-row select, .track-row input { width: auto; }
#trip-mode { width: auto; align-self: center; }
.day-sep { grid-column: 1 / -1; font-weight: 600; font-size: .9rem; padding: .6rem 0 .1rem; border-bottom: 1px solid var(--line); }
.day-list li.whole { margin-bottom: .4rem; border: 1px dashed var(--line); }
.whole-icon { display: grid; place-items: center; font-size: 1.4rem; }
.seg { display: flex; flex-wrap: wrap; gap: 1rem; margin: .4rem 0 .2rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.trip-row { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: flex-end; margin: -.4rem 0 .8rem; }
.trip-row label { margin: 0; }
.trip-row input[type=date] { width: auto; }
.album-opt { padding-bottom: .5rem; }
.picker-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.picker-row label { margin: 0; }
.picker-row input, .picker-row select { width: auto; }
.pick-grid { max-height: 55vh; overflow-y: auto; margin-top: .6rem; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.photo.in-trip { opacity: .45; cursor: default; }
.photo .badge-extra { position: absolute; top: 4px; right: 4px; background: #2e86de; color: #fff; font-size: .7rem; padding: 0 .35rem; border-radius: 6px; }
.photo .remove { position: absolute; top: 4px; left: 4px; padding: 0 .4rem; font-size: .75rem; opacity: 0; background: rgba(192,57,43,.9); color: #fff; border: 0; }
.photo:hover .remove { opacity: 1; }
.photo.selected .remove { left: 32px; }
.build-progress { position: fixed; bottom: 1.2rem; right: 1.2rem; width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 5000; }
.build-progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.build-progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.build-progress .txt { font-size: .85rem; margin-top: .4rem; }

/* --- collapsible trip settings, draft banner, tab bar --- */
.trip-settings { margin: 0 0 1rem; }
.trip-settings > summary { cursor: pointer; padding: .45rem 0; font-weight: 600; list-style-position: inside; }
.trip-settings[open] > summary { margin-bottom: .4rem; }
.draft-banner { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; margin: .4rem 0; padding: .55rem .7rem; border-radius: 8px;
                background: color-mix(in srgb, var(--warn) 16%, transparent); }
.draft-banner span { flex: 1 1 12rem; font-size: .88rem; }
.tabbar, .compact-only { display: none; }
.to-editor { width: 100%; margin-top: 1rem; padding: .7rem; font-size: 1rem; }

/* touch screens: no hover, so the photo buttons are always visible and a bit bigger */
@media (hover: none) {
    .photo .insert, .photo .remove { opacity: 1; padding: .2rem .55rem; font-size: .9rem; }
}

/* --- compact layout (phone, tablet portrait): one pane at a time + tab bar --- */
@media (max-width: 1024px) {
    .lbl, #status { display: none; }
    .top { padding: .45rem .75rem; padding-top: max(.45rem, env(safe-area-inset-top)); }
    .top-actions { gap: .4rem; }
    .top-actions button, .top-actions .button { padding: .45rem .65rem; }
    .layout { display: block; overflow: hidden; }
    .sidebar, .day-pane, .editor-pane { display: none; height: 100%; border: 0; padding: .9rem .9rem 1.4rem; }
    body[data-pane="list"] .sidebar, body[data-pane="day"] .day-pane, body[data-pane="edit"] .editor-pane:not([hidden]) { display: block; }
    .compact-only { display: block; }
    .tabbar { display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
    .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem; border: 0; border-radius: 0;
                     background: none; padding: .45rem 0 .5rem; font-size: 1.25rem; color: var(--muted); }
    .tabbar button span { font-size: .72rem; }
    .tabbar button.active { color: var(--accent); }
    .tabbar button:disabled { opacity: .35; }
    /* iOS zooms into inputs below 16px */
    input, select, textarea, #post-body { font-size: 16px; }
    .trip-title-row { flex-wrap: wrap; }
    .title-input { font-size: 1.25rem; flex: 1 1 100%; }
    #trip-mode { flex: 1; }
    .map { height: 210px; }
    .photos { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
    .photo-toolbar { flex-wrap: wrap; }
    .photo-toolbar #sel-count { flex: 1 1 100%; font-size: .85rem; }
    .day-list li { padding: .45rem .5rem; }
    .day-info .small { max-width: none; }
    .ai-row select { max-width: 50%; }
    #post-body { min-height: 45vh; }
    .preview { max-height: none; }
    .save-row { position: sticky; bottom: -1.4rem; background: var(--surface); padding: .6rem 0 .8rem; margin-bottom: -1.4rem;
                border-top: 1px solid var(--line); z-index: 2; }
    .save-row button { padding: .6rem 1rem; }
    .toast { bottom: calc(4.6rem + env(safe-area-inset-bottom)); }
    .build-progress { left: .75rem; right: .75rem; width: auto; bottom: calc(4.6rem + env(safe-area-inset-bottom)); }
    .row3 { grid-template-columns: 1fr; }
    dialog, dialog.wide { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
    .dialog-body { padding: 1rem; }
    .dialog-actions { flex-wrap: wrap; }
    .pick-grid { max-height: 50dvh; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
    .track-row select, .track-row input, .trip-row input[type=date], .picker-row input, .picker-row select { width: 100%; }
    .track-row label, .picker-row label { flex: 1 1 100%; }
}

/* --- trips prepared in advance --- */
.phase { display: inline-block; margin-left: .45rem; padding: 0 .45rem; border-radius: 6px; font-size: .72rem; font-weight: 600; vertical-align: middle; }
.phase.planned { background: color-mix(in srgb, #2e86de 16%, transparent); color: #2e86de; }
.phase.live { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.day-list li.future { opacity: .7; }
.day-list li .whole-icon { font-size: 1.1rem; color: var(--muted); }
.photos-empty { grid-column: 1 / -1; padding: .6rem 0; }
.track-auto { margin-top: 1.4rem !important; }
