/* ============================================
   Material Design 3 — CSS Variables
   ============================================ */
:root {
  /* Primary — M3 Indigo Blue */
  --md-sys-color-primary: #4355b9;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #dde1ff;
  --md-sys-color-on-primary-container: #001257;
  --md-sys-color-primary-fixed: #dde1ff;
  --md-sys-color-primary-fixed-dim: #b6c4ff;

  /* Secondary */
  --md-sys-color-secondary: #595d72;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #dee1f9;
  --md-sys-color-on-secondary-container: #161a2c;

  /* Tertiary */
  --md-sys-color-tertiary: #745471;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #ffd6f8;
  --md-sys-color-on-tertiary-container: #2b122b;

  /* Error */
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  /* Surface */
  --md-sys-color-surface: #fefbff;
  --md-sys-color-on-surface: #1b1b1f;
  --md-sys-color-surface-variant: #e7e0ec;
  --md-sys-color-on-surface-variant: #49454f;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container: #f1ecf4;
  --md-sys-color-surface-container-high: #ebe6ef;
  --md-sys-color-surface-container-highest: #e5e1e9;
  --md-sys-color-inverse-surface: #303034;
  --md-sys-color-inverse-on-surface: #f2f0f4;
  --md-sys-color-outline: #79747e;
  --md-sys-color-outline-variant: #cac4d0;

  /* M3 Elevation */
  --md-elevation-level0: none;
  --md-elevation-level1: 0 1px 2px rgba(0,0,0,.08), 0 1px 3px 1px rgba(0,0,0,.04);
  --md-elevation-level2: 0 1px 2px rgba(0,0,0,.08), 0 2px 6px 2px rgba(0,0,0,.04);
  --md-elevation-level3: 0 4px 8px 3px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --md-elevation-level4: 0 6px 10px 4px rgba(0,0,0,.06), 0 2px 3px rgba(0,0,0,.04);

  /* M3 Shape */
  --md-shape-corner-none: 0;
  --md-shape-corner-extra-small: 4px;
  --md-shape-corner-small: 8px;
  --md-shape-corner-medium: 12px;
  --md-shape-corner-large: 16px;
  --md-shape-corner-extra-large: 28px;
  --md-shape-corner-full: 9999px;

  /* M3 Typography Scale */
  --md-typescale-display-large: 3.562rem;
  --md-typescale-display-medium: 2.812rem;
  --md-typescale-display-small: 2.25rem;
  --md-typescale-headline-large: 2rem;
  --md-typescale-headline-medium: 1.75rem;
  --md-typescale-headline-small: 1.5rem;
  --md-typescale-title-large: 1.375rem;
  --md-typescale-title-medium: 1rem;
  --md-typescale-title-small: 0.875rem;
  --md-typescale-body-large: 1rem;
  --md-typescale-body-medium: 0.875rem;
  --md-typescale-body-small: 0.75rem;
  --md-typescale-label-large: 0.875rem;
  --md-typescale-label-medium: 0.75rem;
  --md-typescale-label-small: 0.6875rem;

  /* Font */
  --font: 'Roboto', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing — 4px grid */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* M3 Motion */
  --md-motion-duration-short1: 200ms;
  --md-motion-duration-medium1: 300ms;
  --md-motion-duration-long1: 400ms;
  --md-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-motion-easing-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --md-motion-easing-decelerate: cubic-bezier(0, 0, 0, 1);
  --md-motion-easing-accelerate: cubic-bezier(0.3, 0, 1, 1);

  /* === 兼容别名（JS 代码依赖的旧变量名） === */
  --accent: var(--md-sys-color-primary);
  --accent-light: var(--md-sys-color-primary-container);
  --accent-dark: var(--md-sys-color-primary-fixed-dim);
  --accent-subtle: var(--md-sys-color-primary-container);
  --bg: var(--md-sys-color-surface);
  --surface: var(--md-sys-color-surface-container-lowest);
  --surface-hover: var(--md-sys-color-surface-container-low);
  --border: var(--md-sys-color-outline-variant);
  --border-light: var(--md-sys-color-surface-variant);
  --text: var(--md-sys-color-on-surface);
  --text-secondary: var(--md-sys-color-on-surface-variant);
  --text-muted: var(--md-sys-color-outline);
  --danger: var(--md-sys-color-error);
  --danger-light: var(--md-sys-color-error-container);
  --danger-bg: rgba(186, 26, 26, 0.08);
  --warning: #ed6c02;
  --warning-light: #ffd8b8;
  --warning-bg: rgba(237, 108, 2, 0.08);
  --success: #2e7d32;
  --success-light: #c8e6c9;
  --success-bg: rgba(46, 125, 50, 0.08);
  --radius-sm: var(--md-shape-corner-extra-small);
  --radius-md: var(--md-shape-corner-medium);
  --radius-lg: var(--md-shape-corner-large);
  --radius-xl: var(--md-shape-corner-extra-large);
  --radius-2xl: var(--md-shape-corner-extra-large);
  --shadow-xs: var(--md-elevation-level1);
  --shadow-sm: var(--md-elevation-level1);
  --shadow-md: var(--md-elevation-level2);
  --shadow-lg: var(--md-elevation-level3);
  --shadow-xl: var(--md-elevation-level4);
  --duration-fast: var(--md-motion-duration-short1);
  --duration-normal: var(--md-motion-duration-medium1);
  --duration-slow: var(--md-motion-duration-long1);
  --ease-out: var(--md-motion-easing-standard);
  --ease-in-out: var(--md-motion-easing-emphasized);
  --text-xs: var(--md-typescale-body-small);
  --text-sm: var(--md-typescale-body-medium);
  --text-base: var(--md-typescale-body-large);
  --text-lg: var(--md-typescale-title-medium);
  --text-xl: var(--md-typescale-title-large);
  --text-2xl: var(--md-typescale-headline-small);
  --text-3xl: var(--md-typescale-headline-medium);
  --text-num: var(--md-typescale-display-small);
}

