:root {
  --bg:      #111318;
  --surf:    rgba(26, 29, 36, .80);
  --surf2:   #22262f;
  --border:  #2a2f3a;
  --text:    #edecea;
  --dim:     #7a8394;
  --accent:  #e8a33d;
  --accentd: rgba(232, 163, 61, .15);
  --red:     #c1604d;
  --warn:    #c18a2a;
  --warnd:   rgba(193, 138, 42, .12);
  --r:       12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); min-height: 100%; }

body {
  background: transparent;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Анимированный фон ──
   Три больших размытых пятна плавно дрейфуют. Только transform → GPU, почти
   не грузит телефон. Без внешних файлов. Отключается при prefers-reduced-motion. */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bg i {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  will-change: transform;
}
.bg i:nth-child(1) {
  top: -25vmax; left: -20vmax;
  background: radial-gradient(circle at center, rgba(232, 163, 61, .20), transparent 65%);
  animation: drift1 38s ease-in-out infinite alternate;
}
.bg i:nth-child(2) {
  bottom: -30vmax; right: -25vmax;
  background: radial-gradient(circle at center, rgba(70, 130, 180, .20), transparent 65%);
  animation: drift2 46s ease-in-out infinite alternate;
}
.bg i:nth-child(3) {
  top: 25%; left: 30%;
  width: 55vmax; height: 55vmax;
  background: radial-gradient(circle at center, rgba(150, 90, 190, .14), transparent 65%);
  animation: drift3 54s ease-in-out infinite alternate;
}
@keyframes drift1 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(30vmax, 22vmax) scale(1.25); }
}
@keyframes drift2 {
  from { transform: translate(0, 0) scale(1.15); }
  to   { transform: translate(-32vmax, -20vmax) scale(.9); }
}
@keyframes drift3 {
  from { transform: translate(-12vmax, 8vmax) scale(.9); }
  to   { transform: translate(14vmax, -14vmax) scale(1.2); }
}
@media (prefers-reduced-motion: reduce) {
  .bg i { animation: none; }
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(16px, 5vw, 48px) 0;
  max-width: 680px;
  margin: 0 auto;
}
.brand {
  white-space: nowrap;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
  font-size: .85rem;
  color: var(--accent);
  letter-spacing: .08em;
}
.header-actions { display: flex; gap: 8px; align-items: center; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--dim); color: var(--text); }

.ghost-btn-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.ghost-btn-sm:hover { border-color: var(--dim); color: var(--text); }
a.ghost-btn-sm { text-decoration: none; display: inline-block; }

.danger-btn {
  background: var(--red);
  border: none;
  color: #fff;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 16px;
  cursor: pointer;
  transition: filter .15s;
}
.danger-btn:hover { filter: brightness(1.12); }

/* ── Storage warning ── */
.storage-warn {
  max-width: 680px;
  margin: 12px auto 0;
  padding: 10px clamp(16px, 5vw, 48px);
  background: var(--warnd);
  border: 1px solid var(--warn);
  border-radius: var(--r);
  color: var(--warn);
  font-size: .85rem;
}

/* ── Main ── */
main {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px clamp(16px, 5vw, 48px) 60px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Drop zone ── */
.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--r);
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accentd);
}
.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.drop-icon {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--dim);
  margin-bottom: 2px;
}
.drop-zone p { color: var(--dim); font-size: .88rem; }
.drop-hint   { font-size: .75rem !important; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(232, 163, 61, .4);
  cursor: pointer;
  font-size: inherit;
}

