/* Personal Keep — тема Monokai (Sublime Text) */

:root {
  --bg: #272822;
  --bg-deep: #1e1f1c;
  --bg-card: #2f302a;
  --bg-card-hover: #35362f;
  --line: #3e3d32;
  --line-strong: #4f4e44;
  --fg: #f8f8f2;
  --fg-dim: #b8b8b0;
  --comment: #75715e;
  --yellow: #e6db74;
  --orange: #fd971f;
  --red: #f92672;
  --purple: #ae81ff;
  --blue: #66d9ef;
  --green: #a6e22e;
  --selection: #49483e;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --sidebar-w: 260px;
  --radius: 8px;
  --editor-font: 14px;
  --editor-lh: 1.65;
  --editor-pad-top: 24px;
  --editor-pad-bottom: 160px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

::selection { background: var(--selection); }
a { color: var(--blue); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- sidebar ---------- */

.sidebar {
  background: var(--bg-deep);
  border-right: 1px solid var(--line);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 18px;
}
.sidebar-top { display: flex; flex-direction: column; gap: 14px; }
.sidebar-body { display: flex; flex-direction: column; gap: 18px; flex: 1; }
.sidebar-toggle { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .02em;
  padding: 0 4px;
}
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.brand-count { margin-left: auto; color: var(--comment); font-weight: 400; font-size: 12px; }

.search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  padding: 7px 10px;
  outline: none;
  font: inherit;
}
.search input:focus { border-color: var(--comment); }
.search input::placeholder { color: var(--comment); }

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--comment);
  margin-bottom: 6px;
  padding: 0 4px;
  min-height: 22px;
}

/* календарь */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--fg-dim);
  font-size: 13px;
  text-transform: capitalize;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-dow {
  text-align: center;
  font-size: 10px;
  color: var(--comment);
  padding-bottom: 2px;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid transparent;
  color: var(--comment);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.cal-day:hover { border-color: var(--comment); }
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.empty:hover { border-color: transparent; }
.cal-day.l1 { background: #3b4a1f; color: var(--fg-dim); }
.cal-day.l2 { background: #52691f; color: var(--fg); }
.cal-day.l3 { background: #6e8f22; color: var(--bg-deep); }
.cal-day.l4 { background: var(--green); color: var(--bg-deep); font-weight: 600; }
.cal-day.today { border-color: var(--orange); }
.cal-day.active { outline: 2px solid var(--blue); outline-offset: -1px; }

/* сессии и теги: строки списка */
.sessions-list, .tags-list { display: flex; flex-direction: column; gap: 1px; }
.row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--fg-dim);
  text-align: left;
  width: 100%;
  cursor: pointer;
  min-height: 28px;
}
.row:hover { background: var(--bg); color: var(--fg); }
.row.active { background: var(--selection); color: var(--yellow); }
.row .hash { color: var(--comment); }
.row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .cnt { margin-left: auto; color: var(--comment); font-size: 12px; }
.row .row-actions { display: none; gap: 0; margin-left: 2px; }
.row:hover .row-actions { display: inline-flex; }
.row:hover .row-actions + .cnt, .row:hover .cnt.hide-on-hover { display: none; }
.list-empty { color: var(--comment); font-size: 12px; padding: 0 6px; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.link-btn {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 6px;
  border-radius: 6px;
  text-align: left;
}
.link-btn:hover { background: var(--bg); color: var(--fg); }

/* ---------- кнопки ---------- */

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--comment);
  font-size: 18px;
  line-height: 1;
  flex: none;
}
.icon-btn.small { width: 22px; height: 22px; font-size: 16px; }
.icon-btn.tiny { width: 18px; height: 18px; font-size: 14px; border-radius: 4px; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn.tiny svg { width: 12px; height: 12px; }
.icon-btn:hover { background: var(--selection); color: var(--fg); }
.icon-btn.on { color: var(--yellow); }
.icon-btn.danger:hover { color: var(--red); }

.text-btn {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--fg-dim);
}
.text-btn:hover { background: var(--selection); color: var(--fg); }

/* ---------- main ---------- */

.main {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view { flex: 1; min-height: 0; }
#view-feed { padding: 28px 32px 60px; overflow-y: auto; }

/* ---------- вкладки ---------- */

.tabbar {
  display: flex;
  align-items: stretch;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  flex: none;
  height: 38px;
}
.tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 0 12px;
  border-right: 1px solid var(--line);
  color: var(--comment);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: relative;
  max-width: 220px;
  flex: none;
}
.tab:hover { color: var(--fg-dim); background: var(--bg); }
.tab.active { color: var(--fg); background: var(--bg); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: var(--bg);
}
.tab.active::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--yellow);
}
.tab.home { padding: 0 12px; }
.tab.home svg { width: 16px; height: 16px; fill: currentColor; }
.tab-title { overflow: hidden; text-overflow: ellipsis; }
.tab.pinned { padding-right: 10px; max-width: 160px; }
.tab.pinned .tab-title { font-size: 12.5px; }
.tab-btn {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--comment);
  flex: none;
  font-size: 15px;
  line-height: 1;
}
.tab-btn svg { width: 12px; height: 12px; fill: currentColor; }
.tab-btn:hover { background: var(--selection); color: var(--fg); }
.tab .tab-pin { display: none; }
.tab:hover .tab-pin { display: inline-flex; }
.tab.pinned .tab-pin { display: inline-flex; color: var(--yellow); }
.tab.pinned .tab-pin:hover { color: var(--fg); }
.tab .tab-close { display: none; }
.tab:hover .tab-close, .tab.active .tab-close { display: inline-flex; }
.tab-close:hover { color: var(--red); }
.tabbar-end { display: flex; align-items: center; margin-left: auto; padding: 0 6px; flex: none; }

