/* ============================================================
   拾光工作台 · iPad / iPhone 适配层 v2
   修复：侧栏导航不可滚、100vh 溢出、12 栅格被内容撑开导致竖排文字
   增强：触摸目标、iOS 防缩放、安全区、可爱化细节
   加载顺序在 style.css 之后 → 同权重下本文件生效
   ============================================================ */

/* ---------- 1. 视口高度：用 dvh 修正 Safari 工具栏 ---------- */
.app {
  height: 100vh;
  height: 100dvh;          /* 动态视口：iPad Safari / PWA 都准确 */
  min-height: 0;
}

/* ---------- 2. 侧栏：logo 固定、导航可滚、底栏固定 ---------- */
.sidebar {
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
}
.logo { flex: 0 0 auto; min-width: 0; }
.logo-text { min-width: 0; }
.logo-name { white-space: nowrap; }
.logo-slogan { white-space: nowrap; }

.nav {
  flex: 1 1 auto;
  min-height: 0;                    /* 关键：允许在 flex 中收缩 */
  overflow-y: auto;                 /* 关键：装不下时可滚动 */
  overflow-x: hidden;
  overscroll-behavior: contain;     /* 滚到底不带动页面 */
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
  scrollbar-width: thin;
}
.nav::-webkit-scrollbar { width: 5px; }
.nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav-item { flex: 0 0 auto; }
.nav-item .nav-txt { white-space: nowrap; }

.sidebar-footer {
  flex: 0 0 auto;                   /* 底栏不被压缩 */
  margin-top: 10px;
}

/* ---------- 3. 12 栅格：minmax(0,1fr) 防止内容撑爆列宽 ---------- */
.today-grid,
[class*="grid-12"],
.grid-12 {
  grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
}
.view .card,
.today-grid > *,
.view .hero-card { min-width: 0; }

/* ---------- 4. Hero：窄区间自动上下堆叠，杜绝竖排文字 ---------- */
.hero-card { flex-wrap: wrap; row-gap: 16px; }
.hero-left { flex: 1 1 240px; min-width: 0; }
.hero-date-line { white-space: nowrap; }
.topbar-greeting {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: keep-all;             /* 中文按词换行，不再一字一行 */
  line-height: 1.25;
}
.hero-quote { word-break: keep-all; }
.hero-stats {
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-start;
}

/* 1080px 以下：统计区换到下一行，横铺更清爽 */
@media (max-width: 1080px) {
  .hero-card { gap: 18px; }
  .hero-stats {
    flex: 1 1 100%;
    border-left: none;
    border-top: 1px dashed var(--border);
    padding-left: 0;
    padding-top: 16px;
    justify-content: space-between;
    gap: 16px;
  }
  .stat-mini { min-width: 0; flex: 1 1 0; }
  .stat-mini .sm-label { white-space: nowrap; }
  .topbar-right { flex: 0 1 auto; }
  .year-progress .yp-bar { width: min(150px, 24vw); }
}

/* ---------- 5. 平板（761–1180px）：侧栏收窄、留白收紧 ---------- */
@media (min-width: 761px) and (max-width: 1180px) {
  :root { --nav-w: 196px; }
  .sidebar { padding: 18px 12px 12px; }
  .logo { padding: 0 4px 14px; gap: 10px; }
  .logo-mark { width: 40px; height: 40px; font-size: 21px; border-radius: 12px; }
  .logo-name { font-size: 15px; letter-spacing: 0; }
  .nav-item { padding: 10px 11px; font-size: 14px; }
  .topbar { padding: 18px 22px 8px; }
  .view-container { padding: 14px 22px 34px; }
  .view { max-width: 100%; }
  .card { padding: 18px 18px; }
  .sidebar-footer .quote-box { display: none; }   /* 省高度，寄语改到今日页展示 */
  .streak-box { padding: 10px 10px; }
}

/* ---------- 6. 手机（≤760px）：侧栏变底部标签栏 ---------- */
@media (max-width: 760px) {
  .app { flex-direction: column; }

  .sidebar {
    order: 2;
    width: 100%;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 -6px 18px rgba(80, 65, 35, 0.07);
  }
  .logo { display: none; }
  .sidebar-footer { display: none; }

  .nav {
    flex-direction: row;
    flex: 1 1 auto;
    overflow-y: hidden;
    overflow-x: auto;
    gap: 2px;
    padding: 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 8px 10px;
    min-height: 52px;
    border-radius: 14px;
    font-size: 11px;
  }
  .nav-item .nav-ico { font-size: 20px; width: auto; }
  .nav-item .nav-txt { font-size: 11px; letter-spacing: 0; }
  .nav-item.active { background: var(--accent-soft); color: var(--accent-deep); }

  .main { order: 1; flex: 1 1 auto; min-height: 0; }
  .topbar { padding: 14px 16px 6px; gap: 10px; }
  .topbar-greeting { font-size: 21px; }
  .topbar-right { display: none; }        /* 手机上省空间：年进度条收起 */
  .view-container { padding: 10px 16px 20px; }
  .card { padding: 16px 15px; border-radius: 18px; }
  .hero-stats { gap: 10px; }
  .view-title, .topbar-title { font-size: 22px; }
}