/* Dark Theme */
[data-theme="dark"] {
  --md-sys-color-primary: #b6c4ff;
  --md-sys-color-on-primary: #00268c;
  --md-sys-color-primary-container: #27409e;
  --md-sys-color-on-primary-container: #dde1ff;
  --md-sys-color-primary-fixed: #dde1ff;
  --md-sys-color-primary-fixed-dim: #b6c4ff;
  --md-sys-color-secondary: #c2c5dd;
  --md-sys-color-on-secondary: #2b3042;
  --md-sys-color-secondary-container: #414659;
  --md-sys-color-on-secondary-container: #dee1f9;
  --md-sys-color-tertiary: #e4bade;
  --md-sys-color-on-tertiary: #432741;
  --md-sys-color-tertiary-container: #5b3d58;
  --md-sys-color-on-tertiary-container: #ffd6f8;
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;
  --md-sys-color-surface: #131316;
  --md-sys-color-on-surface: #e4e1e6;
  --md-sys-color-surface-variant: #49454f;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-surface-container-lowest: #0e0e11;
  --md-sys-color-surface-container-low: #1b1b1f;
  --md-sys-color-surface-container: #1f1f23;
  --md-sys-color-surface-container-high: #2a292d;
  --md-sys-color-surface-container-highest: #353438;
  --md-sys-color-inverse-surface: #e4e1e6;
  --md-sys-color-inverse-on-surface: #303034;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;
  --md-elevation-level1: 0 1px 3px 1px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-elevation-level2: 0 2px 6px 2px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-elevation-level3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
  --md-elevation-level4: 0 6px 10px 4px rgba(0,0,0,.15), 0 2px 3px rgba(0,0,0,.3);
  --accent: var(--md-sys-color-primary);
  --accent-light: var(--md-sys-color-primary-container);
  --accent-dark: var(--md-sys-color-primary-fixed-dim);
  --accent-subtle: var(--md-sys-color-primary-container);
  --bg: var(--md-sys-color-surface);
  --surface: var(--md-sys-color-surface-container-lowest);
  --surface-hover: var(--md-sys-color-surface-container-low);
  --border: var(--md-sys-color-outline-variant);
  --border-light: var(--md-sys-color-surface-variant);
  --text: var(--md-sys-color-on-surface);
  --text-secondary: var(--md-sys-color-on-surface-variant);
  --text-muted: var(--md-sys-color-outline);
  --danger: var(--md-sys-color-error);
  --danger-light: var(--md-sys-color-error-container);
  --danger-bg: rgba(255, 180, 171, 0.12);
  --warning: #ffa726;
  --warning-light: #553800;
  --warning-bg: rgba(255, 167, 38, 0.12);
  --success: #66bb6a;
  --success-light: #003300;
  --success-bg: rgba(102, 187, 106, 0.12);
  --shadow-xs: var(--md-elevation-level1);
  --shadow-sm: var(--md-elevation-level1);
  --shadow-md: var(--md-elevation-level2);
  --shadow-lg: var(--md-elevation-level3);
  --shadow-xl: var(--md-elevation-level4);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: var(--md-typescale-body-medium);
  line-height: 1.5;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

/* Material Symbols utility */
.material-symbols-rounded {
  font-family: 'Material Symbols Rounded';
  font-weight: normal; font-style: normal;
  font-size: 24px; line-height: 1;
  letter-spacing: normal; text-transform: none;
  display: inline-block; white-space: nowrap;
  word-wrap: normal; direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.material-symbols-rounded.filled { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }

/* ============================================
   Layout — Navigation Rail (Desktop) + Shell
   ============================================ */
.app-layout {
  display: flex;
  min-height: 100dvh;
}

/* Navigation Rail — desktop ≥960px */
.nav-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80px;
  flex-shrink: 0;
  background: var(--md-sys-color-surface-container);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  padding: var(--space-3) 0;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  z-index: 50;
}

.nav-rail-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-2) 0 var(--space-4);
  margin-bottom: var(--space-2);
}

.nav-rail-logo {
  width: 40px; height: 40px;
  border-radius: var(--md-shape-corner-medium);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: var(--space-1);
  overflow: hidden;
}
.nav-rail-logo svg { width: 24px; height: 24px; }

.nav-rail-title {
  font-size: var(--md-typescale-label-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  line-height: 1.2;
  max-width: 68px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-rail-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 var(--space-1);
  width: 100%;
}

.nav-rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: var(--space-2) 0;
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  position: relative;
  text-decoration: none;
}

.nav-rail-item:hover {
  background: var(--md-sys-color-surface-container-high);
}

.nav-rail-item.active {
  color: var(--md-sys-color-on-primary-container);
  background: var(--md-sys-color-primary-container);
  font-weight: 600;
}

.nav-rail-item .nav-rail-icon {
  font-size: 24px;
  line-height: 1;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-shape-corner-full);
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.nav-rail-item.active .nav-rail-icon {
  font-variation-settings: 'FILL' 1;
}

.nav-rail-badge {
  position: absolute;
  top: 4px; right: 12px;
  min-width: 18px; height: 18px;
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
  font-size: 10px; font-weight: 700;
  border-radius: var(--md-shape-corner-full);
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

.nav-rail-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0 0;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin-top: auto;
  width: 100%;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  padding-bottom: calc(var(--space-12) + env(safe-area-inset-bottom, 0px));
}

/* ============================================
   Top App Bar (inside main content)
   ============================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 var(--space-4);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-logo {
  width: 40px; height: 40px;
  border-radius: var(--md-shape-corner-medium);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--md-typescale-title-medium);
  font-weight: 700;
  overflow: hidden;
}
.header-logo svg { width: 24px; height: 24px; }

.header-title h1 {
  font-size: var(--md-typescale-title-large);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  line-height: 1.2;
  letter-spacing: 0;
}

.header-title p {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.4;
}

.header-actions {
  display: flex; align-items: center; gap: var(--space-2);
}

/* Date Picker — M3 Chip style */
.date-picker {
  display: flex; align-items: center; gap: var(--space-1);
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-shape-corner-small);
  padding: 2px;
}

