/* Dashboard layout */

.app-header {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md);
  padding-top: max(var(--space-md), env(safe-area-inset-top));
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-logout {
  min-height: 36px;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.app-header-brand {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
}

.app-logo {
  font-size: var(--text-md);
  font-weight: var(--font-bold);
  letter-spacing: 0.04em;
  color: var(--text);
}

.app-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.dashboard {
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: var(--space-md);
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  width: 100%;
}

#view-dashboard {
  min-height: 100dvh;
}

@media (min-width: 641px) {
  #view-dashboard {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .dashboard {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: var(--space-md);
    padding-bottom: var(--space-md);
    box-sizing: border-box;
  }

  .dashboard-stats {
    flex-shrink: 0;
  }

  .dashboard-grid {
    flex: 1;
    align-items: stretch;
    min-height: 0;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .panel-create {
    position: static;
    min-height: 0;
    overflow-y: auto;
  }

  .panel-tasks {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
  }

  .card-tasks {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  .card-tasks > .card-header,
  .card-tasks > .countdown {
    flex-shrink: 0;
  }

  .card-tasks > .task-list-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
}

@media (min-width: 961px) {
  .dashboard-grid {
    grid-template-rows: minmax(0, 1fr);
  }

  .panel-create {
    max-height: 100%;
  }
}

.dashboard-stats {
  margin-bottom: var(--space-md);
  min-height: calc(var(--stat-card-height) + var(--space-xs) + var(--space-sm));
}

.stats-scroll {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-xs) 0 var(--space-sm);
  scrollbar-width: none;
  align-items: stretch;
}

.stats-scroll::-webkit-scrollbar { display: none; }

.stats-scroll .stat-item {
  flex: 0 0 auto;
  min-width: 100px;
  height: var(--stat-card-height);
  scroll-snap-align: start;
  padding: var(--space-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.stats-scroll .stat-item .value {
  min-height: var(--stat-value-height);
  max-height: var(--stat-value-height);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-scroll .stat-item .label {
  min-height: var(--stat-label-height);
  max-height: var(--stat-label-height);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-md);
  align-items: start;
  width: 100%;
}

@media (min-width: 961px) {
  .dashboard-grid {
    grid-template-columns: var(--panel-create-width) minmax(0, 1fr);
    align-items: stretch;
  }

  .panel-create {
    width: var(--panel-create-width);
    max-width: var(--panel-create-width);
    flex-shrink: 0;
  }

  .panel-tasks {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
}

.panel-create {
  position: static;
}

.card-create .card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.card-create .card-title-row h2 {
  margin-bottom: 0;
  font-size: var(--text-lg);
}

.card-tasks .card-header {
  min-height: auto;
}

.card-tasks .card-header > div:first-child {
  min-width: 0;
  flex: 1;
}

.card-tasks .card-header h2 {
  margin-bottom: var(--space-xs);
  line-height: var(--leading-tight);
}

.footer-stats.inline {
  margin-top: 0;
  text-align: left;
  font-size: var(--text-xs);
  line-height: var(--leading-tight);
  min-height: calc(var(--text-xs) * var(--leading-tight));
}

/* Mobile bottom nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: none;
  padding: var(--space-sm) var(--space-md);
  padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
  justify-content: space-around;
  gap: var(--space-xs);
}

.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-xs);
  min-height: 48px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.mobile-nav-btn:active,
.mobile-nav-btn:hover {
  color: var(--primary);
  background: var(--overlay-hover);
}

.mobile-nav-btn.is-active {
  color: var(--primary);
  background: var(--overlay-active);
  font-weight: var(--font-medium);
}

@media (min-width: 641px) and (max-width: 960px) {
  .panel-create .card-create {
    max-height: 42vh;
    overflow-y: auto;
  }
}

/* Tablet */
@media (max-width: 960px) {
  .panel-create {
    position: static;
    width: 100%;
    max-width: none;
  }

  .panel-tasks {
    width: 100%;
  }

}

/* Phone — 三 Tab 独立模块 */
@media (max-width: 640px) {
  body:has(#view-dashboard:not(.hidden)) {
    overflow: hidden;
    height: 100dvh;
  }

  #view-dashboard {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .dashboard {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    padding-bottom: var(--space-sm);
    max-width: none;
  }

  .dashboard-grid {
    display: contents;
  }

  .mobile-tab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    flex-direction: column;
    width: 100%;
  }

  .mobile-tab-panel.mobile-tab-active {
    display: flex;
  }

  .dashboard-stats {
    margin-bottom: 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .dashboard-stats.mobile-tab-active .stats-scroll {
    flex: 1;
  }

  .panel-create {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel-create .card-create {
    flex: 1;
    min-height: min-content;
  }

  .panel-tasks {
    min-height: 0;
  }

  .panel-tasks.mobile-tab-active .card-tasks {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .panel-tasks.mobile-tab-active .task-list-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .stats-scroll {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-sm);
    overflow: visible;
    scroll-snap-type: none;
    -webkit-overflow-scrolling: auto;
    padding: 0;
    touch-action: auto;
  }

  .stats-scroll .stat-item {
    flex: unset;
    min-width: 0;
    width: auto;
    scroll-snap-align: none;
    height: var(--stat-card-height);
    padding: var(--space-sm) var(--space-md);
  }

  .card {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
  }

  .mobile-nav {
    display: flex;
    position: static;
    flex-shrink: 0;
  }

  .app-header {
    flex-shrink: 0;
    padding: var(--space-md);
    padding-top: max(var(--space-md), env(safe-area-inset-top));
  }

  #toast-container {
    top: auto;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: var(--space-md);
    right: var(--space-md);
    align-items: stretch;
  }

  .toast {
    max-width: none;
    text-align: center;
  }
}

@media (min-width: 641px) {
  .dashboard-stats {
    min-height: calc(
      var(--stat-grid-rows) * var(--stat-card-height)
      + (var(--stat-grid-rows) - 1) * var(--space-sm)
      + var(--space-xs) + var(--space-sm)
    );
  }

  .stats-scroll {
    display: grid;
    grid-template-columns: repeat(var(--stat-grid-cols), 1fr);
    grid-auto-rows: var(--stat-card-height);
    gap: var(--space-sm);
    overflow: visible;
  }

  .stats-scroll .stat-item {
    min-width: 0;
    height: var(--stat-card-height);
  }
}

@media (min-width: 961px) {
  .dashboard {
    padding: var(--space-md) var(--space-lg);
  }
}
