/* Poznámky — styl aplikace.
   Psáno mobile-first: výchozí pravidla platí pro telefon, širší rozvržení
   se zapíná až v media query na konci. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e2e0da;
  --text: #23262a;
  --text-muted: #6b7280;
  --accent: #2f6f4f;
  --accent-soft: #e6f0ea;
  --danger: #a3342b;
  --danger-soft: #fbeceb;
  --info-soft: #eef2f7;
  --radius: 10px;
  --topbar-height: 3.25rem;
  --sidebar-width: 17rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1e2125;
    --border: #32363c;
    --text: #e6e6e3;
    --text-muted: #9aa2ad;
    --accent: #79c39a;
    --accent-soft: #22312a;
    --danger: #e88b83;
    --danger-soft: #3a2523;
    --info-soft: #24282e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- horní lišta --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: var(--topbar-height);
  padding: 0 0.75rem;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  margin-right: auto;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem; height: 2.5rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover { background: var(--bg); }

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.hamburger { position: relative; }
.hamburger::before,
.hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

.space-switch select {
  max-width: 9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.logout { margin: 0; }

.topbar__search { margin: 0; flex: 1; max-width: 18rem; }

.topbar__search .field__input {
  padding: 0.35rem 0.6rem;
  font-size: 0.9rem;
}

/* --- výsledky hledání ---------------------------------------------------- */

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-form .field__input { flex: 1; }
.search-form .button--primary { width: auto; }

.result {
  padding: 0.9rem;
  margin-bottom: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.result__title {
  font-weight: 600;
  text-decoration: none;
}

.result__path {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-word;
}

.result__snippet {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  overflow-wrap: break-word;
}

.link-button {
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.4rem;
}

.link-button:hover { color: var(--text); }

/* --- rozvržení ----------------------------------------------------------- */

.shell { display: block; }

.content {
  padding: 1rem 1rem 4rem;
  padding-bottom: calc(4rem + env(safe-area-inset-bottom));
}

.body--centered .content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* --- navigace (na telefonu vysouvací panel) ------------------------------ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: min(var(--sidebar-width), 85vw);
  height: 100%;
  padding: 1rem 0.75rem 3rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.18s ease-out;
}

.sidebar.is-open { transform: none; }

.sidebar__title {
  margin: 0 0 0.75rem;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.35);
}

/* --- strom --------------------------------------------------------------- */

.tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree .tree { padding-left: 0.75rem; }

.tree__link,
.tree__summary {
  display: block;
  padding: 0.5rem 0.5rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}

/* Rozbalovací trojúhelník patří k <summary>, ale klepnutí na název kategorie
   má otevřít její přehled — proto je uvnitř ještě odkaz. */
.tree__summary {
  display: flex;
  align-items: center;
  cursor: pointer;
  list-style: none;
}

.tree__summary::-webkit-details-marker { display: none; }

.tree__summary::before {
  content: "▸";
  flex: none;
  width: 1rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.tree__folder[open] > .tree__summary::before { transform: rotate(90deg); }

.tree__folder-link {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.tree__link:hover,
.tree__summary:hover { background: var(--bg); }

.tree__link.is-current,
.tree__folder-link.is-current {
  color: var(--accent);
  font-weight: 600;
}

.tree__link.is-current { background: var(--accent-soft); }

/* --- akce v navigaci ----------------------------------------------------- */

.sidebar__actions {
  display: flex;
  gap: 0.4rem;
  margin: 0 0.5rem 1rem;
}

.sidebar__footer {
  margin: 1.5rem 0.5rem 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.popover { position: relative; }

.popover > summary {
  list-style: none;
  display: inline-block;
}

.popover > summary::-webkit-details-marker { display: none; }

.popover__body {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  width: 15rem;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.popover__body .field { margin-bottom: 0.75rem; }

/* --- obsah stránky ------------------------------------------------------- */

.page__meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.page__path {
  min-width: 0;
  word-break: break-word;
}

.page__meta .button { margin-left: auto; }

.prose {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-wrap: break-word;
}

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

.prose h1 { font-size: 1.5rem; }
.prose h2 { font-size: 1.25rem; margin-top: 1.75rem; }
.prose h3 { font-size: 1.05rem; }

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.prose pre {
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--bg);
  border-radius: 4px;
}

/* Široké tabulky se posouvají uvnitř sebe, ať se nikdy neroztáhne celá stránka. */
.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.prose th,
.prose td {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
}

.prose blockquote {
  margin: 1rem 0;
  padding-left: 0.9rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
}

/* --- hlášky a formuláře -------------------------------------------------- */

.notice,
.message {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.notice--info,
.message--info { background: var(--info-soft); }

.message--error {
  background: var(--danger-soft);
  color: var(--danger);
}

.message--success {
  background: var(--accent-soft);
  color: var(--accent);
}

.login {
  width: min(22rem, 100%);
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login__title { margin: 0 0 1.25rem; font-size: 1.35rem; }

.field { display: block; margin-bottom: 1rem; }

.field__label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field__input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  /* 16 px je minimum, při kterém iOS Safari po kliknutí do pole nezvětší stránku. */
  font: inherit;
}

.button {
  display: inline-block;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.button--primary {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.button--small {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.button--danger {
  border-color: var(--danger);
  color: var(--danger);
}

.field__hint {
  margin: 0.25rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card {
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.form-actions .button--primary { width: auto; }

/* --- výpis obsahu kategorie ---------------------------------------------- */

.folder__title { margin: 0 0 0.75rem; font-size: 1.5rem; }

.folder__heading {
  margin: 1.75rem 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.listing {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.listing__item + .listing__item { border-top: 1px solid var(--border); }

.listing__item--row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  flex-wrap: wrap;
}

.listing__item--row form { margin-left: auto; }

.listing__link {
  display: block;
  padding: 0.7rem 0.9rem;
  color: var(--text);
  text-decoration: none;
}

.listing__link:hover { background: var(--bg); }

.listing__link--folder::before {
  content: "▸ ";
  color: var(--text-muted);
}

.listing__meta {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.badge {
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  background: var(--info-soft);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.empty {
  text-align: center;
  color: var(--text-muted);
}

/* --- editor -------------------------------------------------------------- */

/* Editor si bere celou dostupnou výšku pod horní lištou — na telefonu je
   psaní v okénku vysokém pár řádků k ničemu. */
.body--editor .content {
  display: flex;
  padding: 0.75rem;
  height: calc(100dvh - var(--topbar-height));
}

.editor {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.editor__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.editor__path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.editor__status {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.editor__status--ok { color: var(--accent); }
.editor__status--error { color: var(--danger); }

.editor__save { width: auto; }

.editor__surface {
  flex: 1;
  min-height: 0;
}

/* Stránka, kterou by textový režim poškodil, se edituje jen ve zdroji —
   přepínač režimů by z ní vedl rovnou do té škody. */
.editor--forced-source .toastui-editor-mode-switch { display: none; }

/* Štítek zastupující [[odkaz]] SilverBulletu uvnitř editoru. */
.wiki-chip {
  padding: 0.05em 0.4em;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.95em;
  white-space: nowrap;
}

/* --- širší obrazovky ----------------------------------------------------- */

@media (min-width: 60rem) {
  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    transform: none;
    transition: none;
  }

  .icon-button#menu-toggle,
  .scrim { display: none; }

  .content { padding: 1.5rem 2rem 4rem; }

  .page,
  .empty { max-width: 52rem; }
}
