/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #F5F6F7;
  color: #333;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  max-width: 480px;
  margin: 0 auto;
}
#app {
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}
input, textarea, select, button { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* ===== Variables ===== */
:root {
  --primary: #1677FF;
  --primary-light: #E6F0FF;
  --success: #00B578;
  --success-light: #E6F9F1;
  --warning: #FF8F1F;
  --warning-light: #FFF3E5;
  --danger: #FF3141;
  --danger-light: #FFEBEC;
  --bg: #F5F6F7;
  --card: #FFFFFF;
  --text: #333333;
  --text-2: #666666;
  --text-3: #999999;
  --border: #EEEEEE;
  --radius: 12px;
  --radius-sm: 8px;
}

/* ===== Loading ===== */
.loading-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 16px; color: var(--text-3);
}
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Header ===== */
.header {
  background: var(--primary); color: #fff;
  padding: 12px 16px; position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding-top: env(safe-area-inset-top, 12px);
}
.header-title { font-size: 17px; font-weight: 600; }
.header-sub { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.header-back {
  display: flex; align-items: center; gap: 4px; color: #fff; font-size: 15px;
  background: none; border: none; cursor: pointer; padding: 4px 0;
}

/* ===== Cards ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin: 12px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.stat-num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.stat-card.primary .stat-num { color: var(--primary); }
.stat-card.danger .stat-num { color: var(--danger); }
.stat-card.success .stat-num { color: var(--success); }
.stat-card.warning .stat-num { color: var(--warning); }

/* ===== Action List ===== */
.section-title { font-size: 14px; font-weight: 600; color: var(--text-2); padding: 16px 16px 8px; }
.action-list { margin: 0 16px; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.action-item {
  display: flex; align-items: center; padding: 14px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s;
}
.action-item:last-child { border-bottom: none; }
.action-item:active { background: #F8F8F8; }
.action-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-right: 12px; flex-shrink: 0;
}
.action-icon.blue { background: var(--primary-light); color: var(--primary); }
.action-icon.red { background: var(--danger-light); color: var(--danger); }
.action-icon.green { background: var(--success-light); color: var(--success); }
.action-icon.orange { background: var(--warning-light); color: var(--warning); }
.action-text { flex: 1; }
.action-name { font-size: 15px; font-weight: 500; }
.action-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.action-arrow { color: var(--text-3); font-size: 18px; }

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; background: var(--card);
  display: flex; border-top: 1px solid var(--border); z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 0; color: var(--text-3); font-size: 11px; gap: 2px;
  transition: color 0.15s;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--primary); }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text-2); }
.form-label .required { color: var(--danger); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; background: var(--card);
  color: var(--text); transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-3); }

/* Radio buttons */
.radio-group { display: flex; gap: 8px; }
.radio-btn {
  flex: 1; padding: 10px; text-align: center; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; cursor: pointer; transition: all 0.15s;
  background: var(--card);
}
.radio-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 500; }

/* Buttons */
.btn {
  display: block; width: 100%; padding: 14px; border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 500; cursor: pointer; text-align: center; transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: var(--card); color: var(--primary); border: 1px solid var(--primary); }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ===== Tags ===== */
.tag {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
}
.tag-blue { background: var(--primary-light); color: var(--primary); }
.tag-green { background: var(--success-light); color: var(--success); }
.tag-orange { background: var(--warning-light); color: var(--warning); }
.tag-red { background: var(--danger-light); color: var(--danger); }
.tag-gray { background: #F0F0F0; color: var(--text-3); }

/* ===== List Items ===== */
.list-item {
  background: var(--card); margin: 0 16px 8px; border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.list-item-title { font-size: 15px; font-weight: 500; margin-bottom: 6px; }
.list-item-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.list-item-meta span { display: flex; align-items: center; gap: 2px; }

/* ===== Tabs ===== */
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.tab {
  flex: 1; padding: 12px; text-align: center; font-size: 14px;
  color: var(--text-3); cursor: pointer; position: relative; transition: color 0.15s;
}
.tab.active { color: var(--primary); font-weight: 500; }
.tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 3px; background: var(--primary); border-radius: 2px;
}

/* ===== Profile ===== */
.profile-header {
  background: var(--primary); color: #fff; padding: 24px 16px;
  display: flex; align-items: center; gap: 16px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
}
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,0.2); display: flex; align-items: center;
  justify-content: center; font-size: 24px; font-weight: 600;
}
.profile-name { font-size: 18px; font-weight: 600; }
.profile-role { font-size: 12px; opacity: 0.85; margin-top: 2px; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75); color: #fff; padding: 12px 24px;
  border-radius: 8px; font-size: 14px; z-index: 9999;
  animation: fadeIn 0.2s; max-width: 80%; text-align: center;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Empty State ===== */
.empty-state {
  text-align: center; padding: 48px 16px; color: var(--text-3);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 14px; }

/* ===== Misc ===== */
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.page-content { min-height: calc(100vh - 56px - 80px); }
#home-content, #home-todo { min-height: auto; padding-bottom: 0; }
.deadline-urgent { color: var(--danger); font-weight: 500; }

/* ===== Project Switcher ===== */
.project-switcher {
  display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer; padding: 2px 8px; margin-top: 2px;
  border-radius: 12px; background: rgba(255,255,255,0.15);
  transition: background 0.15s;
}
.project-switcher:active { background: rgba(255,255,255,0.25); }
.switch-arrow { font-size: 11px; opacity: 0.9; }

