:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a7de1);
  --danger: var(--tg-theme-destructive-text-color, #d93d3d);
  --warn: #d98a00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17181c; --bg2: #22242a; --text: #ececf0; --hint: #8d8f98; --accent: #4a9af0;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { max-width: 1100px; margin: 0 auto; padding: 12px 16px 40px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
input, textarea { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid transparent; border-radius: 10px; padding: 8px 10px; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
h1 { font-size: 19px; margin: 0; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 0 6px; font-weight: 600; }
.hint { font-size: 13px; color: var(--hint); margin: 4px 0; }
.warn { color: var(--warn); }
.note { background: var(--bg2); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }

/* кнопки */
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 10px; background: var(--bg2); color: var(--link); font-size: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.other { display: inline-flex; gap: 6px; align-items: center; }
.other input { padding: 6px 8px; }

/* календарь */
.month-nav { display: flex; align-items: center; gap: 4px; margin: 0 auto 12px; max-width: 520px; }
.month-nav h1 { text-align: center; flex: 1; }
.nav { width: 44px; height: 44px; font-size: 26px; border-radius: 50%; color: var(--link); }
.nav:disabled { color: var(--hint); opacity: .35; }
.pencil { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text); margin-left: 6px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 520px; margin: 0 auto; }
.weekdays span { text-align: center; font-size: 12px; color: var(--hint); padding-bottom: 4px; }
.cell { position: relative; aspect-ratio: 1; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.cell:disabled { color: var(--hint); opacity: .35; }
.cell.empty { color: var(--hint); }
.cell.empty:active { background: var(--bg2); }
.cell.has { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.cell.has:active { opacity: .8; }
.cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.has.today { box-shadow: inset 0 0 0 2px var(--accent-text), 0 0 0 2px var(--accent); }
.cell .badge { position: absolute; top: 2px; right: 4px; font-size: 11px; line-height: 1; color: var(--warn); background: var(--bg); border-radius: 6px; padding: 1px 2px; }
.legend { max-width: 520px; margin: 14px auto 0; font-size: 13px; color: var(--hint); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); vertical-align: -1px; }
.todo { max-width: 520px; margin: 0 auto; }
.todo-item { background: var(--bg2); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.todo-title { font-size: 13px; color: var(--hint); }
.todo-preview { margin-top: 2px; overflow-wrap: anywhere; }
.done-line { margin-top: 4px; color: var(--link); }

/* день */
.day-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; align-items: flex-start; }
.back { color: var(--link); padding: 4px 0; }
.day-layout { display: flex; flex-direction: column; gap: 18px; }
@media (min-width: 760px) {
  .day-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .voices { order: 2; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
  .card { order: 1; }
}
.voices h2 { margin-top: 0; }
.voices ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.voice { background: var(--bg2); border-radius: var(--radius); padding: 10px 12px; }
.voice.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }
.voice-head { width: 100%; text-align: left; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; font-size: 13px; color: var(--hint); }
.voice-head .chev { margin-left: auto; transition: transform .15s; }
.voice.open .voice-head .chev { transform: rotate(90deg); }
.tag { font-size: 12px; }
.voice .text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
.voice:not(.open) .text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice:not(.open) .actions { display: none; }
.edit-area { width: 100%; resize: vertical; margin-top: 6px; }
.progress { margin-top: 8px; color: var(--hint); }
.progress::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; border: 2px solid var(--hint); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.card .banner { background: var(--bg2); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; }
.card > .hint { margin-bottom: 12px; }
.sec { margin-bottom: 18px; }
.sec h3 { font-size: 16px; margin: 0 0 6px; font-weight: 600; }
.sec p, .sec ul { margin: 0 0 6px; }
.sec ul { padding-left: 20px; }
.sec .none { color: var(--hint); }
.sec .pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.src { cursor: pointer; border-radius: 6px; }
.src:active { background: var(--bg2); }
.mark { font-size: 12px; color: var(--hint); white-space: nowrap; }
.mark::before { content: " · "; }
.earlier { font-size: 13px; color: var(--warn); }
.block { margin-bottom: 8px; }
.block-head { font-size: 13px; color: var(--hint); margin: 0 0 2px; }
.row { margin: 0 0 4px; }
.row .k { color: var(--hint); }

/* новая запись */
.compose { display: flex; flex-direction: column; gap: 8px; max-width: 720px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--hint); align-self: flex-start; }
#compose-text { width: 100%; min-height: 200px; resize: vertical; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.compose-foot .actions { margin-top: 0; }
.hint.warn { color: var(--danger); }
.result { max-width: 720px; }
.result h2:first-child { margin-top: 0; color: var(--text); font-size: 16px; text-transform: none; letter-spacing: 0; }

.status { text-align: center; color: var(--hint); margin-top: 40px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); z-index: 10; }