/* ── Progress ── */
.progress-wrap { display: flex; flex-direction: column; gap: 6px; }
.progress-info { display: flex; align-items: baseline; gap: 10px; }
.progress-name {
  flex: 1;
  min-width: 0;
  font-size: .78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .icon-btn { width: 26px; height: 26px; font-size: .75rem; }
.progress-row .icon-btn:hover { border-color: var(--red); color: var(--red); }
.progress-track {
  flex: 1;
  height: 4px;
  background: var(--surf2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .15s;
}
.progress-wrap .progress-pct {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
  font-size: .72rem;
  color: var(--dim);
  min-width: 34px;
}

/* ── Text form ── */
.text-form { display: flex; gap: 10px; align-items: flex-end; }
.text-form textarea {
  flex: 1;
  resize: vertical;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  padding: 11px 13px;
  outline: none;
  transition: border-color .2s;
  min-height: 68px;
}
.text-form textarea:focus { border-color: var(--accent); }
.text-form textarea::placeholder { color: var(--dim); }

.send-btn {
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: var(--r);
  font-weight: 600;
  font-size: .88rem;
  padding: 11px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s;
}
.send-btn:hover { filter: brightness(1.1); }

/* ── Поиск / сортировка ── */
.search-row { display: flex; gap: 8px; }
.search-row input,
.search-row select {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: .86rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color .2s;
}
.search-row input { flex: 1; min-width: 0; }
.search-row select { cursor: pointer; }
.search-row input:focus,
.search-row select:focus { border-color: var(--accent); }
.search-row input::placeholder { color: var(--dim); }
.search-row select option { background: #1a1d24; color: var(--text); }

mark {
  background: var(--accentd);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
}

/* ── Toolbar / filter ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn {
  background: var(--surf);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 500;
  padding: 5px 13px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--dim); color: var(--text); }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
}

/* ── Item list ── */
.item-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 11px 13px;
  transition: border-color .15s;
}
/* Появление — только у новых строк, иначе при каждой перерисовке мигает весь список */
.item-row.is-new { animation: pop .22s ease; }
.item-row.selected {
  border-color: var(--accent);
  background: var(--accentd);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

.item-checkbox {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.item-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surf2);
  cursor: pointer;
}
.item-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--surf2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: var(--dim);
}

.item-body { flex: 1; min-width: 0; }
.item-name {
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-text {
  font-size: .86rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
/* Свёрнутая заметка — не больше 5 строк */
.item-text.clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  overflow: hidden;
}
.note-toggle {
  background: none;
  border: none;
  padding: 2px 0 0;
  color: var(--accent);
  font: inherit;
  font-size: .74rem;
  font-weight: 600;
  cursor: pointer;
}
.note-toggle:hover { text-decoration: underline; }

/* Миниатюра видео — кадр со значком ▶ поверх */
.thumb-wrap { position: relative; flex-shrink: 0; line-height: 0; }
.thumb-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .7rem;
  line-height: 1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
  pointer-events: none;
}
/* PDF: показываем верх первой страницы (заголовок), а не середину */
.item-thumb-pdf { object-position: top; background: #fff; }
.item-icon-pdf {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--red);
}
.item-meta {
  font-size: .72rem;
  color: var(--dim);
  margin-top: 2px;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
}

.item-actions { display: flex; gap: 5px; flex-shrink: 0; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 8px;
  width: 31px;
  height: 31px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .88rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-decoration: none;
}
.icon-btn:hover     { border-color: var(--accent); color: var(--accent); }
.icon-btn.del:hover { border-color: var(--red);    color: var(--red); }

.empty-state {
  text-align: center;
  color: var(--dim);
  font-size: .86rem;
  padding: 28px 0;
}

/* ── Footer ── */
footer {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 clamp(16px, 5vw, 48px) 22px;
  display: flex;
  gap: 8px;
  justify-content: center;
  color: var(--dim);
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
  font-size: .68rem;
}
.footer-sep { opacity: .4; }
.https-link { color: var(--accent); text-decoration: none; }
.https-link:hover { text-decoration: underline; }

/* ── Окно подтверждения ── */
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.confirm-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  background: #15171d;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 4px);
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  animation: pop .18s ease;
}
.confirm-title { font-size: .95rem; font-weight: 600; color: var(--text); }
.confirm-text {
  margin-top: 6px;
  font-size: .82rem;
  color: var(--dim);
  word-break: break-word;
}
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-actions button { padding: 8px 16px; font-size: .82rem; }

/* ── Preview modal ── */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vw, 40px);
}
.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 12, .78);
  backdrop-filter: blur(3px);
}
.preview-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 920px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: #15171d;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 4px);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-title {
  font-size: .86rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-header-actions { display: flex; gap: 4px; flex-shrink: 0; }
.preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: #0d0e12;
}
.preview-media {
  max-width: 100%;
  max-height: min(72vh, 760px);
  display: block;
  object-fit: contain;
}
.preview-pdf {
  width: 100%;
  height: min(78vh, 900px);
  border: 0;
  background: #fff;
}
.preview-audio { width: 100%; max-width: 480px; margin: 40px auto; }
.preview-text {
  width: 100%;
  height: min(70vh, 760px);
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
  font-size: .82rem;
  line-height: 1.5;
  color: var(--text);
  align-self: stretch;
  box-sizing: border-box;
}
.preview-unsupported {
  padding: 48px 24px;
  color: var(--dim);
  font-size: .88rem;
  text-align: center;
}
.item-thumb[data-previewable],
.item-icon[data-previewable] {
  cursor: pointer;
}

