/* barvy: light-dark(svetla, tmava); rezim urcuje color-scheme (auto = podle systemu) */
:root {
  color-scheme: light dark;
  --desk: light-dark(#cfc6b4, #161512);
  --paper: light-dark(#fffdf6, #24221e);
  --card: light-dark(#fff, #2f2c27);          /* zvednuta/upravovana karta, pole formulare */
  --code: light-dark(#f3efe4, #302d28);
  --border: light-dark(#d8cfbd, #45413a);
  --rule: light-dark(#dfe8f1, #34322d);
  --margin: light-dark(#f2b8b5, #6e3a38);
  --ink: light-dark(#2b2b2b, #e6e1d6);
  --muted: light-dark(#9a958a, #8f897c);
  --accent: light-dark(#3a6ea5, #7fa8d9);
  --go-right: #3a6ea5;
  --go-left: #4f8a5b;
  --prio: light-dark(#d22d2d, #ff6464);
  --age: var(--prio);      /* "+X" = stejna cervena jako prosle datum a priorita */
  --fold1: light-dark(#d6cdb7, #3a3731);      /* ohnuty roh */
  --fold2: light-dark(#efe8d6, #2e2b27);
  --fold3: light-dark(#fbf8ef, #26241f);
  --toast: light-dark(#2b2b2b, #3b3833);
  --sel: light-dark(#e6eef8, #2c3542);         /* vybrany ukol (klavesnice) */
  --search: light-dark(#7b4fae, #b892e6);      /* pole v rezimu hledani */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--desk); }

/* --- sesit: vodorovne posuvne strany (PC 2 vedle sebe, mobil 1) --- */
:root { --gap: 1.5rem; }
/* sesit presne na vysku okna: odsazeni pres padding (margin by "propadl" z body ven) */
body.notebook { padding-top: var(--gap); overflow: hidden; }
.book-wrap { position: relative; max-width: 1200px; margin: 0 auto; }
.book {
  display: flex;
  height: calc(100dvh - 2 * var(--gap));
  box-shadow: 0 12px 40px rgba(0,0,0,.25); border-radius: 6px;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.book::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 50%; scroll-snap-align: start;
  overflow-y: auto; min-width: 0;
  /* cervena okrajova linka jako pozadi; "local" = posouva se s obsahem -> pres celou delku */
  background: linear-gradient(to right, transparent 2.4rem, var(--margin) 2.4rem,
              var(--margin) calc(2.4rem + 2px), transparent calc(2.4rem + 2px)) var(--paper);
  background-attachment: local;
  padding: 1.5rem 1.5rem 3rem 3.2rem;
  position: relative;
}
.page + .page { box-shadow: inset 18px 0 24px -18px rgba(0,0,0,.35); }   /* hrbet */
.book.flipping, .book.flipping * { cursor: grabbing !important; user-select: none; }

/* PC: listovani tazenim (nadpis = "uchop") a ohnutym rohem */
@media (min-width: 761px) {
  .page-head { cursor: grab; }
}
.corner {
  position: absolute; top: 0; z-index: 3; display: none;
  width: 2.6rem; height: 2.6rem; padding: 0; border: 0; cursor: pointer;
  transition: width .15s ease, height .15s ease;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.25));
}
.corner-next {
  right: 0; border-radius: 0 6px 0 0;
  background: linear-gradient(225deg, var(--desk) 0 50%, var(--fold1) 50%, var(--fold2) 62%, var(--fold3) 100%);
  border-bottom-left-radius: 6px;
}
.corner-prev {
  left: 0; border-radius: 6px 0 0 0;
  background: linear-gradient(135deg, var(--desk) 0 50%, var(--fold1) 50%, var(--fold2) 62%, var(--fold3) 100%);
  border-bottom-right-radius: 6px;
}
.corner:hover, .corner:focus-visible { width: 3.6rem; height: 3.6rem; outline: none; }
@media (min-width: 761px) { .corner.show { display: block; } }

.page-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1rem; }
.page-head h1 {
  margin: 0; font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 600;
}
.date { color: var(--muted); }

.add input {
  width: 100%; font: inherit; font-size: 1.05rem;
  padding: .6rem .2rem; border: 0; border-bottom: 2px solid var(--accent);
  background: transparent; outline: none;
}
.add input::placeholder { color: var(--muted); }

/* --- ukoly --- */
.tasks { list-style: none; margin: .5rem 0 0; padding: 0; }
.task { position: relative; overflow: hidden; border-bottom: 1px solid var(--rule); touch-action: pan-y; }
.row {
  position: relative; z-index: 1; background: var(--paper);
  display: flex; align-items: center; gap: .7rem;
  padding: .7rem .2rem; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; transition: box-shadow .15s;
}
/* preskupovani: zvednuta karta */
.task.lifted { overflow: visible; z-index: 5; }
.task.lifted .row { box-shadow: 0 6px 18px rgba(0,0,0,.22); background: var(--card); transform: scale(1.02); }
.task.lifted .hint { display: none; }
.task.shift { transition: transform .15s ease; }
body.reordering, body.reordering * { cursor: grabbing !important; }
.check { width: 1.25rem; height: 1.25rem; flex: none; accent-color: var(--accent); cursor: pointer; }
.title {
  flex: 1; min-width: 0; color: inherit; text-decoration: none;
  overflow-wrap: anywhere; -webkit-user-drag: none;
}
.has-notes, .repeat { color: var(--muted); }
.age {
  flex: none; font-size: .8rem; font-weight: 600; color: #fff; background: var(--age);
  border-radius: 999px; padding: .1rem .45rem;
}
.due { flex: none; font-size: .8rem; color: var(--accent); white-space: nowrap; }
.due.overdue { color: var(--prio); font-weight: 700; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task.done .row { opacity: .75; }
.empty { color: var(--muted); padding: .8rem .2rem; font-style: italic; }

.hint {
  position: absolute; inset: 0; display: none; align-items: center;
  padding: 0 1rem; color: #fff; font-weight: 600; opacity: .55;
}
.hint-right { background: var(--go-right); justify-content: flex-start; }
.hint-left { background: var(--go-left); justify-content: flex-end; }
.task.dir-right .hint-right, .task.dir-left .hint-left { display: flex; }
.task.armed .hint { opacity: 1; }
.hint-prio { background: var(--prio); }
/* priorita */
.prio-high .title { font-weight: 700; }
.prio { color: var(--prio); font-weight: 800; margin-right: .35em; }
.task.done .prio { color: var(--muted); }

/* --- uzky displej: jedna strana --- */
@media (max-width: 760px) {
  :root { --gap: 0px; }
  .book { border-radius: 0; box-shadow: none; }
  .page { flex-basis: 100%; scroll-snap-stop: always; padding: 1rem .75rem 3rem; }
  .page + .page { box-shadow: none; }
  .page { background-image: none; }    /* bez cervene okrajove linky - setri sirku */
  .page-head h1 { font-size: 1.6rem; }
}

/* --- detail ukolu --- */
.sheet {
  max-width: 760px; margin: 2rem auto; padding: 1.5rem 2rem 2rem;
  background: var(--paper); border-radius: 6px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
@media (max-width: 760px) { .sheet { margin: 0; min-height: 100dvh; border-radius: 0; padding: 1rem; } }
.back { color: var(--accent); text-decoration: none; }
.sheet h1 { font-family: Georgia, serif; margin: .8rem 0 1rem; overflow-wrap: anywhere; }
.sheet h1.done { text-decoration: line-through; color: var(--muted); }
.md { line-height: 1.55; overflow-wrap: anywhere; }
.md pre { background: var(--code); padding: .8rem; overflow-x: auto; border-radius: 4px; }
.md code { background: var(--code); padding: .1rem .3rem; border-radius: 3px; }
.md pre code { padding: 0; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--rule); padding: .3rem .6rem; }
.md blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--rule); color: var(--muted); }
.md img { max-width: 100%; }
/* cteni / uprava: prepina trida .editing na .sheet (editor.js) */
.sheet:not(.editing) .edit-only, .sheet.editing .view-only { display: none !important; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.bar > span { display: flex; align-items: center; gap: 1.2rem; }
.bar .link, .edit .link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.bar .save {
  font: inherit; padding: .4rem 1.2rem; border: 0; border-radius: 4px; background: var(--accent); color: #fff; cursor: pointer;
}
/* uprava: na PC sirka celeho sesitu, vyska okna; pole poznamky vyplni zbytek */
.sheet.editing {
  max-width: 1200px; margin: var(--gap) auto; height: calc(100dvh - 2 * var(--gap));
  display: flex; flex-direction: column; padding-bottom: 1rem;
}
@media (max-width: 760px) { .sheet.editing { margin: 0; height: 100dvh; min-height: 0; } }
body:has(> .sheet.editing) { display: flow-root; }     /* okraj .sheet nepropadne pres body (jinak +gap scroll) */
.edit { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: .6rem; }
.edit label { display: block; margin: .4rem 0; color: var(--muted); font-size: .9rem; }
.edit input:not(.tick), .edit textarea, .edit select {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-size: 1rem; color: var(--ink);
  padding: .5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--card);
}
.edit select { width: auto; }
.fields-row { display: flex; flex-wrap: wrap; gap: 0 1.6rem; align-items: flex-end; }   /* nazev, datum, priorita, opakovani */
.fields-row .title-field { flex: 1 1 18rem; }
.fields-row label[hidden] { display: none; }
.due-edit { display: flex; align-items: center; gap: .8rem; margin-top: .3rem; }
.due-edit input { width: auto; margin-top: 0; }
.due-line { color: var(--muted); margin: -.5rem 0 1rem; }
.due-line strong { color: var(--ink); }
.notes-head { display: flex; justify-content: space-between; margin-top: .6rem; color: var(--muted); font-size: .9rem; }
.edit textarea, .edit .preview, .edit .cm-host { flex: 1; min-height: 6rem; margin-top: .3rem; }
/* CodeMirror (jen PC, app/static/cm.js): vzhled jako pole formulare, text proporcionalne */
.edit .cm-host { border: 1px solid var(--border); border-radius: 4px; background: var(--card); overflow: hidden; }
.edit .cm-host[hidden] { display: none; }
.cm-host .cm-editor { height: 100%; }
.cm-host .cm-editor.cm-focused { outline: none; }
.cm-host:focus-within { border-color: var(--accent); }
.cm-host .cm-scroller { font: 1rem/1.5 system-ui, sans-serif; padding: .3rem .2rem; }
.cm-host .cm-cursor { border-left-color: var(--ink); }
.cm-host .cm-placeholder { color: var(--muted); }
.edit textarea { font-family: ui-monospace, monospace; resize: none; line-height: 1.45; }
.edit .preview { overflow-y: auto; border: 1px dashed var(--border); border-radius: 4px; padding: .5rem .8rem; }
.edit .preview[hidden], .edit textarea[hidden] { display: none; }
.foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem 2rem; margin-top: .6rem; }
.foot form { margin: 0; }
.foot .danger { font: inherit; background: none; border: 0; padding: 0; color: var(--age); cursor: pointer; }
.keys-help { display: grid; grid-template-columns: auto 1fr; gap: .1rem .8rem; margin: 0; font-size: .8rem; color: var(--muted); flex: 1; }
.keys-help dt { font-family: ui-monospace, monospace; white-space: nowrap; }
.keys-help dd { margin: 0; }
@media (max-width: 760px) { .keys-help { display: none; } }
/* zaskrtavaci seznam "- [ ]" */
.md li:has(> .tick, > p > .tick) { list-style: none; }
.md .tick { width: 1.05rem; height: 1.05rem; margin: 0 .45rem 0 -1.4rem; vertical-align: -.15rem; accent-color: var(--accent); cursor: pointer; }
.md li:has(> .tick:checked) { color: var(--muted); text-decoration: line-through; }
main:focus { outline: none; }

/* uprava nazvu primo v seznamu */
.title-edit {
  flex: 1; min-width: 0; font: inherit; color: inherit; padding: .15rem .3rem; margin: -.15rem 0;
  border: 0; border-bottom: 2px solid var(--accent); background: var(--card); outline: none;
}
.task.editing .row { background: var(--card); }

/* lista Zpet */
#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 20;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 1.2rem; white-space: nowrap;
  background: var(--toast); color: #fff; padding: .7rem 1rem .7rem 1.2rem; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: auto;
  animation: toast-life 6s ease forwards;
}
.toast button {
  font: inherit; font-weight: 700; color: #ffd36b; background: none; border: 0;
  padding: .2rem .4rem; cursor: pointer; text-transform: uppercase; letter-spacing: .04em;
}
@keyframes toast-life {
  0% { opacity: 0; transform: translateY(10px); }
  5%, 85% { opacity: 1; transform: none; }
  100% { opacity: 0; visibility: hidden; }
}

/* --- nastaveni: barevny rezim a skryvani hotovych --- */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
.hide-done .page:not(.history):not(.page-list) li.task.done { display: none; }   /* seznam: hotove videt */
body:not(.searching).hide-done .page:not(.history):not(.page-list) .tasks:has(li.done):not(:has(li.task:not(.done)))::after {
  content: "Nic tu není."; display: block; color: var(--muted); padding: .8rem .2rem; font-style: italic;
}
.gear {
  position: fixed; z-index: 15;
  right: max(.8rem, env(safe-area-inset-right)); bottom: max(.8rem, env(safe-area-inset-bottom));
  width: 2.6rem; height: 2.6rem; padding: .55rem; border: 0; border-radius: 50%; cursor: pointer;
  color: var(--muted); background: color-mix(in srgb, var(--paper) 85%, transparent);
  box-shadow: 0 2px 8px rgba(0,0,0,.18); opacity: .75;
}
.gear:hover, .gear:focus-visible { opacity: 1; color: var(--ink); }
.gear svg { width: 100%; height: 100%; display: block; }
.settings {
  border: 0; border-radius: 10px; padding: 1.2rem 1.4rem 1.4rem;
  width: min(24rem, calc(100vw - 2rem));       /* pevna sirka: dlouhe texty se zalomi */
  background: var(--paper); color: var(--ink); box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.settings::backdrop { background: rgba(0,0,0,.35); }
.settings header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
.settings h2 { margin: 0; font-family: Georgia, serif; font-size: 1.3rem; }
.settings .close { font-size: 1.4rem; line-height: 1; border: 0; background: none; color: var(--muted); cursor: pointer; }
.settings fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.settings legend { color: var(--muted); font-size: .9rem; margin-bottom: .4rem; }
.settings label { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; cursor: pointer; }
.settings input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; margin: 0; }

/* --- vyber ukolu klavesnici --- */
.task.selected .row { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }

/* --- hledani (pole pro novy ukol zacinajici / nebo ?) --- */
.add input.search {
  border-bottom-color: var(--search); color: var(--search);
  padding-left: 1.6rem; background: no-repeat .1rem 50% / 1.1rem
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a958a' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E");
}
li.task.nomatch { display: none; }
body.searching li.empty { display: none; }
body.searching .tasks:not(:has(li.match))::after {
  content: "Nic nenalezeno."; display: block; color: var(--muted); padding: .8rem .2rem; font-style: italic;
}

/* --- napoveda klavesovych zkratek v nastaveni (jen zarizeni s mysi/klavesnici) --- */
.hotkeys, .fold-section { border-top: 1px solid var(--rule); padding: .8rem 0; }
.hotkeys summary, .fold-section summary { cursor: pointer; color: var(--accent); }
.pw-form label { display: block; margin: .6rem 0; color: var(--muted); font-size: .9rem; padding: 0; }
.pw-form input {
  display: block; width: 100%; height: auto; margin-top: .25rem; font: inherit; font-size: 1rem; color: var(--ink);
  padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--card);
}
.pw-form button {
  font: inherit; padding: .45rem 1.1rem; border: 0; border-radius: 4px; margin-top: .3rem;
  background: var(--accent); color: #fff; cursor: pointer;
}
.pw-note { font-size: .85rem; color: var(--muted); border-left: 3px solid var(--prio); padding-left: .6rem; }
.pw-msg { margin: .6rem 0 0; font-size: .9rem; }
.pw-msg.error { color: var(--prio); }
.pw-msg.ok { color: var(--go-left); }
.hotkeys dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; margin: .8rem 0 0; font-size: .9rem; }
.hotkeys dt { white-space: nowrap; }
.hotkeys dd { margin: 0; color: var(--muted); }
kbd {
  font: .8rem ui-monospace, monospace; padding: .1rem .35rem; border-radius: 4px;
  border: 1px solid var(--border); background: var(--card); box-shadow: 0 1px 0 var(--border);
}
@media (hover: none) and (pointer: coarse) { .hotkeys { display: none; } }

/* --- prihlaseni --- */
.login { max-width: 22rem; margin-top: 12vh; }
.login label { display: block; margin: 1rem 0; color: var(--muted); font-size: .9rem; }
.login input {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-size: 1rem; color: var(--ink);
  padding: .5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--card);
}
.login button {
  font: inherit; padding: .55rem 1.4rem; border: 0; border-radius: 4px; margin-top: .5rem;
  background: var(--accent); color: #fff; cursor: pointer;
}
.login .error { color: var(--prio); }
@media (max-width: 760px) { .login { margin-top: 0; } }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; padding: .8rem 0; border-top: 1px solid var(--rule); font-size: .9rem; color: var(--muted); }
.account strong { color: var(--ink); }
.account form { margin: 0; }
.account .link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.version { margin: .6rem 0 0; font-size: .8rem; color: var(--muted); }
.version .debug { font-family: monospace; font-size: .75rem; overflow-wrap: anywhere; }

/* --- DONE / TRASH (historie) --- */
.page-tools { margin: -.4rem 0 .6rem; text-align: right; font-size: .9rem; }
.page-tools .link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.page-tools .danger { color: var(--age); }
li.group { list-style: none; margin: 1rem 0 .2rem; color: var(--muted); font-size: .8rem;
           text-transform: uppercase; letter-spacing: .05em; }
li.group:first-child { margin-top: 0; }
body.searching li.group { display: none; }
.history li.task.done .title { text-decoration: none; color: var(--ink); opacity: .8; }
#trash li.task .title { color: var(--muted); }
.muted { color: var(--muted); }

/* Seznamy (SHELF) a aktualni seznam (LIST) - vlevo od Today */
.shelf-item .row { min-height: 2.4rem; }
.shelf-item .title { font-weight: 500; }
.shelf-item.current .title { color: var(--accent); }
.shelf-item.current .title::before { content: "▸ "; }
.shelf-item .count { margin-left: auto; color: var(--muted); font-size: .85rem; }
#list-name[data-id]:not([data-id=""]) { cursor: text; }
.list-name-edit { font: inherit; text-transform: none; letter-spacing: normal; width: 100%; padding: 0 .2rem; }
