/*
 * idea-notebook · v3 · style.css
 *
 * 基于 Schema v0.2 的多视图布局 + 边缘手势 + PWA standalone 优化
 * 主力设备：Android Chrome（portrait）
 */

:root {
  --bg: #f9f7f2;
  --bg-alt: #f3f0e8;
  --fg: #2a2a2a;
  --fg-muted: #8a8a8a;
  --fg-faint: #c0c0c0;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.1);
  --archive: #10b981;
  --archive-soft: rgba(16, 185, 129, 0.12);
  --delete: #ef4444;
  --delete-soft: rgba(239, 68, 68, 0.12);
  --surface: #ffffff;
  --border: rgba(0,0,0,0.08);
  --shadow-soft: 0 2px 8px rgba(0,0,0,0.05);
  --shadow-float: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-drawer: 0 -8px 24px rgba(0,0,0,0.08);
  --nav-duration: 250ms;
  --drawer-duration: 300ms;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;       /* 阻止浏览器下拉刷新 */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;       /* 关掉 double-tap-zoom */
}

body {
  position: fixed;                  /* 避免 iOS/Android 滚动漂移 */
  inset: 0;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ============================================================
 *  VIEW 基础
 * ============================================================ */

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: transform var(--nav-duration) ease;
  will-change: transform;
}

/* 默认所有 view 在视口左外侧，只有 active 归位 */
.view:not(.drawer) { transform: translateX(100%); }
.view:not(.drawer).active { transform: translateX(0); }
.view:not(.drawer).leaving-left { transform: translateX(-100%); }
.view:not(.drawer).leaving-right { transform: translateX(100%); }

/* fresh_list 默认在原位 —— 一开始就显示 */
[data-active-view="fresh_list"] > .view[data-view="fresh_list"] { transform: translateX(0); }

.view-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.view-title {
  font-size: 20px;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0.02em;
}

.view-count {
  font-size: 12px;
  color: var(--fg-muted);
  flex: 1;
}

.view-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.view-action:active {
  background: rgba(0,0,0,0.04);
}

.view-action.danger {
  color: var(--delete);
  border-color: rgba(239, 68, 68, 0.3);
}

.view-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 40px;
  -webkit-overflow-scrolling: touch;
}

.view-footer {
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  text-align: center;
}

.view-footer[data-cta="open-edit"] {
  /* v4: fresh_list 的 footer 承担"打开编辑"的 CTA 角色 */
  cursor: pointer;
  padding-top: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg-alt), var(--bg));
  transition: background 180ms ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.view-footer[data-cta="open-edit"]:active {
  background: linear-gradient(to top, var(--accent-soft), var(--bg));
}

.footer-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.footer-grip {
  width: 36px;
  height: 4px;
  background: var(--fg-faint);
  border-radius: 2px;
  opacity: 0.5;
}

.footer-cta-text {
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.04em;
  font-weight: 500;
}

.hint-text {
  font-size: 11px;
  color: var(--fg-faint);
  letter-spacing: 0.02em;
  opacity: 0.7;
}

/* ============================================================
 *  CARD
 * ============================================================ */

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

.idea-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  will-change: transform;
  touch-action: pan-y;              /* 允许垂直滚动，水平交给 JS */
  transition: background 150ms ease;
}

.idea-card:active {
  background: rgba(0,0,0,0.02);
}

.idea-card.swiping-right {
  background: var(--archive-soft);
}

.idea-card.swiping-left {
  background: var(--delete-soft);
}

.idea-card.fly-right {
  animation: fly-right 220ms ease-out forwards;
}

.idea-card.fly-left {
  animation: fly-left 220ms ease-out forwards;
}

@keyframes fly-right {
  to { transform: translateX(120%); opacity: 0; }
}

@keyframes fly-left {
  to { transform: translateX(-120%); opacity: 0; }
}