/* быстрый ввод */
.composer {
  max-width: 600px;
  margin: 0 auto 32px;
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
.composer textarea {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 16px;
  min-height: 44px;
}
.composer textarea::placeholder { color: var(--comment); font-family: var(--sans); }
.composer.collapsed textarea { height: 44px; overflow: hidden; }
.composer.collapsed .composer-bar { display: none; }
.composer-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 6px;
}

/* фильтры */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--selection);
  color: var(--yellow);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
}
.chip .x { color: var(--comment); }
.chip:hover .x { color: var(--red); }

/* лента */
.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--comment);
  margin: 8px 0 10px 4px;
}
.section-title + .cards { margin-bottom: 28px; }

.cards {
  columns: 240px;
  column-gap: 14px;
}
.card {
  break-inside: avoid;
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  position: relative;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.card:hover { border-color: var(--line-strong); background: var(--bg-card-hover); }
.card.open { border-color: var(--comment); }
.card-body {
  padding: 14px 16px 10px;
  max-height: 340px;
  overflow: hidden;
  position: relative;
  font-size: 13.5px;
  color: var(--fg);
  overflow-wrap: anywhere;
}
.card-body.clamped::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 48px;
  background: linear-gradient(transparent, var(--bg-card));
  pointer-events: none;
}
.card:hover .card-body.clamped::after { background: linear-gradient(transparent, var(--bg-card-hover)); }
.card-empty { color: var(--comment); font-style: italic; }

.card-foot {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 6px;
  min-height: 34px;
}
.card-date { color: var(--comment); font-size: 11px; padding-left: 8px; }
.card-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.card:hover .card-actions, .card-actions:focus-within { opacity: 1; }
.card.pinned .card-pin { opacity: 1; color: var(--yellow); }
.card-pin-mark {
  position: absolute;
  top: 8px; right: 8px;
  color: var(--yellow);
  opacity: .7;
}
.card-pin-mark svg { width: 14px; height: 14px; fill: currentColor; }

.feed-empty {
  color: var(--comment);
  text-align: center;
  padding: 60px 0;
}