/* ---------- 7. iOS 输入焦点不缩放 + 触摸反馈 ---------- */
input, textarea, select { font-size: 16px; }
@media (hover: none) and (pointer: coarse) {
  button, .btn, .nav-item, .chip, .tab { min-height: 44px; }
  input, select, textarea { min-height: 44px; }
  .card:hover { transform: none; }
  .card:active { transform: scale(0.995); }
  .nav-item:active { transform: scale(0.96); }
  .btn:active, button:active { transform: scale(0.96); }
  -webkit-tap-highlight-color: transparent;
}
button, .btn, .nav-item, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
.view-container { -webkit-overflow-scrolling: touch; }
html { scrollbar-color: var(--border-strong) transparent; }

/* ---------- 8. PWA 独立窗口（主屏图标打开） ---------- */
@media (display-mode: standalone) {
  .sidebar { padding-top: calc(16px + env(safe-area-inset-top)); }
  .topbar { padding-top: calc(16px + env(safe-area-inset-top)); }
  .view-container { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
}
@supports (padding: max(0px)) {
  .nav { padding-left: max(0px, env(safe-area-inset-left)); }
  .view-container { padding-right: max(16px, env(safe-area-inset-right)); }
  @media (max-width: 760px) {
    .nav { padding-right: max(2px, env(safe-area-inset-right)); }
    .nav { padding-left: max(2px, env(safe-area-inset-left)); }
  }
}

/* ============================================================
   9. 哥哥的寄语（可爱卡片 · 今日页固定展示）
   ============================================================ */
.brother-note {
  grid-column: span 12;
  margin-bottom: 18px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(217, 111, 50, 0.10), transparent 55%),
    var(--card);
  border: 1.5px dashed var(--accent-soft-2, #f5dcc8);
  border-radius: 20px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  animation: noteIn 0.6s var(--ease) both;
}
@keyframes noteIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.brother-note .bn-heart {
  font-size: 26px;
  flex: 0 0 auto;
  animation: heartBeat 2.4s ease-in-out infinite;
}
@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.18); }
  24% { transform: scale(1); }
  36% { transform: scale(1.12); }
}
.brother-note .bn-body { min-width: 0; }
.brother-note .bn-tag {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: 700;
}
.brother-note .bn-text {
  font-family: "STKaiti", "KaiTi", "STSong", serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
  letter-spacing: 0.5px;
}
@media (max-width: 760px) {
  .brother-note { padding: 14px 16px; gap: 11px; border-radius: 18px; }
  .brother-note .bn-heart { font-size: 22px; }
  .brother-note .bn-text { font-size: 16px; }
}

/* ---------- 10. 离线提示条 ---------- */
.offline-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(-140%);
  top: calc(10px + env(safe-area-inset-top));
  z-index: 9999;
  background: var(--text);
  color: var(--bg);
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  transition: transform 0.32s var(--ease);
  pointer-events: none;
}
.offline-bar.show { transform: translateX(-50%) translateY(0); }

/* ---------- 11. 平板触感微调：更圆润可爱 ---------- */
@media (min-width: 761px) {
  .card { border-radius: 20px; }
  .nav-item { border-radius: 14px; }
  .logo-mark { border-radius: 13px; }
}

/* 侧栏寄语小字 */
.sidebar-note {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 11.5px;
  color: var(--text-3);
  padding: 6px 4px 2px;
  letter-spacing: 0.5px;
}
.sidebar-note span { white-space: nowrap; }