.date-picker button {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  font-size: var(--md-typescale-body-medium);
}

.date-picker button:hover {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

.date-picker .date-display {
  font-weight: 600;
  font-size: var(--md-typescale-label-large);
  min-width: 100px;
  text-align: center;
  color: var(--md-sys-color-on-surface);
}

/* Theme Toggle — M3 Icon Button */
.theme-toggle {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-shape-corner-full);
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 20px;
}

.theme-toggle:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

/* ============================================
   Navigation Bar (Tablet) & Bottom Bar (Mobile)
   ============================================ */
.tab-nav {
  display: flex;
  gap: 0;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-corner-large);
  padding: 0;
  margin-bottom: var(--space-6);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  box-shadow: var(--md-elevation-level1);
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: 0;
  font-size: var(--md-typescale-label-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  min-width: 64px;
  height: 64px;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  position: relative;
  cursor: pointer;
}

.tab-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.tab-btn.active {
  color: var(--md-sys-color-on-primary-container);
  background: var(--md-sys-color-primary-container);
  font-weight: 600;
}

.tab-btn .tab-icon {
  font-size: 24px;
  line-height: 1;
  transition: font-variation-settings var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.tab-btn.active .tab-icon {
  font-variation-settings: 'FILL' 1;
}

/* Bottom Tab Bar (Mobile) */
.bottom-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--md-sys-color-surface-container);
  padding: var(--space-1) var(--space-1) calc(var(--space-1) + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -1px 3px rgba(0,0,0,.08);
}

.bottom-tabs-inner {
  display: flex; flex-wrap: wrap; justify-content: center;
  max-width: 560px; margin: 0 auto;
  gap: 0;
}

.bottom-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  padding: var(--space-1) var(--space-1);
  border-radius: var(--md-shape-corner-full);
  font-size: 0.5625rem; font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  min-height: 48px;
  min-width: 52px;
  flex: 0 1 auto;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  cursor: pointer;
}

.bottom-tab .bottom-tab-icon {
  font-size: 22px; line-height: 1;
}

.bottom-tab.active {
  color: var(--md-sys-color-on-primary-container);
  background: var(--md-sys-color-primary-container);
  font-weight: 600;
}

.bottom-tab.active .bottom-tab-icon {
  font-variation-settings: 'FILL' 1;
}

/* ============================================
   Content Panels
   ============================================ */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Sub-tabs */
.sub-tabs {
  display: flex; gap: 0;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-shape-corner-medium);
  padding: 2px;
  margin-bottom: var(--space-5);
}

.sub-tab {
  flex: 1; text-align: center;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--md-shape-corner-small);
  font-size: var(--md-typescale-label-large); font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  white-space: nowrap;
  min-height: 40px;
  display: flex; align-items: center; justify-content: center; gap: var(--space-1);
}

.sub-tab:hover {
  color: var(--md-sys-color-on-surface);
}

.sub-tab.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* Upload area */
.upload-zone {
  border: 2px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-large);
  padding: var(--space-8);
  text-align: center;
  cursor: pointer;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  background: var(--md-sys-color-surface-container-lowest);
}

.upload-zone:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

.upload-zone.drag-over {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

.upload-zone input[type="file"] { display: none; }
.upload-icon { font-size: 3rem; margin-bottom: var(--space-3); }

/* Alert banner */
.alert-banner {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--md-shape-corner-small);
  margin-bottom: var(--space-4);
  font-size: var(--md-typescale-body-small); line-height: 1.5;
}

.alert-banner.danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.alert-banner.warn {
  background: var(--warning-bg);
  color: var(--warning);
}

/* Filter bar */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  margin-bottom: var(--space-4);
  align-items: center;
}

/* Table — 通用 */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--md-shape-corner-medium);
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--md-typescale-body-small);
  table-layout: auto;
}
.table-wrap th,
.table-wrap td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
.table-wrap th {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
  font-size: var(--md-typescale-label-medium);
  height: 44px;
}
.table-wrap tr:hover td {
  background: var(--md-sys-color-surface-container-low);
}
.table-wrap td:first-child,
.table-wrap th:first-child { border-radius: var(--md-shape-corner-medium) 0 0 0; }
.table-wrap td:last-child,
.table-wrap th:last-child { border-radius: 0 var(--md-shape-corner-medium) 0 0; }
.table-wrap tbody tr:last-child td:first-child { border-radius: 0 0 0 var(--md-shape-corner-medium); }
.table-wrap tbody tr:last-child td:last-child { border-radius: 0 0 var(--md-shape-corner-medium) 0; }
.table-wrap tbody tr:last-child td { border-bottom: none; }

[data-theme="dark"] .table-wrap th {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

/* Stat cards */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}
.stat-card {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-4);
  box-shadow: var(--md-elevation-level1);
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-card.danger { border-left: 4px solid var(--md-sys-color-error); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.primary { border-left: 4px solid var(--md-sys-color-primary); }
.stat-card .stat-value {
  font-size: var(--md-typescale-headline-small);
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  line-height: 1.2;
}
.stat-card .stat-label {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: var(--space-1);
  line-height: 1.4;
}
.stat-card .stat-label small {
  font-size: var(--md-typescale-label-small);
  color: var(--md-sys-color-outline);
}

/* Data source info icon — 固定在卡片右上角 */
.stat-card {
  position: relative;
}
.stat-info-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-outline);
  cursor: help;
  z-index: 2;
  transition: all 0.15s;
  line-height: 1;
}
.stat-info-icon svg {
  fill: currentColor;
  display: block;
}
.stat-info-icon:hover,
.stat-info-icon:focus {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.stat-info-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  right: -4px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: var(--md-shape-corner-small);
  box-shadow: var(--md-elevation-level3);
  z-index: 100;
  pointer-events: none;
  line-height: 1.5;
  text-align: left;
}
.stat-info-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 10px;
  border: 5px solid transparent;
  border-top-color: var(--md-sys-color-inverse-surface);
}
.stat-info-icon:hover .stat-info-tooltip,
.stat-info-icon:focus .stat-info-tooltip {
  display: block;
}

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: 9999px;
  font-size: var(--md-typescale-label-small);
  font-weight: 600;
  line-height: 1.4;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}
