:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-card: #1b2029;
  --border: #262d38;
  --text: #e8ecf2;
  --text-dim: #96a0af;
  --accent: #4f8cff;
  --accent-soft: #22345a;
  --danger: #ff5f56;
  --ok: #3ecf8e;
  --warn: #ffb454;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 40px; }
.hidden { display: none !important; }

/* ── верхняя панель ───────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-icon { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── карточки и кнопки ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #1f2531; border-color: #38424f; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #6a9dff; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: #4a2320; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:hover { background: #1f2531; }
.icon-btn.danger { color: var(--danger); }

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill-ok { color: var(--ok); border-color: #1f4a37; background: #12241c; }
.pill-warn { color: var(--warn); border-color: #4a3a1c; background: #241f12; }
.pill-err { color: var(--danger); border-color: #4a2320; background: #241314; }
.pill-muted { color: var(--text-dim); }

.hint { color: var(--text-dim); font-size: 12.5px; }

/* ── диктофон ─────────────────────────────────────────────────────────── */
.recorder-row { display: flex; align-items: center; gap: 16px; }
.recorder-body { flex: 1; min-width: 0; }
.recorder-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }

.record-btn {
  position: relative;
  width: 68px; height: 68px;
  flex: 0 0 68px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.record-btn:hover { border-color: var(--accent); }
.record-dot {
  position: absolute; inset: 50% auto auto 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: var(--danger);
  transition: all 0.15s;
}
.record-btn.recording { border-color: var(--danger); animation: pulse 1.6s infinite; }
.record-btn.recording .record-dot { width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 5px; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 95, 86, 0.45); }
  70% { box-shadow: 0 0 0 14px rgba(255, 95, 86, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 95, 86, 0); }
}

.timer { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; }
#waveform { width: 100%; height: 64px; display: block; }

.composer-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.progress { margin-top: 12px; }
.progress-bar {
  height: 6px;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.15s;
}

/* ── список ───────────────────────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar select, .field input, .field select, .title-input, .raw-text, .modal-box input[type="text"] {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.toolbar input:focus, .toolbar select:focus, .field input:focus { border-color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 10px; }

.note {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.note:hover { border-color: var(--accent); }
.note-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.note-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-snippet { color: var(--text-dim); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }

.empty { text-align: center; padding: 40px 20px; color: var(--text-dim); }

/* ── подробный просмотр ───────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  overflow-y: auto;
}
.sheet-inner { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.title-input { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; }
.sheet-meta { color: var(--text-dim); font-size: 12.5px; }
#detail-audio { width: 100%; }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* кнопка правки живёт в той же строке, но прижата вправо */
.tab-edit {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  align-self: center;
}
.tab-edit:hover { color: var(--text); border-color: var(--accent); }
.tab-edit.active { color: var(--accent); border-color: var(--accent); }

.speech-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
}
.speech-box audio { flex: 1; min-width: 200px; }

.speech-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.speech-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.speech-title { font-weight: 600; font-size: 14px; }
.speech-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.speech-buttons .btn.busy { opacity: 0.6; }
.speech-options { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.speech-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); }
.speech-field select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}
.speech-field input[type="range"] { width: 140px; accent-color: var(--accent); }
.speech-field b { color: var(--text); font-variant-numeric: tabular-nums; }

.trash-list { max-height: 50vh; overflow-y: auto; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.trash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}
.trash-item .trash-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-item .trash-when { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.modal-box.wide { max-width: 640px; }

.raw-text { width: 100%; min-height: 320px; resize: vertical; line-height: 1.6; }

.markdown { line-height: 1.65; }
.markdown h2 { font-size: 17px; margin: 20px 0 8px; }
.markdown h3 { font-size: 15px; margin: 16px 0 6px; color: var(--text); }
.markdown p { margin: 10px 0; }
.markdown ul { margin: 8px 0; padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown li.task { list-style: none; margin-left: -18px; }
.markdown code { background: var(--bg-soft); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.markdown em { color: var(--text-dim); }

.alert {
  border: 1px solid #4a2320;
  background: #241314;
  color: #ffb3ae;
  padding: 12px;
  border-radius: 10px;
  font-size: 13.5px;
}
.alert.ok { border-color: #1f4a37; background: #12241c; color: #9be7c4; }

/* ── модальные окна и всплывашки ──────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}
.modal-box h2 { margin: 0 0 8px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 13.5px; color: var(--text-dim); }
.checkbox { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #232a36;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  z-index: 80;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 600px) {
  .record-btn { width: 58px; height: 58px; flex-basis: 58px; }
  .timer { font-size: 18px; }
  .brand span:last-child { display: none; }
}