/* ---------- 12. 数据自愈兜底卡片 ---------- */
.rescue-card { border: 1.5px dashed var(--border-strong); }
.rescue-card .rc-title { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.rescue-card .rc-text { font-size: 14px; color: var(--text-2); line-height: 1.8; }
.rescue-card .rc-list { margin: 8px 0 14px 18px; font-size: 13.5px; color: var(--text-2); line-height: 1.9; }
.rescue-card .rc-err {
  margin-top: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px;
  color: var(--text-3); background: var(--card-hover); border-radius: 10px; padding: 8px 10px;
  word-break: break-all;
}

/* ============================================================
   13. 平板布局精修（解决"卡片被拉长、元素散落、内容重复"）
   ============================================================ */

/* ---- 13.1 hero 里不再重复顶栏的问候语与日期 ---- */
@media (max-width: 1180px) {
  .hero-card .hero-date-line,
  .hero-card .hero-left .topbar-greeting { display: none; }
  .hero-card .hero-quote { margin-top: 0; font-size: 16px; }
  .hero-card { align-items: flex-start; }
  .hero-left { flex: 1 1 100%; }
}

/* ---- 13.2 连续活跃卡：竖排大空卡 → 横向紧凑横幅 ---- */
@media (min-width: 761px) and (max-width: 1180px) {
  .streak-card {
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left !important;
    padding: 14px 20px !important;
  }
  .streak-card .card-title { margin: 0; justify-content: flex-start !important; }
  .streak-card > div { margin: 0 !important; }
  .streak-card .streak-flame { font-size: 24px; }
  .streak-card > div:nth-of-type(2) { font-size: 30px !important; line-height: 1 !important; }
  .streak-card > div:nth-of-type(3) { font-size: 13px !important; letter-spacing: 1px !important; margin: 0 2px 0 -6px !important; }
  .streak-card .tag { margin-left: auto; white-space: nowrap; }
}

/* ---- 13.3 心情按钮：平铺等宽，不再被拉伸到两端 ---- */
.mood-options { flex-wrap: wrap; }
@media (min-width: 761px) {
  .mood-options { justify-content: flex-start; gap: 10px; }
  .mood-options .mood-btn { flex: 0 1 auto; min-width: 92px; max-width: 140px; }
  .intensity-row { flex-wrap: wrap; }
  .intensity-row .intensity-btn { min-width: 84px; }
}

/* ---- 13.4 待办列表：平板给足高度，一屏看全 ---- */
@media (min-width: 761px) {
  .todo-list { max-height: none; }
  .log-list { max-height: none; }
  .todo-item { padding: 12px 14px; }
}

/* ---- 13.5 侧栏底栏：小空间里也整齐 ---- */
@media (min-width: 761px) and (max-width: 1180px) {
  .coins-box, .streak-box {
    padding: 10px 12px !important;
    font-size: 12px !important;
    line-height: 1.5 !important;
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px 8px;
    text-align: center;
  }
  .coins-box > *, .streak-box > * { margin: 0 !important; }
}

/* ---- 13.6 栅格：平板上的成对卡片 ---- */
@media (min-width: 761px) and (max-width: 1180px) {
  .today-grid > .span-4,
  .today-grid > .span-5,
  .today-grid > .span-6 { grid-column: span 12; }
}

/* ---- 13.7 统计小卡在宽卡里居中不散 ---- */
@media (min-width: 761px) and (max-width: 1180px) {
  .stat-mini { text-align: center; }
  .hero-stats { justify-content: space-around; }
}

/* ---- 13.8 手机端：寄语与卡片更紧凑 ---- */
@media (max-width: 760px) {
  .hero-card { padding: 16px 15px !important; }
  .hero-stats { border-top: 1px dashed var(--border); padding-top: 12px; }
  .brother-note { margin-bottom: 14px; }
}

/* ---- 13.9 待办行：标题与标签同一行，紧凑规整 ---- */
@media (min-width: 761px) {
  .todo-body { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
  .todo-meta { margin-top: 0 !important; }
  .todo-title { flex: 0 1 auto; }
}

/* ---- 13.10 手机端细节修复（寄语换行 / 底部标签文字 / 连续活跃紧凑） ---- */
@media (max-width: 760px) {
  /* 寄语必须能换行，且不超出卡片 */
  .brother-note { align-items: flex-start; max-width: 100%; overflow: hidden; }
  .brother-note .bn-body { min-width: 0; flex: 1 1 auto; }
  .brother-note .bn-text {
    white-space: normal !important;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.7;
  }
  /* 底部标签栏：恢复文字 */
  .nav-item .nav-txt { display: inline !important; }
  .nav-item { padding: 7px 12px; }
  /* 连续活跃：手机上同样改为横向紧凑条 */
  .streak-card {
    display: flex !important;
    align-items: center;
    gap: 10px;
    text-align: left !important;
    padding: 12px 15px !important;
    flex-wrap: wrap;
  }
  .streak-card .card-title { margin: 0 !important; justify-content: flex-start !important; }
  .streak-card > div { margin: 0 !important; }
  .streak-card .streak-flame { font-size: 20px !important; }
  .streak-card > div:nth-of-type(2) { font-size: 26px !important; line-height: 1 !important; }
  .streak-card > div:nth-of-type(3) { font-size: 12px !important; letter-spacing: 1px !important; margin: 0 4px 0 -4px !important; }
  .streak-card .tag { margin-left: auto; white-space: nowrap; font-size: 11px; }
}

/* ---- 13.11 寄语：固定两行显示 + 手机端输入行不溢出 ---- */
.brother-note .bn-text .bn-l1,
.brother-note .bn-text .bn-l2 { display: block; white-space: nowrap; }
@media (max-width: 760px) {
  .brother-note .bn-text .bn-l1,
  .brother-note .bn-text .bn-l2 { white-space: normal; }
  .brother-note .bn-text { font-size: 15.5px; }
  /* 待办输入行：输入框独占一行，按钮换行不溢出 */
  .todo-input-row { flex-wrap: wrap; }
  .todo-input-row .input { flex: 1 1 100%; }
  .todo-input-row .btn { flex: 0 0 auto; }
}