.chip-danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}
.chip-warning {
  background: var(--warning-container);
  color: var(--warning);
}
.chip-active {
  background: var(--success-container);
  color: var(--success);
}
.chip-left {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

[data-theme="dark"] .chip {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}
[data-theme="dark"] .chip-danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}
[data-theme="dark"] .chip-warning {
  background: var(--warning-container);
  color: var(--warning);
}
[data-theme="dark"] .chip-active {
  background: var(--success-container);
  color: var(--success);
}

.filter-bar select, .filter-bar input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-lowest);
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  min-height: 40px;
  transition: border-color var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.filter-bar select:focus, .filter-bar input:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: calc(var(--space-2) - 1px) calc(var(--space-3) - 1px);
}

/* Multi-select dropdown */
.multi-select { position: relative; user-select: none; }

.ms-trigger {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-lowest);
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface);
  cursor: pointer; white-space: nowrap;
  min-width: 120px; min-height: 40px;
  display: flex; align-items: center; gap: var(--space-2);
  transition: border-color 0.15s;
}

.ms-trigger:hover { border-color: var(--md-sys-color-outline); }

.ms-trigger .ms-count {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 10px;
  padding: 1px 6px; border-radius: var(--md-shape-corner-full);
  display: none;
}

.ms-trigger .ms-count.has { display: inline; }

.ms-dropdown {
  display: none; position: absolute; top: 100%; left: 0; z-index: 100;
  margin-top: 4px;
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-extra-small);
  box-shadow: var(--md-elevation-level3);
  min-width: 160px; max-height: 220px; overflow-y: auto;
  padding: var(--space-1) 0;
}

.ms-dropdown.open { display: block; }

.ms-option {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); cursor: pointer;
  font-size: var(--md-typescale-body-small);
  transition: background 0.1s;
  min-height: 40px;
}

.ms-option:hover { background: var(--md-sys-color-surface-container-low); }
.ms-option input[type="checkbox"] { accent-color: var(--md-sys-color-primary); margin: 0; }

/* Scrollable table */
.scroll-table {
  overflow-x: auto;
  border-radius: var(--md-shape-corner-medium);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}

.scroll-table table {
  width: 100%; border-collapse: collapse;
  font-size: var(--md-typescale-body-small);
}

.scroll-table th {
  background: var(--md-sys-color-surface-container-high);
  position: sticky; top: 0; z-index: 2;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0;
  text-transform: none;
  padding: var(--space-3) var(--space-4);
  text-align: left; white-space: nowrap;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  height: 48px;
}

.scroll-table th:hover { background: var(--md-sys-color-surface-container-highest); }
.scroll-table th .sort-arrow { font-size: 0.8em; margin-left: 2px; }

.scroll-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--md-sys-color-surface-variant);
  white-space: nowrap;
  height: 48px;
}

.scroll-table tr:hover td { background: var(--md-sys-color-surface-container-low); }
.scroll-table .row-danger td { background: var(--danger-bg) !important; }
.scroll-table .row-warn td { background: var(--warning-bg) !important; }

.scroll-table .summary-row td {
  font-weight: 700;
  background: var(--md-sys-color-surface-container-high);
  border-top: 2px solid var(--md-sys-color-primary);
  position: sticky; bottom: 0; z-index: 1;
}

.scroll-table .danger-row td { background: var(--danger-bg); color: var(--danger); }
.scroll-table .warn-row td { background: var(--warning-bg); }

/* History list */
.history-list {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.history-chip {
  padding: var(--space-1) var(--space-4);
  border-radius: var(--md-shape-corner-small);
  font-size: var(--md-typescale-label-medium); font-weight: 600;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: all var(--md-motion-duration-short1);
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 32px;
}

.history-chip:hover {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.history-chip.active {
  background: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary-container);
}

.history-chip .chip-del {
  cursor: pointer; opacity: 0.6; font-size: 0.85em; margin-left: 2px;
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-shape-corner-full);
}

.history-chip .chip-del:hover {
  opacity: 1; color: var(--md-sys-color-error);
  background: var(--md-sys-color-error-container);
}

/* v2.4: Member badge styles */
.member-new-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-small);
  font-weight: 600;
  margin-left: 4px;
  line-height: 1.3;
}
.member-left-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-small);
  margin-left: 4px;
  line-height: 1.3;
}
.history-chip.left-member {
  opacity: 0.5;
}
.history-chip.left-member:hover {
  opacity: 0.75;
}

/* Section Header */
.section-header {
  margin-bottom: var(--space-5);
}

.section-header h2 {
  font-size: var(--md-typescale-headline-small);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  line-height: 1.2;
  letter-spacing: 0;
}

.section-header p {
  font-size: var(--md-typescale-body-medium);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: var(--space-1);
}

/* ============================================
   Card
   ============================================ */
.card {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-5);
  box-shadow: var(--md-elevation-level1);
  transition: box-shadow var(--md-motion-duration-medium1) var(--md-motion-easing-standard);
}

.card:hover { box-shadow: var(--md-elevation-level2); }
.card + .card { margin-top: var(--space-4); }

/* ============================================
   Buttons — M3 Style
   ============================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-6);
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-large); font-weight: 600;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  white-space: nowrap;
  height: 40px;
  letter-spacing: 0;
  text-transform: none;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: scale(0.97); }

/* Filled Button */
.btn-primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-elevation-level1);
}

.btn-primary:hover {
  background: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-level2);
  filter: brightness(1.08);
}

