/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== Variables ===== */
:root {
  --gray-50: #f8f8f8;
  --gray-100: #efefef;
  --gray-200: #ddd;
  --gray-400: #aaa;
  --gray-600: #666;
  --gray-800: #222;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --transition: .15s ease;
}

/* ===== Base ===== */
body {
  font-family: system-ui, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  font-size: 15px;
}
h1 { font-size: 1.4rem; margin-bottom: 20px; }
h2 { font-size: 1.1rem; margin: 24px 0 12px; color: var(--gray-600); }

/* ===== Layout ===== */
.container { max-width: 800px; margin: 0 auto; padding: 24px 16px; }
.container-wide { max-width: 1280px; margin: 0 auto; padding: 24px 16px; }


/* ===== Card ===== */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.board-table-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
}
/* ===== Navigation ===== */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 24px;
}
nav a {
  display: inline-block;
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--gray-600);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color var(--transition);
}
nav a:hover { color: var(--accent); }
nav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--gray-600);
  padding: 6px 0;
}
.nav-user .role-badge {
  background: var(--gray-100);
  border-radius: 99px;
  padding: 2px 8px;
  font-size: 0.78rem;
  color: var(--gray-600);
}
.nav-user a.logout {
  padding: 4px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--gray-600);
  text-decoration: none;
}
.nav-user a.logout:hover { background: var(--gray-100); color: var(--gray-800); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  min-height: 36px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm {
  padding: 5px 12px;
  min-height: 30px;
  font-size: 0.82rem;
}
.btn-submit {
  width: 100%;
  padding: 10px;
  min-height: 38px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-submit:hover { background: var(--accent-dark); }
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  color: var(--gray-800);
  border: 1px solid var(--gray-200);
  font-size: 0.8rem;
  padding: 4px 10px;
  min-height: 28px;
  border-radius: var(--radius);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition);
}
.btn-action:hover { background: var(--gray-200); }

