:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --bg-card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.center { text-align: center; }

/* ===== Topbar ===== */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 8px; }
.brand { font-weight: 800; font-size: 18px; color: var(--primary); cursor: pointer; letter-spacing: 1px; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: all .15s;
  white-space: nowrap;
}
.nav a:hover { color: var(--primary); background: var(--primary-light); }
.nav a.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.topbar-right { display: flex; gap: 8px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
  line-height: 1;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { color: var(--primary); background: var(--primary-light); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

/* ===== Cards ===== */
.card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 16px; }
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* ===== Forms ===== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field label .req { color: var(--danger); margin-left: 2px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 90px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row .field { flex: 1; }

/* ===== Auth page ===== */
.auth-wrap { max-width: 420px; margin: 40px auto; }
.auth-card { background: var(--bg-card); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px 28px; }
.auth-title { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.auth-sub { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 24px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row button { white-space: nowrap; }

/* ===== Stat / hero ===== */
.hero { padding: 40px 0 8px; }
.hero h1 { font-size: 26px; font-weight: 800; }
.hero p { color: var(--text-muted); margin-top: 6px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 20px; }
.stat { background: var(--bg-card); border-radius: 12px; padding: 18px; text-align: center; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat .lbl { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ===== Step indicator ===== */
.steps { display: flex; align-items: center; gap: 6px; margin: 10px 0 24px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.step .dot { width: 24px; height: 24px; border-radius: 50%; background: var(--border); color: var(--text-muted); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.step.active .dot { background: var(--primary); color: #fff; }
.step.done .dot { background: var(--success); color: #fff; }
.step .txt { font-size: 13px; color: var(--text-muted); }
.step.active .txt, .step.done .txt { color: var(--text); font-weight: 600; }
.step-arrow { color: var(--border); }

/* ===== Tracks ===== */
.track-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.track { position: relative; border: 2px solid var(--border); border-radius: 12px; padding: 18px; cursor: pointer; transition: all .15s; background: #fff; }
.track:hover { border-color: var(--primary); }
.track.selected { border-color: var(--primary); background: var(--primary-light); }
.track .t-name { font-weight: 700; font-size: 16px; }
.track .t-desc { font-size: 13px; color: var(--text-muted); margin-top: 6px; min-height: 36px; }
.track .t-check { position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 12px; color: #fff; }
.track.selected .t-check { background: var(--primary); border-color: var(--primary); }

/* ===== Upload ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 26px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  background: #fafafa;
}
.upload-zone:hover { border-color: var(--primary); color: var(--primary); }
.upload-zone.busy { pointer-events: none; opacity: .6; }
.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.file-item { display: flex; align-items: center; gap: 10px; background: #f9fafb; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.file-item .fi-icon { font-size: 20px; }
.file-item .fi-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fi-size { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.file-item .fi-del { cursor: pointer; color: var(--danger); font-size: 18px; padding: 0 4px; border: none; background: none; }
.file-item .fi-status { font-size: 12px; }
.file-item .fi-status.ok { color: var(--success); }
.file-item .fi-status.err { color: var(--danger); }
.fi-progress { height: 3px; background: var(--border); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.fi-progress div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 700px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { background: #f9fafb; font-size: 12px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; }
table.data tr:hover td { background: #fafafa; }
@media (max-width: 720px) {
  table.data { font-size: 13px; }
  table.data th, table.data td { padding: 9px 8px; }
}

/* ===== Status badges ===== */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.approved { background: #dcfce7; color: #166534; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.neutral { background: var(--border); color: var(--text-muted); }

/* ===== Filter bar ===== */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .field { margin-bottom: 0; min-width: 140px; }
.filters .field input, .filters .field select { padding: 9px 10px; font-size: 13px; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  background: none; border: none; padding: 10px 14px; font-size: 14px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Misc ===== */
.banner {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: #fff; border-radius: 16px; padding: 28px; margin-bottom: 20px;
}
.banner h2 { font-size: 22px; }
.banner p { opacity: .9; margin-top: 6px; }
.banner .btn { margin-top: 16px; background: #fff; color: var(--primary); }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.material-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); text-decoration: none; margin-right: 8px; font-size: 13px; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal img { max-width: 100%; max-height: 90vh; border-radius: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; top: 24px; transform: translateX(-50%) translateY(-20px);
  background: rgba(17,24,39,.92); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .3s; z-index: 300; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: rgba(220,38,38,.95); }
.toast.ok { background: rgba(22,163,74,.95); }

/* ===== Loading ===== */
.loading, .page-loading { text-align: center; color: var(--text-muted); padding: 60px 0; font-size: 15px; }
.spinner { display: inline-block; width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Desktop / responsive ===== */
@media (max-width: 720px) {
  .topbar { height: auto; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; row-gap: 4px; }
  .nav { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .form-row { flex-direction: column; gap: 0; }
  .card { padding: 18px; }
  .banner { padding: 22px; }
  .auth-wrap { margin: 20px auto; }
  .steps { gap: 4px; }
  .step .txt { font-size: 12px; }
}