/* Outlined Button */
.btn-secondary {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.btn-secondary:hover {
  background: rgba(67, 85, 185, 0.08);
  border-color: var(--md-sys-color-primary);
}

/* Danger Button */
.btn-danger {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.btn-danger:hover {
  filter: brightness(1.1);
  box-shadow: var(--md-elevation-level1);
}

/* Small button */
.btn-sm {
  padding: 0 var(--space-4);
  font-size: var(--md-typescale-label-medium);
  height: 32px;
}

/* Text / Ghost button */
.btn-ghost {
  color: var(--md-sys-color-on-surface-variant);
  padding: 0 var(--space-3);
}

.btn-ghost:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--space-10) + env(safe-area-inset-bottom, 0px));
  right: var(--space-6);
  width: 56px; height: 56px;
  border-radius: var(--md-shape-corner-large);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: var(--md-elevation-level3);
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  z-index: 50;
}

.fab:hover {
  box-shadow: var(--md-elevation-level4);
  filter: brightness(1.05);
}

.fab:active { transform: scale(0.95); }

/* ============================================
   Modal — M3 Dialog
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  align-items: center; justify-content: center;
  padding: var(--space-4);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-shape-corner-extra-large);
  padding: var(--space-6);
  width: 100%; max-width: 560px;
  max-height: 90dvh; overflow-y: auto;
  box-shadow: var(--md-elevation-level3);
}

.modal h3 {
  font-size: var(--md-typescale-headline-small);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--space-4);
  line-height: 1.3;
}

.modal .form-group {
  display: flex; flex-direction: column; gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.modal .form-group label {
  font-size: var(--md-typescale-body-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.modal .form-group input,
.modal .form-group select,
.modal .form-group textarea {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-lowest);
  font-size: var(--md-typescale-body-medium);
  min-height: 48px;
  transition: border-color var(--md-motion-duration-short1);
  color: var(--md-sys-color-on-surface);
}

.modal .form-group input:focus,
.modal .form-group select:focus,
.modal .form-group textarea:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: calc(var(--space-3) - 1px) calc(var(--space-4) - 1px);
}

.modal .form-group textarea { resize: vertical; min-height: 80px; }

.modal-actions {
  display: flex; gap: var(--space-3); justify-content: flex-end;
  margin-top: var(--space-6);
}

/* ============================================
   Toast / Snackbar — M3 Style
   ============================================ */
.toast-container {
  position: fixed; bottom: var(--space-4); left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column-reverse; gap: var(--space-2);
  align-items: center;
}

.toast {
  padding: var(--space-3) var(--space-6);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: var(--md-shape-corner-extra-small);
  box-shadow: var(--md-elevation-level3);
  font-size: var(--md-typescale-body-medium); font-weight: 500;
  animation: snackbarIn var(--md-motion-duration-medium1) var(--md-motion-easing-standard);
  white-space: nowrap;
}

@keyframes snackbarIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Progress Ring (Checklist)
   ============================================ */
.progress-ring { display: inline-flex; align-items: center; gap: var(--space-3); }

.ring-container { position: relative; width: 48px; height: 48px; flex-shrink: 0; }

.ring-bg {
  fill: none;
  stroke: var(--md-sys-color-surface-variant);
  stroke-width: 4;
}

.ring-fill {
  fill: none;
  stroke: var(--md-sys-color-primary);
  stroke-width: 4;
  stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: center;
  transition: stroke-dashoffset var(--md-motion-duration-long1) var(--md-motion-easing-standard);
}

.ring-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--md-typescale-label-medium); font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

/* ============================================
   Tab 1 — Daily Checklist (M3)
   ============================================ */
.priority-group {
  margin-bottom: var(--space-4);
  border-radius: var(--md-shape-corner-medium);
  overflow: hidden;
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}

.priority-group-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: background var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.priority-group-header:hover {
  background: var(--md-sys-color-surface-container-low);
}

.priority-dot {
  width: 12px; height: 12px;
  border-radius: var(--md-shape-corner-extra-small);
  flex-shrink: 0;
}

.priority-dot.red {
  background: var(--md-sys-color-error);
}

.priority-dot.yellow {
  background: var(--warning);
}

.priority-dot.green {
  background: var(--success);
}

.priority-label {
  font-weight: 600;
  font-size: var(--md-typescale-title-small);
  color: var(--md-sys-color-on-surface);
  flex: 1;
}

.priority-badge {
  font-size: var(--md-typescale-label-small);
  font-weight: 600;
  padding: 2px var(--space-2);
  border-radius: var(--md-shape-corner-extra-small);
}

.priority-badge.red {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.priority-badge.yellow {
  background: var(--warning-bg);
  color: var(--warning);
}

.priority-badge.green {
  background: var(--success-bg);
  color: var(--success);
}

.priority-progress {
  font-size: var(--md-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.checklist-items {
  padding: 0 var(--space-3) var(--space-3);
}

.checklist-item {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--md-shape-corner-small);
  background: var(--md-sys-color-surface-container-low);
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  position: relative;
}

.checklist-item + .checklist-item { margin-top: var(--space-2); }

.checklist-item:hover {
  background: var(--md-sys-color-surface-container);
}

.ci-seq {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-medium); font-weight: 700;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  flex-shrink: 0;
}

.ci-content { flex: 1; min-width: 0; }

.ci-name {
  font-weight: 600;
  font-size: var(--md-typescale-body-medium);
  color: var(--md-sys-color-on-surface);
  line-height: 1.3;
}

.ci-meta {
  display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1);
}

.ci-tag {
  font-size: var(--md-typescale-label-small); font-weight: 500;
  padding: 2px var(--space-2);
  border-radius: var(--md-shape-corner-extra-small);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.ci-tag.score {
  background: var(--warning-bg);
  color: var(--warning);
}

.ci-detail {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: var(--space-2); line-height: 1.5;
  white-space: pre-line;
}

.ci-risk {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-error);
  margin-top: var(--space-1); font-weight: 500;
  white-space: pre-line;
}

.ci-actions {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  flex-shrink: 0;
}

/* M3 Segmented Button style status toggle */
.status-btn {
  min-width: 56px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 var(--space-3);
  border-radius: var(--md-shape-corner-full);
  font-size: var(--md-typescale-label-large); font-weight: 600; line-height: 1;
  transition: all var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  border: none;
  cursor: pointer;
}

