/* ============================================================================
   布局层：应用外壳、可折叠侧边栏、顶栏、移动端底部 Tab、登录页
   桌面端(>860px)：左侧可折叠侧边栏
   移动端(≤860px)：自动切换为底部 Tab 导航
   ========================================================================== */

.app {
  display: flex;
  min-height: 100dvh;
}

/* ------------------------------------------------------------ 侧边栏 -- */

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  background: linear-gradient(180deg, #fff 0%, var(--bg-2) 100%);
  border-right: 1px solid var(--line);
  transition: width .26s cubic-bezier(.3, .8, .3, 1);
}

.app.is-collapsed .sidebar { width: var(--sidebar-w-sm); }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  overflow: hidden;
}

.sidebar__logo {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 6px 16px var(--primary-ring);
}

.sidebar__name {
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: .3px;
  white-space: nowrap;
}

.sidebar__sub {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.app.is-collapsed .sidebar__brand { justify-content: center; padding-inline: 0; }
.app.is-collapsed .sidebar__title { display: none; }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  font-weight: 650;
  color: var(--text-2);
  text-align: left;
  width: 100%;
  transition: background .2s, color .2s, transform .2s;
}

@media (hover: hover) {
  .nav__item:hover {
    background: var(--primary-softer);
    color: var(--primary-dark);
    transform: translateX(2px);
  }
}

.nav__item.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.nav__item.is-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 58%;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
}

.nav__emoji {
  flex: none;
  width: 26px;
  font-size: 19px;
  text-align: center;
  transition: transform .2s;
}

.nav__item.is-active .nav__emoji { transform: scale(1.1); }
.nav__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app.is-collapsed .sidebar__nav { align-items: center; }
.app.is-collapsed .nav__item { justify-content: center; padding: 11px 0; width: 52px; }
.app.is-collapsed .nav__label { display: none; }
.app.is-collapsed .nav__item.is-active::before { display: none; }

.sidebar__foot {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 侧边栏底部用户卡片 */
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 13px;
  background: var(--primary-softer);
  border: 1px solid var(--line);
  overflow: hidden;
}

.sidebar__avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 4px 10px var(--primary-ring);
}

.sidebar__userinfo { min-width: 0; }

.sidebar__username {
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__userrole {
  font-size: 10.5px;
  color: var(--text-3);
  white-space: nowrap;
}

.app.is-collapsed .sidebar__user { justify-content: center; padding: 8px 0; }
.app.is-collapsed .sidebar__userinfo { display: none; }

.collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-3);
  transition: background .2s, color .2s;
}
@media (hover: hover) {
  .collapse-btn:hover { background: var(--primary-softer); color: var(--primary-dark); }
}
.app.is-collapsed .collapse-btn { justify-content: center; padding: 9px 0; }
.app.is-collapsed .collapse-btn span:last-child { display: none; }

/* -------------------------------------------------------------- 主区域 -- */

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  padding: 22px 28px 48px;
  transition: margin-left .26s cubic-bezier(.3, .8, .3, 1);
}

.app.is-collapsed .main { margin-left: var(--sidebar-w-sm); }

.view {
  max-width: 1120px;
  margin: 0 auto;
  animation: viewIn .32s cubic-bezier(.2, .8, .3, 1);
}

/* 数据变化引起的重绘不重放进入动画，避免打卡时整页闪动 */
.view--no-anim { animation: none; }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- 顶栏 -- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.topbar__left { min-width: 0; }

.topbar__title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.topbar__desc {
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 2px;
}

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

/* 同步状态胶囊 */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 650;
  background: var(--primary-softer);
  color: var(--text-2);
  border: 1px solid var(--line);
  transition: background .2s, color .2s;
  white-space: nowrap;
}
.sync-pill.is-syncing { color: var(--info); border-color: rgba(111, 168, 245, .3); }
.sync-pill.is-syncing .sync-pill__emoji { animation: spin 1.1s linear infinite; display: inline-block; }
.sync-pill.is-offline { color: var(--warn); border-color: rgba(255, 174, 69, .32); }
.sync-pill.is-pending { color: var(--warn); border-color: rgba(255, 174, 69, .32); }
.sync-pill.is-error { color: var(--danger); border-color: rgba(255, 107, 138, .3); }
.sync-pill.is-synced { color: var(--good); border-color: rgba(76, 195, 138, .3); }

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------- 移动端底部 Tab 栏 -- */

.bottom-tabs { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }

  .app,
  .app.is-collapsed { display: block; }

  .main,
  .app.is-collapsed .main {
    margin-left: 0;
    padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 26px);
  }

  .view { max-width: none; }

  .topbar { margin-bottom: 14px; gap: 10px; }
  .topbar__title { font-size: 19px; }

  .bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .93);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 22px rgba(214, 140, 163, .1);
  }

  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--tabbar-h);
    font-size: 10.5px;
    font-weight: 650;
    color: var(--text-3);
    transition: color .2s;
  }

  .tab__emoji {
    font-size: 20px;
    line-height: 1;
    transition: transform .24s cubic-bezier(.3, 1.4, .5, 1);
  }

  .tab.is-active { color: var(--primary-dark); }
  .tab.is-active .tab__emoji { transform: translateY(-2px) scale(1.14); }

  .tab.is-active::after {
    content: '';
    position: absolute;
    top: 0;
    width: 22px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--primary);
  }
}

/* ------------------------------------------------------------- 登录页 -- */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 26px 18px calc(26px + env(safe-area-inset-bottom));
}

.auth__card {
  width: 100%;
  max-width: 412px;
  padding: 32px 28px;
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: viewIn .4s cubic-bezier(.2, .8, .3, 1);
}

.auth__logo {
  width: 66px;
  height: 66px;
  margin: 0 auto 16px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 10px 26px var(--primary-ring);
}

.auth__title {
  font-size: 21px;
  font-weight: 800;
  text-align: center;
}

.auth__sub {
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
  margin: 5px 0 22px;
}

.auth__tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--primary-softer);
  margin-bottom: 22px;
}

.auth__tab {
  padding: 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-2);
  transition: background .2s, color .2s;
}
.auth__tab.is-active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.auth__foot {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.7;
}

.auth__links {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.auth__link {
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-3);
  transition: color .18s;
}
@media (hover: hover) { .auth__link:hover { color: var(--primary-dark); } }

.auth__error {
  margin-bottom: 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 107, 138, .1);
  color: #C6425E;
  font-size: 13px;
  font-weight: 600;
}

.auth__ok {
  margin-bottom: 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(76, 195, 138, .12);
  color: #2F8A5F;
  font-size: 13px;
  font-weight: 600;
}

/* —— 未配置 Supabase 时的引导块 —— */
.setup-note {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 174, 69, .12);
  border: 1px solid rgba(255, 174, 69, .3);
  font-size: 12.5px;
  line-height: 1.75;
  color: #8A5A17;
}
.setup-note code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, .7);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11.5px;
}
.setup-note b { color: #6E4611; }

/* ---------------------------------------------------------- 加载遮罩 -- */

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  gap: 16px;
  text-align: center;
}

.boot__heart {
  font-size: 46px;
  animation: beat 1.5s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); }
  25% { transform: scale(1.14); }
  45% { transform: scale(.98); }
}

.boot__text { font-size: 13.5px; color: var(--text-3); }