/* Автоссылки в тексте заметок */
.note-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.note-link:hover { opacity: .85; }

/* Подсветка синтаксиса в предпросмотре текстовых/код-файлов — лёгкая,
   без внешней библиотеки: несколько общих категорий токенов. */
.tok-comment { color: #6b7280; font-style: italic; }
.tok-string  { color: #a3d977; }
.tok-number  { color: #e8a33d; }
.tok-keyword { color: #7fb3e8; }

/* ── QR-код ── */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vw, 40px);
}
.qr-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 12, .78);
  backdrop-filter: blur(3px);
}
.qr-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 320px;
  background: #15171d;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 4px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
}
.qr-panel-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .86rem;
  color: var(--text);
}
.qr-code {
  background: #fff;
  padding: 12px;
  border-radius: 10px;
  line-height: 0;
}
.qr-code svg { display: block; width: 220px; height: 220px; }
.qr-url {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Consolas', monospace;
  font-size: .76rem;
  color: var(--dim);
  word-break: break-all;
  text-align: center;
  user-select: all;
}
.qr-hint {
  margin: 0;
  font-size: .72rem;
  color: var(--dim);
  text-align: center;
  line-height: 1.4;
}

/* ── Группировка по дате ── */
.date-group-header {
  list-style: none;
  padding: 18px 2px 6px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--dim);
}
.date-group-header:first-child { padding-top: 2px; }

/* ── Редактирование заметки ── */
.item-edit-textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  background: var(--surf2);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: .86rem;
  padding: 8px 10px;
  outline: none;
  box-sizing: border-box;
}
.item-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.item-edit-actions button {
  font-family: inherit;
  font-size: .78rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surf2);
  color: var(--text);
  cursor: pointer;
}
.item-edit-actions .save-btn { background: var(--accent); border-color: var(--accent); color: #111318; font-weight: 600; }
.item-edited-mark { opacity: .7; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: var(--surf2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: .82rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .45);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.has-action {
  display: flex;
  white-space: nowrap;
  align-items: center;
  gap: 14px;
  padding: 6px 6px 6px 16px;
  max-width: calc(100vw - 32px);
}
.toast.show.has-action { pointer-events: auto; }
.toast-action {
  background: var(--accentd);
  border: none;
  border-radius: 999px;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.toast-action:hover { filter: brightness(1.2); }
.toast.err  { border-color: var(--red); color: #f0b8ac; }

.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 480px) {
  .text-form { flex-direction: column; align-items: stretch; }
  /* 16px — иначе iOS увеличивает страницу при фокусе на поле */
  .text-form textarea,
  #search-input,
  #sort-select,
  .item-edit-textarea { font-size: 16px; }
  .send-btn  { width: 100%; padding: 13px; }
  /* В шапке на телефоне — только значки (подписи есть в title/aria-label) */
  .header-actions .btn-label { display: none; }
  .header-actions .ghost-btn-sm { padding: 6px 11px; font-size: .85rem; }
  .preview-modal  { padding: 0; }
  .preview-panel  { max-width: 100%; height: 100%; border-radius: 0; }
  .preview-media,
  .preview-pdf,
  .preview-text  { height: 100%; max-height: none; }
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Страница входа ── */
.login-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 4px);
  padding: 24px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.login-card .brand { margin-bottom: 10px; }
.login-label { font-size: .8rem; color: var(--dim); }
.login-card input[type=password] {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 11px 13px;
  outline: none;
}
.login-card input[type=password]:focus { border-color: var(--accent); }
.login-card .send-btn { padding: 12px; margin-top: 4px; }
.login-card .send-btn:disabled { opacity: .6; cursor: wait; }
.login-error { color: #f0b8ac; font-size: .82rem; }
.login-hint  { color: var(--dim); font-size: .72rem; text-align: center; }

/* Выход / предупреждения о безопасности */
.security-warn {
  max-width: 680px;
  margin: 12px auto 0;
  padding: 10px clamp(16px, 5vw, 48px);
  background: rgba(193, 96, 77, .12);
  border: 1px solid var(--red);
  border-radius: var(--r);
  color: #f0b8ac;
  font-size: .82rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.security-warn span { flex: 1; }
.security-warn button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
}
.footer-link {
  background: none;
  border: none;
  color: var(--dim);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.footer-link:hover { color: var(--text); }