.status-btn:hover {
  filter: brightness(1.05);
}

.status-btn:active { transform: scale(0.95); }

.status-btn.done {
  background: var(--success);
  color: white;
  box-shadow: var(--md-elevation-level1);
}

.status-btn.progress {
  background: var(--warning);
  color: white;
  box-shadow: var(--md-elevation-level1);
}

.status-btn.pending {
  background: var(--md-sys-color-error);
  color: white;
  box-shadow: var(--md-elevation-level1);
}

.ci-remark-btn {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: var(--md-typescale-label-small); line-height: 1;
  color: var(--md-sys-color-on-surface-variant);
  transition: color var(--md-motion-duration-short1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--md-shape-corner-extra-small);
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}
.ci-remark-btn .material-symbols-rounded {
  font-size: 16px; vertical-align: middle;
}

.ci-remark-btn:hover {
  color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

/* Red Lines — M3 style */
.redline-card {
  background: var(--md-sys-color-error-container);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-4);
  margin-top: var(--space-4);
}

.redline-card h3 {
  font-size: var(--md-typescale-title-small); font-weight: 600;
  color: var(--md-sys-color-on-error-container);
  margin-bottom: var(--space-3);
}

.redline-list { list-style: none; }

.redline-list li {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-error-container);
  padding: var(--space-1) 0;
  padding-left: var(--space-5);
  position: relative;
  line-height: 1.5;
  opacity: 0.85;
}

.redline-list li::before {
  content: '✕'; position: absolute; left: 0;
  color: var(--md-sys-color-error); font-weight: 700;
}

/* ============================================
   Tab 2 — Daily Data Entry
   ============================================ */
.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
}

.data-field { display: flex; flex-direction: column; gap: var(--space-1); }

.data-field label {
  font-size: var(--md-typescale-label-medium); font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.data-field input, .data-field select {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-lowest);
  font-size: var(--md-typescale-body-medium);
  min-height: 48px;
  transition: border-color var(--md-motion-duration-short1) var(--md-motion-easing-standard);
  color: var(--md-sys-color-on-surface);
}

.data-field input:focus, .data-field select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: calc(var(--space-3) - 1px) calc(var(--space-4) - 1px);
}

.data-field input::placeholder { color: var(--md-sys-color-outline); }

.auto-calc {
  background: var(--md-sys-color-primary-container) !important;
  border-color: var(--md-sys-color-primary) !important;
  color: var(--md-sys-color-on-primary-container) !important;
  font-weight: 600 !important;
}

/* ============================================
   Tab 3 — Weekly Summary
   ============================================ */
.weekly-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--md-shape-corner-medium);
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}

.weekly-table {
  width: 100%; border-collapse: collapse;
  font-size: var(--md-typescale-body-medium);
}

.weekly-table th {
  background: var(--md-sys-color-surface-container-high);
  font-weight: 600;
  font-size: var(--md-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none;
  letter-spacing: 0;
  padding: var(--space-3) var(--space-4);
  text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  height: 48px;
}

.weekly-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--md-sys-color-surface-variant);
  white-space: nowrap;
  height: 48px;
}

.weekly-table tr:last-child td { border-bottom: none; }
.weekly-table tr:hover td { background: var(--md-sys-color-surface-container-low); }
.weekly-table .week-label { font-weight: 600; color: var(--md-sys-color-primary); }
.weekly-table .cell-empty { color: var(--md-sys-color-outline); }

.chart-container {
  margin-top: var(--space-6);
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-5);
  box-shadow: var(--md-elevation-level1);
  position: relative;
  height: auto;
}

.chart-container canvas {
  max-height: 360px !important;
  width: 100% !important;
}

.chart-container h3 {
  font-size: var(--md-typescale-title-medium); font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--md-sys-color-on-surface);
}

/* ============================================
   Tab 4 — KPI Dashboard
   ============================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
}

.kpi-card {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-4);
  box-shadow: var(--md-elevation-level1);
  transition: box-shadow var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.kpi-card:hover {
  box-shadow: var(--md-elevation-level2);
}

.kpi-card .kpi-category {
  font-size: var(--md-typescale-label-small); font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: var(--space-1);
}

.kpi-card .kpi-name {
  font-size: var(--md-typescale-body-medium); font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--space-3);
}

.kpi-card .kpi-value {
  font-size: var(--md-typescale-display-small); font-weight: 700;
  color: var(--md-sys-color-on-surface); line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--space-1);
}

.kpi-card .kpi-target {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
}

.kpi-bar {
  height: 4px; border-radius: 2px;
  background: var(--md-sys-color-surface-variant);
  margin-top: var(--space-3);
  overflow: hidden;
}

.kpi-bar-fill {
  height: 100%; border-radius: 2px;
  transition: width var(--md-motion-duration-long1) var(--md-motion-easing-standard);
}

.kpi-bar-fill.good { background: var(--success); }
.kpi-bar-fill.warn { background: var(--warning); }
.kpi-bar-fill.danger { background: var(--md-sys-color-error); }

.kpi-status {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--md-typescale-label-small); font-weight: 600;
  margin-top: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--md-shape-corner-extra-small);
}

.kpi-status.good {
  background: var(--success-bg);
  color: var(--success);
}

.kpi-status.warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.kpi-status.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Score Simulation */
.score-table-wrap {
  overflow-x: auto;
  border-radius: var(--md-shape-corner-medium);
  margin-top: var(--space-6);
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}

.score-table {
  width: 100%; border-collapse: collapse;
  font-size: var(--md-typescale-body-medium);
}

.score-table th {
  background: var(--md-sys-color-surface-container-high);
  font-weight: 600;
  font-size: var(--md-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none;
  letter-spacing: 0;
  padding: var(--space-3) var(--space-4);
  text-align: left; border-bottom: 1px solid var(--md-sys-color-outline-variant);
  height: 48px;
}

.score-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--md-sys-color-surface-variant);
  height: 48px;
}

.score-table .total-row td {
  font-weight: 700;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-top: 2px solid var(--md-sys-color-primary);
}