.idea-card-time {
  font-size: 10px;
  color: var(--fg-muted);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.idea-card-text {
  font-size: 14.5px;
  color: var(--fg);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  /* 不截断，卡片高度自适应 */
}

.empty-hint {
  padding: 64px 24px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.8;
}

/* ============================================================
 *  EDIT DRAWER（view 4）
 * ============================================================ */

.drawer {
  z-index: 20;
  pointer-events: none;
}

.drawer[hidden] { display: none !important; }

.drawer .drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0);
  transition: background var(--drawer-duration) ease;
  pointer-events: auto;
}

.drawer.open .drawer-backdrop {
  background: rgba(0,0,0,0.2);
}

.drawer-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-drawer);
  transform: translateY(100%);
  transition: transform var(--drawer-duration) ease;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  touch-action: pan-y;
}

.drawer.open .drawer-content {
  transform: translateY(0);
}

.drawer-grip {
  width: 40px;
  height: 4px;
  background: var(--fg-faint);
  border-radius: 2px;
  margin: 10px auto 0;
  opacity: 0.5;
}

.drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 6px;
}

.drawer-close {
  background: transparent;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 4px 10px;
}

.drawer-close:active { color: var(--fg); }

.drawer-title {
  font-size: 13px;
  color: var(--fg-muted);
  letter-spacing: 0.05em;
}

.drawer-body {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

#capture-input {
  width: 100%;
  min-height: 220px;
  max-height: 60vh;
  padding: 16px 18px;
  font-size: 17px;
  font-family: inherit;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: none;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 150ms ease;
}

#capture-input:focus {
  border-color: var(--accent);
}

#capture-input.committing {
  animation: commit-flash 350ms ease;
}

@keyframes commit-flash {
  0% { background: var(--bg-alt); }
  50% { background: var(--accent-soft); }
  100% { background: var(--bg-alt); }
}

.drawer-hints {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  font-size: 11px;
  color: var(--fg-faint);
}

.draft-indicator {
  color: var(--fg-muted);
  opacity: 0;
  transition: opacity 400ms ease;
}

.draft-indicator.show { opacity: 0.7; }
.draft-indicator.fading { opacity: 0; }

.drawer-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.recall-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

.recall-btn:active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.recall-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

.recall-icon {
  font-size: 14px;
}

.recall-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  max-height: 30vh;
}

.recall-bubble {
  padding: 10px 14px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  opacity: 0;
  transform: translateY(4px);
}

.recall-bubble.visible {
  animation: bubble-in 320ms ease-out forwards;
}

@keyframes bubble-in {
  to { opacity: 0.85; transform: translateY(0); }
}

.recall-bubble-label {
  font-size: 10px;
  color: var(--fg-muted);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.recall-bubble-text {
  font-size: 13px;
  color: var(--fg);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recall-bubble-time {
  font-size: 10px;
  color: var(--fg-muted);
  margin-top: 3px;
  opacity: 0.6;
}

/* ============================================================
 *  TOAST
 * ============================================================ */

#toast-layer {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  padding: 10px 18px;
  background: rgba(42, 42, 42, 0.92);
  color: #ffffff;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow-float);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: auto;
  transition: opacity 200ms ease, transform 200ms ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-action {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

/* ============================================================
 *  EDGE HINTS（教学式提示条，首次进入时显示）
 * ============================================================ */

.edge-hint {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms ease;
  font-size: 10px;
  color: var(--fg-faint);
  letter-spacing: 0.05em;
}

.edge-hint.visible { opacity: 0.5; }

/* ============================================================
 *  小屏优化
 * ============================================================ */

@media (max-width: 400px) {
  .view-header { padding: 16px 16px 10px; }
  .view-title { font-size: 18px; }
  #capture-input { min-height: 200px; }
}

/* PWA standalone 模式下隐藏不必要的边距 */
@media (display-mode: standalone) {
  .hint-text {
    opacity: 0.55;
  }
}