/* markdown внутри карточек */
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 0 0 6px; line-height: 1.3; color: var(--yellow); }
.md h1 { font-size: 17px; }
.md h2 { font-size: 15.5px; }
.md h3, .md h4, .md h5, .md h6 { font-size: 14px; }
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md b { color: var(--orange); font-weight: 600; }
.md i { color: var(--fg-dim); }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--bg-deep); padding: 1px 5px; border-radius: 4px; color: var(--green); }
.md pre { background: var(--bg-deep); border-radius: 6px; padding: 8px 10px; margin: 0 0 8px; overflow: hidden; }
.md pre code { background: none; padding: 0; white-space: pre; display: block; }
.md blockquote { margin: 0 0 8px; padding-left: 10px; border-left: 2px solid var(--comment); color: var(--fg-dim); }
.md hr { border: 0; border-top: 1px solid var(--line-strong); margin: 8px 0; }
.md .li { margin: 0 0 2px 4px; }
.md .tag { color: var(--purple); }
.md a { color: var(--blue); text-decoration: none; }
.md a:hover { text-decoration: underline; }

/* ---------- редактор ---------- */

#view-editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-deep);
  flex: none;
}
.editor-title {
  color: var(--fg-dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}
.editor-status { color: var(--comment); font-size: 12px; margin-right: 8px; }

.editor-body {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
  font-family: var(--mono);
  font-size: var(--editor-font);
  line-height: var(--editor-lh);
  tab-size: 4;
}
.gutter {
  flex: none;
  overflow: hidden;
  padding: var(--editor-pad-top) 14px var(--editor-pad-bottom) 18px;
  text-align: right;
  color: var(--comment);
  background: var(--bg);
  user-select: none;
  min-width: 3.5ch;
}
.gutter .ln { white-space: nowrap; }
.gutter .ln.cur { color: var(--fg-dim); }
#editor-text {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 0;
  outline: none;
  resize: none;
  font: inherit;
  line-height: inherit;
  padding: var(--editor-pad-top) 36px var(--editor-pad-bottom) 4px;
  tab-size: inherit;
  caret-color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
  margin: 0;
}
.editor-mirror {
  position: absolute;
  top: 0; left: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  line-height: inherit;
  tab-size: inherit;
  padding: 0;
  margin: 0;
  border: 0;
}
.editor-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-deep);
  color: var(--comment);
  font-family: var(--mono);
  font-size: 11.5px;
  flex: none;
  white-space: nowrap;
  overflow: hidden;
}
.editor-foot #editor-meta { overflow: hidden; text-overflow: ellipsis; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-deep);
  border: 1px solid var(--line-strong);
  color: var(--fg);
  padding: 8px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
  z-index: 10;
  font-size: 13px;
}

/* ---------- смартфоны и планшеты ---------- */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; height: 100dvh; grid-template-rows: auto 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    gap: 12px;
    overflow: visible;
  }
  .sidebar-top { gap: 10px; }
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--fg-dim);
    font-size: 13px;
    background: var(--bg);
    border: 1px solid var(--line);
  }
  .sidebar-toggle .chevron { transition: transform .15s; color: var(--comment); }
  .sidebar.open .sidebar-toggle .chevron { transform: rotate(180deg); }
  .sidebar-body { display: none; }
  .sidebar.open .sidebar-body { display: flex; }
  .sidebar-footer { margin-top: 0; }
  .cal-day { aspect-ratio: auto; height: 28px; }

  .main { height: auto; min-height: 0; }
  #view-feed { padding: 16px; }
  #view-editor { height: 100%; }
  #editor-text { padding-right: 16px; }
  .gutter { padding-left: 10px; padding-right: 10px; }
  .card-actions { opacity: 1; }
  .row .row-actions { display: inline-flex; }
  .tab .tab-close { display: inline-flex; }
}