.score-bar {
  height: 8px; border-radius: 4px;
  background: var(--md-sys-color-surface-variant);
  min-width: 80px; overflow: hidden;
}

.score-bar-fill {
  height: 100%; border-radius: 4px;
  background: var(--md-sys-color-primary);
}

/* ============================================
   Tab 5 — Behavior Tracking
   ============================================ */
.behavior-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.behavior-stat {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  padding: var(--space-4);
  box-shadow: var(--md-elevation-level1);
}

.behavior-stat .stat-label {
  font-size: var(--md-typescale-label-small); font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none; letter-spacing: 0;
}

.behavior-stat .stat-value {
  font-size: var(--md-typescale-headline-small); font-weight: 700;
  color: var(--md-sys-color-on-surface);
  line-height: 1; margin-top: var(--space-2);
}

.behavior-stat .stat-sub {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: var(--space-1);
}

.behavior-table-wrap {
  overflow-x: auto;
  border-radius: var(--md-shape-corner-medium);
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-elevation-level1);
}

.behavior-table {
  width: 100%; border-collapse: collapse;
  font-size: var(--md-typescale-body-medium);
}

.behavior-table th {
  background: var(--md-sys-color-surface-container-high);
  font-weight: 600;
  font-size: var(--md-typescale-label-medium);
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none; letter-spacing: 0;
  padding: var(--space-3) var(--space-4);
  text-align: left; border-bottom: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
  height: 48px;
}

.behavior-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--md-sys-color-surface-variant);
  vertical-align: top;
  height: 48px;
}

.behavior-table tr:hover td { background: var(--md-sys-color-surface-container-low); }

.rectified-badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--md-typescale-label-small); font-weight: 600;
  padding: 2px var(--space-2); border-radius: var(--md-shape-corner-extra-small);
}

.rectified-badge.yes {
  background: var(--success-bg);
  color: var(--success);
}

.rectified-badge.no {
  background: var(--warning-bg);
  color: var(--warning);
}

/* ============================================
   Tab 6 — Timeline
   ============================================ */
.timeline {
  position: relative;
  padding-left: var(--space-8);
}

.timeline::before {
  content: ''; position: absolute; left: 15px; top: 8px; bottom: 8px;
  width: 2px; background: var(--md-sys-color-outline-variant);
  border-radius: 1px;
}

.timeline-node {
  position: relative;
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-shape-corner-medium);
  box-shadow: var(--md-elevation-level1);
  transition: box-shadow var(--md-motion-duration-short1) var(--md-motion-easing-standard);
}

.timeline-node:hover { box-shadow: var(--md-elevation-level2); }

.timeline-node.current {
  border: 2px solid var(--md-sys-color-primary);
  box-shadow: 0 0 0 4px var(--md-sys-color-primary-container);
}

.timeline-node::before {
  content: ''; position: absolute;
  left: calc(-1 * var(--space-8) + 9px);
  top: var(--space-5);
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--md-sys-color-surface-container-lowest);
  border: 2px solid var(--md-sys-color-outline);
  z-index: 1;
}

.timeline-node.current::before {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 4px var(--md-sys-color-primary-container);
}

.timeline-node.done::before {
  background: var(--success);
  border-color: var(--success);
}

.tl-time {
  font-size: var(--md-typescale-label-small); font-weight: 600;
  color: var(--md-sys-color-primary);
  text-transform: none; letter-spacing: 0;
}

.tl-title {
  font-size: var(--md-typescale-body-medium); font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-top: var(--space-1);
}

.tl-desc {
  font-size: var(--md-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: var(--space-1); white-space: pre-line; line-height: 1.5;
}

.tl-meta {
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-2);
}

.tl-duration {
  font-size: var(--md-typescale-label-small); font-weight: 500;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  padding: 2px var(--space-2); border-radius: var(--md-shape-corner-extra-small);
}

.tl-status {
  font-size: var(--md-typescale-label-small); font-weight: 600;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 959px) {
  .nav-rail { display: none; }
  .main-content { padding: 0; }
  .app-shell { padding: var(--space-4) var(--space-4); }
}

@media (max-width: 768px) {
  /* ── 隐藏桌面导航，显示底部标签栏 ── */
  .tab-nav { display: none; }
  .bottom-tabs { display: block; }
  .app-shell { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

  /* ── 顶部标题栏 ── */
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) 0 var(--space-3);
  }
  .header-brand { gap: var(--space-2); }
  .header-logo { width: 32px; height: 32px; }
  .header-logo svg { width: 20px; height: 20px; }
  .header-title h1 { font-size: var(--md-typescale-title-medium); }
  .header-title p { font-size: var(--md-typescale-label-medium); }
  .header-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-1);
  }
  .header-actions .user-info {
    font-size: var(--md-typescale-label-small) !important;
  }
  .header-actions .user-info .material-symbols-rounded {
    font-size: 16px !important;
  }
  .date-picker {
    padding: 1px;
    border-radius: var(--md-shape-corner-small);
  }
  .date-picker button {
    width: 28px; height: 28px;
  }
  .date-picker .date-display {
    font-size: var(--md-typescale-label-medium);
    min-width: 85px;
  }
  .theme-toggle { width: 32px; height: 32px; }

  /* ── 数据网格 ── */
  .data-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .behavior-stats { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); }
  .stat-card { padding: var(--space-3); min-height: 80px; }

  /* ── FAB — 避开底部导航 ── */
  .fab { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); right: var(--space-4); width: 48px; height: 48px; font-size: 20px; }

  /* ── 清单卡片 ── */
  .checklist-item {
    flex-wrap: wrap;
    padding: var(--space-2);
    gap: var(--space-2);
  }
  .checklist-item .ci-seq { width: 28px; height: 28px; font-size: var(--md-typescale-label-small); }
  .ci-actions {
    flex-direction: row;
    width: 100%;
    justify-content: flex-end;
    gap: var(--space-1);
  }
  .status-btn { min-width: 48px; height: 32px; font-size: var(--md-typescale-label-medium); }
  .ci-remark-btn { font-size: var(--md-typescale-label-small); }
  .ci-meta { gap: var(--space-1); }

  /* ── 优先级组 ── */
  .priority-group-header { padding: var(--space-2) var(--space-3); }
  .priority-label { font-size: var(--md-typescale-body-medium); }
  .checklist-items { padding: 0 var(--space-2) var(--space-2); }

  /* ── 卡片 ── */
  .card { padding: var(--space-4); }
  .card + .card { margin-top: var(--space-3); }

  /* ── 模态框 ── */
  .modal { margin: var(--space-3); padding: var(--space-4); border-radius: var(--md-shape-corner-large); }

  /* ── Toast ── */
  .toast-container { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

  /* ── 周报表格 ── */
  .weekly-table th, .weekly-table td { padding: var(--space-2) var(--space-2); font-size: var(--md-typescale-body-small); }
  .behavior-table th, .behavior-table td { padding: var(--space-2) var(--space-2); font-size: var(--md-typescale-body-small); }

  /* ── Section header ── */
  .section-header h2 { font-size: var(--md-typescale-title-large); }
  .section-header .flex-between { flex-wrap: wrap; gap: var(--space-2); }

  /* ── Sub-tabs ── */
  .sub-tab { padding: var(--space-2) var(--space-2); font-size: var(--md-typescale-label-medium); }
}