/* ===== Bottom Sheet ===== */
.bottom-sheet-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 999;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s;
}
.bottom-sheet {
  width: 100%; max-width: 480px; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 8px 0 16px;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 36px; height: 4px; background: var(--border); border-radius: 2px;
  margin: 4px auto 12px;
}
.sheet-title { font-size: 16px; font-weight: 600; text-align: center; padding: 0 16px 12px; color: var(--text); }
.sheet-list { max-height: 50vh; overflow-y: auto; }
.sheet-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; cursor: pointer; transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}
.sheet-item:last-child { border-bottom: none; }
.sheet-item:active { background: #F8F8F8; }
.sheet-item.active { color: var(--primary); font-weight: 500; }
.sheet-item-name { font-size: 15px; }
.sheet-item-check { color: var(--primary); font-size: 18px; }
.sheet-cancel {
  margin: 12px 16px 0; padding: 14px; text-align: center;
  font-size: 16px; color: var(--text-2); border-radius: var(--radius-sm);
  background: var(--bg); cursor: pointer;
}
.sheet-cancel:active { background: var(--border); }

/* ===== Small Buttons (record action buttons) ===== */
.btn-sm {
  display: inline-block; padding: 6px 14px; border: none; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer; transition: opacity 0.15s;
}
.btn-sm:active { opacity: 0.8; }
.btn-sm.btn-primary { background: var(--primary); color: #fff; }
.btn-sm.btn-success { background: var(--success); color: #fff; }
.btn-sm.btn-danger { background: var(--danger); color: #fff; }

/* ===== Action Button Group (on record cards) ===== */
.action-btn-group {
  margin-top: 10px; display: flex; gap: 8px; align-items: center;
}

/* ===== Active Role (profile page) ===== */
.action-item.active-role {
  background: #F0F7FF;
  border-left: 3px solid var(--primary);
}

/* ===== Image Uploader ===== */
.img-uploader { margin-top: 4px; }
.img-preview-list {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.img-preview-item {
  position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
}
.img-preview-item img {
  width: 100%; height: 100%; object-fit: cover; cursor: pointer;
}
.img-remove {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: rgba(0,0,0,0.6); color: #fff;
  border: none; font-size: 14px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.img-upload-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 72px; height: 72px; border: 2px dashed var(--border); border-radius: 8px;
  cursor: pointer; color: var(--text-3); transition: border-color 0.15s;
}
.img-upload-btn:active { border-color: var(--primary); }
.img-upload-icon { font-size: 24px; line-height: 1; }
.img-upload-text { font-size: 10px; margin-top: 2px; }

/* Image thumbnails in list items */
.img-thumb-list {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.img-thumb {
  width: 56px; height: 56px; border-radius: 6px; object-fit: cover; cursor: pointer;
}

/* Image viewer overlay */
.image-viewer-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s;
}
.image-viewer-img {
  max-width: 95%; max-height: 90vh; border-radius: 4px;
}

/* ===== Todo Center ===== */
#todo-list { padding-bottom: 8px; }

.todo-stats {
  display: flex; padding: 12px 16px; background: var(--card);
  margin: 0 0 8px;
}
.todo-stat {
  flex: 1; text-align: center; border-right: 1px solid var(--border);
}
.todo-stat:last-child { border-right: none; }
.todo-stat-num { font-size: 24px; font-weight: 700; }
.todo-stat-label { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.todo-stat.urgent .todo-stat-num { color: var(--danger); }
.todo-stat.total .todo-stat-num { color: var(--primary); }

.todo-item {
  background: var(--card); margin: 0 16px 8px; border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  border-left: 3px solid transparent;
}
.todo-item.urgent { border-left-color: var(--danger); }
.todo-item.warning { border-left-color: var(--warning); }
.todo-item.normal { border-left-color: var(--primary); }
.todo-item-type {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-3); margin-bottom: 4px;
}
.todo-item-title { font-size: 15px; font-weight: 500; }
.todo-item-meta {
  display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px;
  color: var(--text-3); margin-top: 6px;
}
.todo-item.need-confirm {
  border-left-color: var(--danger);
  background: linear-gradient(to right, #FFF8F8 0%, #FFF 30%);
}
.todo-confirm-badge {
  display: inline-block;
  background: var(--danger-light); color: var(--danger);
  font-size: 10px; font-weight: 500;
  padding: 1px 6px; border-radius: 8px;
  margin-left: 4px;
}
.todo-project-tag {
  display: inline-block;
  background: #F0F5FF; color: #1677FF;
  font-size: 10px; font-weight: 500;
  padding: 1px 6px; border-radius: 8px;
  margin-left: 4px;
}
.ms-box { border: 1px solid var(--border, #e5e5e5); border-radius: 8px; padding: 8px 10px; max-height: 180px; overflow: auto; background: var(--bg, #fff); }
.ms-item { display: flex; align-items: center; gap: 8px; padding: 7px 2px; font-size: 14px; border-bottom: 1px solid #f2f2f2; }
.link-btn { color: var(--primary, #1677FF); font-weight: 600; cursor: pointer; margin-left: 2px; }
.ms-item:last-child { border-bottom: none; }
.ms-item input { width: 16px; height: 16px; }
.dept-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px; border-bottom: 1px solid #f2f2f2; }
.dept-row:last-child { border-bottom: none; }
.dept-info { min-width: 0; }
.dept-name { font-size: 15px; font-weight: 500; }
.dept-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.dept-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn { border: 1px solid var(--border, #e5e5e5); background: #fff; border-radius: 6px; padding: 5px 9px; font-size: 12px; color: var(--text-2); cursor: pointer; }
.mini-btn.on { border-color: #1677FF; color: #1677FF; background: #F0F5FF; }
.mini-btn.danger { color: #cf1322; border-color: #ffccc7; }
