/* ──────────────────────────────────────────────────────────
   MyMemoKeeper Mini App
   Theming: 100% derived from Telegram's --tg-theme-* variables,
   injected by telegram-web-app.js. No hardcoded light/dark palette —
   fallbacks below only cover the (rare) case of opening outside Telegram.
   ────────────────────────────────────────────────────────── */

:root {
  --bg:            var(--tg-theme-bg-color, #ffffff);
  --bg-secondary:  var(--tg-theme-secondary-bg-color, #f0f0f3);
  --bg-section:    var(--tg-theme-section-bg-color, var(--bg));
  --text:          var(--tg-theme-text-color, #1c1c1e);
  --hint:          var(--tg-theme-hint-color, #8e8e93);
  --link:          var(--tg-theme-link-color, #2481cc);
  --accent:        var(--tg-theme-button-color, #2481cc);
  --accent-text:   var(--tg-theme-button-text-color, #ffffff);
  --destructive:   var(--tg-theme-destructive-text-color, #ff3b30);
  --separator:     var(--tg-theme-section-separator-color, rgba(120,120,128,0.2));

  --radius-card: 14px;
  --radius-sheet: 20px;
  --radius-pill: 100px;

  --tint-tasks: 142 70% 45%;
  --tint-watch: 261 65% 58%;
  --tint-read:  28  80% 52%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Safety net: [hidden] must always win over component display rules
   (e.g. .loader { display: flex }), regardless of CSS source order. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.tabbar {
  display: flex;
  padding: 10px 12px 12px;
  gap: 6px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--separator);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: none;
  border: none;
  border-radius: var(--radius-card);
  color: var(--hint);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.tab:active { transform: scale(0.96); }

.tab.active {
  background: var(--bg-secondary);
  color: var(--text);
}

.tab-icon { display: block; color: currentColor; }
.tab-label { letter-spacing: 0.01em; }

.subbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.subbar::-webkit-scrollbar { display: none; }

.subbar-pill {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--separator);
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.subbar-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

main#content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 100px;
  -webkit-overflow-scrolling: touch;
}

.list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list[hidden] { display: none; }

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--bg-section);
  border-radius: var(--radius-card);
  border: 1px solid var(--separator);
  cursor: pointer;
  animation: card-in 0.22s ease backwards;
  transition: transform 0.1s ease;
}

.card:active { transform: scale(0.985); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-ribbon {
  flex-shrink: 0;
  width: 5px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--separator);
  position: relative;
  overflow: hidden;
}
.card-ribbon::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: hsl(var(--tint, var(--tint-tasks)));
  height: var(--fill, 0%);
  border-radius: 3px;
  transition: height 0.3s ease;
}
.card[data-section="tasks"] .card-ribbon { --tint: var(--tint-tasks); }
.card[data-section="watch"] .card-ribbon { --tint: var(--tint-watch); }
.card[data-section="read"]  .card-ribbon { --tint: var(--tint-read); }
.card.is-done .card-ribbon::after { height: 100%; }

.card-body { flex: 1; min-width: 0; }

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card.is-done .card-title { color: var(--hint); text-decoration: line-through; text-decoration-color: var(--separator); }

.card-meta {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-note-dot {
  flex-shrink: 0;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: hsl(var(--tint-read));
  margin-right: 2px;
}

.card-chevron { flex-shrink: 0; color: var(--hint); opacity: 0.5; }

.loader {
  display: flex;
  justify-content: center;
  padding: 60px 0;
}
.loader[hidden] { display: none; }
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--separator);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 70px 24px;
  color: var(--hint);
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }
#empty-text { font-size: 15px; margin: 0; line-height: 1.5; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  cursor: pointer;
  transition: transform 0.15s ease;
  z-index: 20;
}
.fab:active { transform: scale(0.92); }

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 50;
  animation: overlay-in 0.18s ease;
}
.sheet-overlay[hidden] { display: none; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-height: 86vh;
  background: var(--bg);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: sheet-in 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--separator);
  margin: 4px auto 16px;
}

.sheet-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet-status {
  font-size: 13px;
  color: var(--hint);
  margin: 0 0 18px;
}

.sheet-field {
  margin-bottom: 14px;
}
.sheet-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.sheet-field-value {
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}
.sheet-field-value a { color: var(--link); }

.sheet-input, .sheet-textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: 10px;
  color: var(--text);
  outline: none;
}
.sheet-input:focus, .sheet-textarea:focus { border-color: var(--accent); }
.sheet-textarea { resize: vertical; min-height: 70px; }

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--bg-secondary); color: var(--text); }
.btn-destructive { background: transparent; color: var(--destructive); }
.btn-ghost { background: transparent; color: var(--hint); }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.progress-row .sheet-input { background: var(--bg); flex: 1; margin: 0; }
.btn-stepper {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.btn-stepper:active { transform: scale(0.92); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(0);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in 0.2s ease;
  max-width: calc(100vw - 48px);
  text-align: center;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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