:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e4e7ec;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- 顶栏 ---- */
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 24px;
}
.navbar .brand { font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.navbar nav { display: flex; gap: 4px; flex: 1; }
.navbar nav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
}
.navbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.navbar nav a.active { background: #eff4ff; color: var(--primary); font-weight: 500; }
.navbar .user-area { display: flex; align-items: center; gap: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.navbar .user-area img { width: 28px; height: 28px; border-radius: 6px; }

/* ---- 布局 ---- */
.container { max-width: 1040px; margin: 24px auto; padding: 0 24px; }
.container.narrow { max-width: 460px; }
.container.form { max-width: 760px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { min-width: 0; font-size: 20px; margin: 0; overflow-wrap: anywhere; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 0 auto 16px;
}
.card h2 { font-size: 16px; margin: 0 0 16px; }

/* ---- 表单 ---- */
label { display: block; font-weight: 500; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 120px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.error-text { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { margin: 0; font-weight: 400; }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

.attachment-upload label:first-child { margin-bottom: 8px; }
.upload-native-input { display: none; }
.upload-dropzone {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 92px;
  padding: 16px;
  border: 1px dashed #b9c3d4;
  border-radius: 8px;
  background: #f9fbff;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.upload-dropzone:hover,
.upload-dropzone:focus,
.upload-dropzone.is-dragging {
  border-color: var(--primary);
  background: #f2f7ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
  outline: none;
}
.upload-dropzone.has-error {
  border-color: #fca5a5;
  background: #fff7f7;
}
.upload-mark {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #e8f0ff;
  color: var(--primary);
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
}
.upload-copy { min-width: 0; }
.upload-title {
  display: block;
  color: var(--text);
  font-weight: 600;
}
.upload-hint {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
}
.upload-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.upload-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.upload-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.upload-file-details {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}
.upload-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.upload-file-size {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
}
.upload-file-remove {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}
.upload-file-remove:hover {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}
.upload-error {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 12.5px;
}

/* ---- 按钮 ---- */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
.btn.block { width: 100%; text-align: center; }

/* ---- 提示条 ---- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert ul { margin: 0; padding-left: 18px; }

/* ---- 表格 ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
td .sub { color: var(--muted); font-size: 12.5px; }

/* ---- 徽章 ---- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.st-open { background: #fef3c7; color: #92400e; }
.badge.st-in_progress { background: #dbeafe; color: #1e40af; }
.badge.st-waiting_reply { background: #fae8ff; color: #86198f; }
.badge.st-resolved { background: #d1fae5; color: #065f46; }
.badge.st-closed { background: #e5e7eb; color: #4b5563; }
.badge.pr-low { background: #f1f5f9; color: #475569; }
.badge.pr-medium { background: #e0f2fe; color: #075985; }
.badge.pr-high { background: #ffedd5; color: #9a3412; }
.badge.pr-urgent { background: #fee2e2; color: #991b1b; }
.badge.cat { color: #fff; }
.badge.internal { background: #fef9c3; color: #854d0e; }

/* ---- 工单对话 ---- */
.thread { display: flex; flex-direction: column; gap: 12px; }
.message {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 14px 16px;
}
.message.staff { border-left: 3px solid var(--primary); }
.message.internal { background: #fffbeb; border-color: #fde68a; }
.message .meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.message .meta .author { color: var(--text); font-weight: 600; font-size: 13.5px; }
.message .content { white-space: pre-wrap; word-break: break-word; }
.message .files { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.message .files .file-download {
  font-size: 12.5px;
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--bg);
}
.file-preview {
  width: min(260px, 100%);
  margin: 0;
}
.file-preview a {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}
.file-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}
.file-preview figcaption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* ---- 筛选栏 ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filters select, .filters input { width: auto; }
.mail-test-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}
.mail-test-grid .field { margin-bottom: 0; }
.mail-test-grid .btn {
  min-height: 38px;
  white-space: nowrap;
}
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tabs a { padding: 6px 14px; border-radius: 8px; color: var(--muted); }
.tabs a.active { background: #eff4ff; color: var(--primary); font-weight: 500; text-decoration: none; }
.tabs a:hover { text-decoration: none; background: var(--bg); }

/* ---- 分页 ---- */
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.pagination a, .pagination span {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.disabled { color: #c0c4cc; }
.pagination a:hover { text-decoration: none; background: var(--bg); }

/* ---- 统计卡片 ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: 12.5px; }

/* ---- 绑定验证码 ---- */
.bind-code {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 10px;
  text-align: center;
  padding: 18px 0;
  background: var(--bg);
  border-radius: var(--radius);
  margin: 12px 0;
  user-select: all;
}
.bind-status { text-align: center; color: var(--muted); }
.bind-status.ok { color: #047857; font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: 100px 1fr; gap: 6px 12px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }

.ticket-overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 28px;
  align-items: start;
  padding: 28px;
}
.ticket-overview-main { min-width: 0; }
.ticket-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.ticket-no {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}
.ticket-detail-grid {
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px 20px;
  max-width: 600px;
}
.ticket-detail-grid dt {
  font-weight: 600;
}
.ticket-detail-grid dd {
  min-width: 0;
  color: var(--text);
  font-weight: 500;
  overflow-wrap: anywhere;
}
.ticket-actions-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}
.ticket-actions-title {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}
.ticket-actions-stack,
.ticket-action-form {
  display: grid;
  gap: 12px;
}
.ticket-action-form + .ticket-action-form {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.ticket-action-label {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.ticket-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.ticket-action-row select,
.ticket-action-row .btn,
.ticket-action-full {
  min-height: 38px;
}
.ticket-action-row .btn,
.ticket-action-full {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.ticket-action-full {
  width: 100%;
}

.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.auth-title { text-align: center; font-size: 20px; margin: 32px 0 20px; }
.auth-foot { text-align: center; color: var(--muted); margin-top: 16px; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

@media (max-width: 720px) {
  .navbar { padding: 0 12px; gap: 8px; overflow-x: auto; }
  .container { padding: 0 12px; margin-top: 16px; }
  .page-head { align-items: flex-start; }
  .upload-dropzone { grid-template-columns: auto minmax(0, 1fr); }
  .upload-action { grid-column: 1 / -1; width: 100%; }
  .mail-test-grid { grid-template-columns: 1fr; }
  .mail-test-grid .btn { width: 100%; }
  .ticket-overview { grid-template-columns: 1fr; padding: 20px; gap: 20px; }
  th, td { padding: 8px; }
}

@media (max-width: 560px) {
  .ticket-detail-grid { grid-template-columns: 1fr; gap: 4px; }
  .ticket-detail-grid dt:not(:first-child) { margin-top: 10px; }
  .ticket-action-row { grid-template-columns: 1fr; }
  .ticket-action-row .btn { width: 100%; }
}
