/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --warning: #d97706;
  --warning-hover: #b45309;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ===== Header ===== */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.header-left h2 { font-size: 18px; color: var(--text); }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-right .welcome { color: var(--text-secondary); font-size: 14px; }
.header-right .welcome strong { color: var(--text); }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.card-header {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 14px;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .2s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-control[readonly] { background: #f8fafc; }
textarea.form-control { resize: vertical; min-height: 120px; }
.form-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  gap: 6px;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: var(--warning-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-xs { padding: 3px 7px; font-size: 11px; border-radius: 4px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
/* 单行按钮组：始终不换行 */
.btn-row { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; }
.btn-row .btn, .btn-row form { flex-shrink: 0; }

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table th, table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
table td.content-cell { max-width: 300px; }
table td.status-cell,
table td.action-cell { white-space: nowrap; }

/* 内容预览：单行省略 + 点击展开 */
.content-preview {
    display: block;
    cursor: pointer;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    transition: color .15s;
}
.content-preview:hover { color: var(--primary); }
.content-preview.expanded {
    white-space: normal;
    word-break: break-word;
    max-width: none;
    overflow: visible;
}

/* 管理员提交审核表格：固定布局防止内容溢出 */
.admin-sub-table { table-layout: fixed; width: 100%; }
.admin-sub-table th { font-size: 12px; }
.admin-sub-table td { font-size: 13px; word-break: break-word; }
.admin-sub-table .content-th { width: 7%; }
.admin-sub-table td.content-cell { max-width: none; overflow: hidden; }
.admin-sub-table .content-preview { max-width: 100%; }
.admin-sub-table th:nth-child(1),
.admin-sub-table td:nth-child(1) { width: 40px; }
.admin-sub-table th:nth-child(2),
.admin-sub-table td:nth-child(2) { width: 95px; }
.admin-sub-table .project-name { display: block; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.admin-sub-table .project-name:hover { color: var(--primary); }
.admin-sub-table .project-name.expanded { white-space: normal; word-break: break-word; }
.admin-sub-table th:nth-child(3),
.admin-sub-table td:nth-child(3) { width: 65px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-sub-table th:nth-child(4),
.admin-sub-table td:nth-child(4) { width: 95px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-sub-table th:nth-child(7),
.admin-sub-table td:nth-child(7) { width: 74px; }
.admin-sub-table th:nth-child(8),
.admin-sub-table td:nth-child(8) { width: 74px; white-space: nowrap; }
.admin-sub-table th:nth-child(9),
.admin-sub-table td:nth-child(9) { width: 103px; white-space: nowrap; }
.admin-sub-table th:nth-child(10),
.admin-sub-table td:nth-child(10) { width: 58px; text-align: center; }
.admin-sub-table th:nth-child(11),
.admin-sub-table td:nth-child(11) { width: 44px; text-align: center; white-space: nowrap; }
.admin-sub-table th:nth-child(12),
.admin-sub-table td:nth-child(12) { width: 130px; }
.admin-sub-table .btn-sm { padding: 5px 8px; font-size: 12px; }
.admin-sub-table .btn-group { gap: 4px; flex-wrap: wrap; }

/* 失败原因小字 */
.failed-reason {
    font-size: 11px;
    color: var(--danger);
    margin-top: 3px;
    white-space: normal;
    word-break: break-all;
}
table tbody tr:hover { background: #f8fafc; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-submitted { background: #dbeafe; color: #1e40af; }
.badge-processing { background: #fef3c7; color: #92400e; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-failed { background: #fef2f2; color: #991b1b; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fef2f2; color: #991b1b; }
.badge-hidden { background: #f1f5f9; color: var(--text-muted); }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--card);
}
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: var(--text-muted); pointer-events: none; }

/* ===== Tabs ===== */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.tab {
  padding: 10px 20px;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Login Page ===== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 440px;
  padding: 32px;
}
.login-card h1 {
  font-size: 22px;
  text-align: center;
  margin-bottom: 6px;
  color: var(--text);
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}
.login-card .tabs { justify-content: center; }

/* ===== Install Page ===== */
.install-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.install-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  padding: 32px;
}
.install-card h1 { font-size: 22px; text-align: center; margin-bottom: 6px; }
.install-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }
.step-indicator {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  justify-content: center;
}

/* ===== Admin Layout ===== */
.admin-wrap { display: flex; min-height: calc(100vh - 57px); }
.admin-sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  padding: 16px 0;
  flex-shrink: 0;
}
.admin-sidebar .nav-item {
  display: block;
  padding: 12px 24px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: all .2s;
  border-left: 3px solid transparent;
}
.admin-sidebar .nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
  text-decoration: none;
}
.admin-sidebar .nav-item.active {
  background: rgba(37,99,235,.15);
  color: #fff;
  border-left-color: var(--sidebar-active);
}
.admin-sidebar-title {
  padding: 8px 24px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 12px;
}
.admin-content { flex: 1; padding: 24px; min-width: 0; }

/* ===== Sidebar Toggle (Mobile) ===== */
.sidebar-toggle {
  display: none;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 18px;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ===== Image Preview ===== */
.img-preview {
  max-width: 200px;
  max-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 8px;
}

/* ===== Image Upload List ===== */
.image-upload-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.image-upload-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.image-upload-item span {
  min-width: 56px;
  color: var(--text-secondary);
  font-size: 13px;
  flex-shrink: 0;
}
.image-upload-item input[type="file"] {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}
.image-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
  padding: 0;
}
.image-clear-btn:hover {
  background: var(--danger-hover);
}

/* ===== File Upload ===== */
.file-upload-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state p { font-size: 15px; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar select, .filter-bar input { padding: 8px 10px; }

/* ===== User Detail ===== */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.detail-item label { font-size: 12px; color: var(--text-muted); display: block; }
.detail-item span { font-size: 15px; font-weight: 500; }

/* ===== Settings Grid (change_password) ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.settings-grid .card { margin-bottom: 0; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .card { padding: 16px; }
  .card-header { font-size: 16px; }
  .header .container { flex-direction: column; align-items: flex-start; }
  .header-right { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 4px 6px; }
  .header-right .welcome { width: 100%; font-size: 13px; white-space: nowrap; margin-bottom: 2px; }
  .header-right .btn-sm { flex: 1; min-width: 0; padding: 5px 4px; font-size: 12px; white-space: nowrap; text-align: center; }
  .form-row { flex-direction: column; gap: 0; }
  .btn-group { flex-direction: column; }
  .btn-group .btn { width: 100%; }
  .admin-sub-table .btn-group { flex-direction: row; }
  .admin-sub-table .btn-group .btn { width: auto; }
  .btn-row { flex-wrap: nowrap !important; }
  .btn-row .btn { flex-shrink: 1; white-space: nowrap; font-size: 14px; padding: 8px 14px; }

  /* 图片上传：手机端标签和输入框上下排列，防止横向滚动 */
  .image-upload-item {
    flex-wrap: wrap;
  }
  .image-upload-item span {
    min-width: 0;
    width: 100%;
  }
  .image-upload-item input[type="file"] {
    flex: 1;
    min-width: 0;
    max-width: 100%;
  }

  /* 防止iOS输入框聚焦时页面自动缩放 */
  input.form-control, select.form-control, textarea.form-control { font-size: 16px; }
  textarea.form-control { min-height: 80px; height: 120px; }

  /* 设置页面：上下排列 */
  .settings-grid { grid-template-columns: 1fr; }

  /* 管理后台侧边栏：上3下3两行网格，去掉菜单按钮 */
  .admin-wrap { flex-direction: column; }
  .admin-sidebar {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    position: static !important;
    z-index: auto !important;
    padding: 0 !important;
  }
  .admin-sidebar .nav-item {
    border-left: none !important;
    border-bottom: 3px solid transparent;
    text-align: center;
    padding: 12px 4px;
    font-size: 13px;
    white-space: nowrap;
  }
  .admin-sidebar .nav-item.active {
    background: rgba(37,99,235,.15);
    border-bottom-color: var(--sidebar-active);
  }
  .sidebar-toggle { display: none !important; }
  .admin-content { padding: 16px; }

  .login-card, .install-card { padding: 24px 16px; }

  /* 通用表格紧凑 */
  table th, table td { padding: 8px 6px; font-size: 13px; white-space: normal; }
  table th { font-size: 11px; white-space: nowrap; }
  table td.content-cell { max-width: 120px; }

  /* 项目列表专用：固定列宽防止左右滑动 */
  .project-table { table-layout: fixed; width: 100%; }
  .project-table th:nth-child(2), .project-table td:nth-child(2) { width: 56px; }
  .project-table th:nth-child(3), .project-table td:nth-child(3),
  .project-table th:nth-child(4), .project-table td:nth-child(4),
  .project-table th:nth-child(5), .project-table td:nth-child(5) { width: 32px; text-align: center; }
  .project-table th:nth-child(6), .project-table td:nth-child(6) { width: 60px; }
  .project-table .title-cell { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .project-table .desc-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
  .project-table .reward-cell { white-space: nowrap; font-size: 13px; }
  .project-table .stat-cell { font-size: 12px; white-space: nowrap; }
  .project-table td:last-child { white-space: nowrap; }

  /* 我的提交列表专用 */
  .submission-table td, .submission-table th { vertical-align: middle; }
  .submission-table td.content-cell { max-width: 55px; padding-left: 6px; }
  .submission-table .content-preview { max-width: 55px; font-size: 12px; }
  .submission-table .btn-xs { min-width: 22px; text-align: center; padding: 3px 5px; }
  .submission-table .time-col { font-size: 10px; white-space: nowrap; color: var(--text-muted); }
  .submission-table .status-cell { white-space: nowrap; }
  .submission-table .status-cell .badge { font-size: 10px; padding: 2px 6px; white-space: nowrap; }
  .submission-table .failed-reason { font-size: 10px; }

  /* 管理员提交审核表格手机适配 */
  .admin-sub-table { table-layout: auto; }
  .admin-sub-table .content-th { width: auto; }
  .admin-sub-table td.content-cell { max-width: 100px; }

  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { width: 100%; }
  .filter-bar select, .filter-bar input { width: 100%; }
}

@media (max-width: 480px) {
  .detail-grid { grid-template-columns: 1fr; }
  .modal { padding: 16px; }
}