/* ===== Form ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--gray-600); margin-bottom: 4px; }
.field label .required { color: var(--danger); margin-left: 2px; }
.field input,
.field select,
.field textarea {
  width: 100%;
  height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--gray-50);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field textarea { height: auto; }
.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
  background: #fff;
}

/* ===== Alert ===== */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.alert-error { background: #fee2e2; color: var(--danger); }
.alert-cancelled {
  background: #fee2e2;
  color: var(--danger);
  font-weight: 600;
  font-size: 1rem;
  border-left: 4px solid var(--danger);
}

/* ===== Badge ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.78rem;
  background: var(--gray-100);
  color: var(--gray-600);
}
.badge-active { background: #dbeafe; color: var(--accent-dark); }
.badge-overdue { background: #fee2e2; color: var(--danger); }

/* ===== Info Grid ===== */
dl.info { display: grid; grid-template-columns: 7em 1fr; gap: 6px 12px; }
dl.info dt { color: var(--gray-600); font-size: 0.85rem; }
dl.info dd { font-size: 0.95rem; }

/* ===== Timeline ===== */
.timeline { list-style: none; border-left: 2px solid var(--gray-200); padding-left: 16px; }
.timeline li { position: relative; margin-bottom: 12px; font-size: 0.88rem; }
.timeline li::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline .ts { color: var(--gray-400); font-size: 0.8rem; }

/* ===== Board Table ===== */
.board-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.board-table {
  width: 100%;
  min-width: 1200px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.board-table th {
  padding: 8px 12px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  vertical-align: middle;
}
.board-table td {
  padding: 12px 16px;
  text-align: center;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
  white-space: nowrap;
}
/* 表头内筛选下拉框 */
.th-filter {
  display: block;
  width: 65px;
  margin: 4px auto 0;
  padding: 0 18px 0 6px;
  height: 26px;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca3af'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  background-size: 8px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  color: var(--gray-600);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.2s;
}
.th-filter:hover,
.th-filter:focus {
  border-color: var(--accent);
  outline: none;
}

/* ===== 设置页网格布局 ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: #f8f9fa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.setting-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--gray-800);
}
.setting-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.setting-input {
  width: 60px;
  height: 32px;
  text-align: center;
  padding: 0 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.9rem;
}
.setting-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.setting-unit {
  font-size: 0.85rem;
  color: var(--gray-600);
}
@media (max-width: 767px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
.board-row { cursor: pointer; transition: background var(--transition); }
.board-row:hover { background: #f0f6ff; }
.row-overdue { background: #fff8f8; }
.row-overdue:hover { background: #fee2e2; }
.row-completed { background: #f0fdf4; }
.row-completed td { color: #4b7c59; }
.row-completed:hover { background: #dcfce7; }
.row-cancelled td { color: #999; text-decoration: line-through; }
.row-cancelled { background: #f7f7f7; }
.row-cancelled:hover { background: #eeeeee; }
.col-muted { color: var(--gray-600); }
.col-customer { font-weight: 500; }
.col-sm { font-size: 0.83rem; }
.col-remark {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-repair {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  border-radius: 3px;
  vertical-align: middle;
  line-height: 1.6;
}

/* ===== Personnel Table ===== */
.personnel-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.personnel-th {
  padding: 12px 16px;
  text-align: center;
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  vertical-align: middle;
}
.personnel-row { border-bottom: 1px solid var(--gray-100); }
.personnel-row--inactive { color: var(--gray-400); }
.personnel-td {
  padding: 12px 16px;
  text-align: center;
  vertical-align: middle;
}
.personnel-td--muted { color: var(--gray-600); }
.personnel-row--inactive .personnel-td--muted { color: var(--gray-400); }
.personnel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
}
.personnel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 12px;
  min-height: 30px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  color: var(--gray-800);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.personnel-btn:hover { background: var(--gray-50); }
.personnel-btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.personnel-btn--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.personnel-btn--danger {
  border-color: var(--danger);
  color: var(--danger);
}
.personnel-btn--danger:hover { background: #fee2e2; }
.personnel-btn--success {
  border-color: var(--success);
  color: var(--success);
}
.personnel-btn--success:hover { background: #dcfce7; }
.personnel-input {
  padding: 4px 8px;
  height: 30px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.88rem;
  width: 120px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.personnel-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.fw-600 { font-weight: 600; }
.text-xs { font-size: 0.78rem; }

/* Board 页头部布局 */
.board-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.board-header h1 { margin: 0; }
.board-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.85rem;
}

/* Board 筛选栏 */
.board-filter-card {
  margin-bottom: 16px;
  padding: 14px 16px;
}
.board-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.board-filter-field {
  margin: 0;
  flex: 2;
  min-width: 160px;
}
.board-filter-field label { font-size: 0.8rem; }

/* 按钮变体 */
.btn-gray {
  background: var(--gray-100);
  color: var(--gray-800);
}
.btn-filter-submit { align-self: flex-end; }
.board-empty-cell { text-align: center; color: var(--gray-400); padding: 40px; }

/* Order Detail 页面 */
.badge-completed { background: #dcfce7; color: #166534; font-size: 0.75rem; vertical-align: middle; margin-left: 8px; }
.badge-cancelled { background: #fee2e2; color: #991b1b; font-size: 0.75rem; vertical-align: middle; margin-left: 8px; }
.detail-edit-btn { float: right; margin-top: -4px; }
.repair-remark-hint { color: var(--gray-600); font-size: 0.88rem; }
.repair-current { margin-bottom: 12px; color: #d97706; font-weight: 600; }
.restore-hint { color: var(--gray-600); font-size: 0.88rem; margin: 0 0 10px; }
.qr-wrap { margin-top: 10px; display: flex; align-items: flex-end; gap: 10px; }
.qr-img { width: 140px; height: 140px; border: 1px solid var(--gray-200); border-radius: 6px; }
.token-missing { color: var(--gray-400); }
.token-regen-form { display: inline; margin-left: 8px; }
.ops-section-title { margin-top: 0; }
.ops-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: flex-start; margin-bottom: 16px; }
.rollback-form-wrap { display: none; margin-bottom: 16px; }
.cancel-form-wrap { display: none; margin-bottom: 8px; }
.repair-form-wrap { display: none; }
.btn-rollback { background: #92400e; color: #fff; }
.btn-cancel-outline { background: #fff; border: 1px solid var(--danger); color: var(--danger); padding: 6px 14px; border-radius: 6px; font-size: 0.88rem; cursor: pointer; line-height: 1.5; }
.btn-ml-8 { margin-left: 8px; }
.timeline-repair { border-left-color: #d97706; background: rgba(251,191,36,0.06); padding-left: 12px; margin-left: -12px; border-radius: 0 4px 4px 0; }
.timeline-repair-label { color: #d97706; font-weight: 600; }
.timeline-remark { font-size: 0.85rem; }
.timeline-remark--repair { color: #92400e; }
.timeline-remark--normal { color: var(--gray-600); }
.timeline-empty { color: var(--gray-400); }

/* Personnel 页新增表单 */
.personnel-add-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.personnel-add-field {
  margin: 0;
  flex: 1;
  min-width: 120px;
}
.personnel-add-btn { flex-shrink: 0; }
.personnel-table-card { padding: 0; overflow: hidden; }
.name-edit-wrap { display: none; }
.name-edit-form { display: inline-flex; gap: 6px; align-items: center; }
.badge-inactive { background: var(--gray-100); color: var(--gray-400); }

/* ===== Login Page ===== */
body.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-box h1 { font-size: 1.2rem; margin-bottom: 24px; text-align: center; }
.login-box .field { margin-bottom: 16px; }

/* ===== Toast ===== */
#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(34,34,34,.92);
  color: #fff;
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#toast.show { opacity: 1; }

/* ===== Responsive ===== */
@media (max-width: 767px) {
  nav {
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 0;
  }
  nav a { padding: 8px 12px; }
  .nav-spacer { display: none; }
  .nav-user {
    width: 100%;
    border-top: 1px solid var(--gray-200);
    padding: 8px 2px 6px;
    font-size: 0.82rem;
    gap: 8px;
    justify-content: flex-end;
  }

  .container { padding: 16px 12px; }
  h1 { font-size: 1.2rem; }

  .card { padding: 16px; }

  .field input,
  .field select,
  .field textarea {
    font-size: 1rem;
    height: auto;
    padding: 12px;
  }
  .field select {
    background-position: right 12px center;
    padding-right: 36px;
  }

  dl.info { grid-template-columns: 5.5em 1fr; }

  .col-secondary { display: none; }
  .col-hide-mobile { display: none; }

  .btn-block-mobile {
    width: 100%;
    justify-content: center;
  }
}