@media (max-width: 480px) {
  .app-shell { padding: var(--space-3); padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .card { padding: var(--space-3); border-radius: var(--md-shape-corner-medium); }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: var(--space-2); }
  .data-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; gap: var(--space-2); }
  .score-table-wrap { font-size: var(--md-typescale-body-small); }
  .section-header h2 { font-size: var(--md-typescale-title-large); }
  .checklist-item { padding: var(--space-2); }
  .status-btn { min-width: 44px; height: 30px; font-size: var(--md-typescale-label-small); }

  /* ── 头部更紧凑 ── */
  .header-brand { gap: var(--space-1); }
  .header-logo { width: 28px; height: 28px; }
  .header-logo svg { width: 16px; height: 16px; }
  .header-title h1 { font-size: 1rem; }
  .header-title p { font-size: var(--md-typescale-label-small); }
  .header-actions { gap: var(--space-1); }
  .date-picker .date-display { font-size: var(--md-typescale-label-small); min-width: 72px; }
  .date-picker button { width: 24px; height: 24px; }
  .date-picker button .material-symbols-rounded { font-size: 16px; }

  /* ── 底部导航图标更紧凑 ── */
  .bottom-tab { min-height: 48px; padding: var(--space-1); }
  .bottom-tab .bottom-tab-icon { font-size: 20px; }
  .bottom-tab { font-size: 0.5625rem; }

  /* ── FAB 更小 ── */
  .fab { width: 44px; height: 44px; font-size: 18px; right: var(--space-3); bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }

  /* ── KPI 卡片 ── */
  .kpi-card { padding: var(--space-3); }
  .kpi-card .kpi-value { font-size: var(--md-typescale-headline-medium); }
  .stat-card .stat-value { font-size: var(--md-typescale-title-large); }

  /* ── 周报 ── */
  .chart-container { padding: var(--space-3); }
  .chart-container canvas { max-height: 240px !important; }

  /* ── 上传区 ── */
  .upload-zone { padding: var(--space-4); }
  .upload-icon { font-size: 2rem; }
}

/* ============================================
   Desktop Navigation Rail (≥960px)
   ============================================ */
@media (min-width: 960px) {
  .nav-rail { display: flex; }
  .tab-nav { display: none; }
  .bottom-tabs { display: none !important; }
  .app-shell { max-width: 960px; }
}

/* Misc utility classes */
.text-muted { color: var(--md-sys-color-on-surface-variant); }
.text-danger { color: var(--md-sys-color-error); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.gap-2 { gap: var(--space-2); }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ── 全部日期汇总表 ── */
.date-summary-table-wrap table th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); white-space: nowrap;
}
.summary-row:hover { background: var(--primary-bg) !important; }
.btn-xs {
  padding: 2px 8px; font-size: 11px; border-radius: 4px;
  border: 1px solid var(--border); cursor: pointer; font-family: inherit;
  background: var(--bg); color: var(--text);
}
.btn-xs:hover { background: var(--bg-subtle); }
.inline-flex { display: inline-flex; align-items: center; }

/* ============================================
   v3.9.2 角色权限：观察者(viewer)只读控制
   body.role-viewer 下隐藏所有写操作按钮
   body.role-admin 不限制
   ============================================ */
/* 写操作按钮容器（上传/导入/编辑/录入等） */
body.role-viewer .inline-flex.gap-2 { display: none !important; }
/* 二次级动作按钮（编辑清单、上传新周报等），排除导出类 */
body.role-viewer .btn.btn-sm.btn-secondary:not([id*="logout"]):not([id*="export"]) { display: none !important; }
/* 主要动作按钮（上传调款单、导入日报等） */
body.role-viewer .btn.btn-primary.btn-sm { display: none !important; }
/* outline 风格的写按钮 */
body.role-viewer .btn.btn-outline.btn-sm { display: none !important; }
/* file input 隐藏 */
body.role-viewer input[type="file"] { display: none !important; }
/* FAB */
body.role-viewer #fab-add { display: none !important; }
/* 删除按钮 */
body.role-viewer .checklist-status-btn,
body.role-viewer .adjustment-delete-btn,
body.role-viewer [data-adj-delete],
body.role-viewer [data-dr-del],
body.role-viewer .chip-del { display: none !important; }
/* 只读提示条 */
body.role-viewer .readonly-banner { display: block !important; }
body.role-viewer .btn-outline.btn-sm { display: none !important; }
.readonly-banner { display: none; background: #fff3e0; color: #e65100; padding: 8px 12px; border-radius: 8px; margin: 8px 0; font-size: 0.85rem; }
.cell-empty { color: var(--md-sys-color-outline); }