/* ---------- аккаунт ---------- */
.account { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.account-email {
  color: var(--comment);
  font-size: 12px;
  padding: 4px 6px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-actions { display: flex; gap: 2px; }
.account-actions .link-btn { flex: 1; font-size: 13px; }

/* ---------- выделение ---------- */
.editor-sel { color: var(--yellow); }
.editor-sel:empty { display: none; }
.sel-info {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--bg-deep);
  border: 1px solid var(--line-strong);
  color: var(--yellow);
  padding: 5px 12px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  z-index: 9;
  pointer-events: none;
}

/* ---------- модальные окна ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.modal-card {
  background: var(--bg-deep);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  width: min(560px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.modal-body { overflow-y: auto; padding: 8px 0; }
.hist-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 16px;
  font-size: 13px;
}
.hist-row + .hist-row { border-top: 1px solid var(--line); }
.hist-icon { font-size: 12px; color: var(--comment); text-align: center; }
.hist-row.created .hist-icon { color: var(--green); }
.hist-row.edited .hist-icon { color: var(--blue); }
.hist-row.pinned .hist-icon, .hist-row.unpinned .hist-icon { color: var(--yellow); }
.hist-row.imported .hist-icon { color: var(--purple); }
.hist-when { color: var(--fg); }
.hist-when small { color: var(--comment); margin-left: 6px; }
.hist-stat { color: var(--comment); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.hist-stat .plus { color: var(--green); }
.hist-stat .minus { color: var(--red); }
.hist-summary { padding: 6px 16px 10px; color: var(--comment); font-size: 12px; border-bottom: 1px solid var(--line); }
.hist-row.has-content { cursor: pointer; }
.hist-row.has-content:hover { background: var(--bg); }
.hist-row.selected { background: var(--selection); }
.hist-row .hist-nosnap { color: var(--comment); font-size: 11px; }
.modal-card.wide { width: min(800px, 100%); }
.hist-body { display: flex; flex-direction: column; min-height: 0; }
.hist-list { max-height: 36vh; overflow-y: auto; flex: none; }
.hist-detail { border-top: 1px solid var(--line-strong); display: flex; flex-direction: column; min-height: 0; flex: 1; }
.hist-detail-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 16px;
  font-size: 13px;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--line);
}
.text-btn.accent { color: var(--yellow); }
.text-btn.accent:hover { background: var(--selection); }
.hist-diff {
  margin: 0;
  padding: 10px 0;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  max-height: 40vh;
  min-height: 80px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.hist-diff .dl { display: block; padding: 0 16px 0 12px; }
.hist-diff .dl::before { content: attr(data-sign); display: inline-block; width: 16px; color: var(--comment); }
.hist-diff .dl.add { background: rgba(166, 226, 46, .12); color: var(--green); }
.hist-diff .dl.del { background: rgba(249, 38, 114, .12); color: var(--red); text-decoration: line-through; text-decoration-color: rgba(249, 38, 114, .5); }
.hist-diff .dl.ctx { color: var(--fg-dim); }
.hist-diff .dl.skip { color: var(--comment); text-align: center; padding: 2px 0; }
.hist-diff .dl.skip::before { content: ""; width: 0; }
.hist-diff .empty { color: var(--comment); padding: 0 16px; }

/* ---------- вход ---------- */
.auth {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--bg-deep);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.auth-card .brand { font-size: 18px; padding: 0; }
.auth-hint { color: var(--fg-dim); font-size: 13px; line-height: 1.5; }
.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--comment); }
.auth-field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  padding: 9px 11px;
  font: inherit;
  outline: none;
}
.auth-field input:focus { border-color: var(--comment); }
#auth-code { font-family: var(--mono); font-size: 20px; letter-spacing: .3em; text-align: center; }
.auth-error { color: var(--red); font-size: 13px; }
.auth-submit {
  background: var(--yellow);
  color: var(--bg-deep);
  font-weight: 600;
  padding: 10px;
  border-radius: 6px;
}
.auth-submit:hover { filter: brightness(1.08); }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-links { display: flex; justify-content: space-between; gap: 6px; }
.auth-links .link-btn { font-size: 13px; padding: 4px 6px; }

/* полоса прокрутки */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
.tabbar::-webkit-scrollbar { height: 4px; }
