:root {
  --orange: #ff7a1a;
  --orange-600: #f0640a;
  --orange-50: #fff3e9;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a9099;
  --line: #ececf0;
  --green: #1fab5a;
  --green-50: #e8f8ef;
  --red: #e54848;
  --red-50: #fdeaea;
  --blue: #2f6fed;
  --blue-50: #eaf1fe;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(20, 23, 28, .06);
  --shadow-lg: 0 8px 30px rgba(20, 23, 28, .14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  background: var(--orange);
  color: #fff;
  transition: filter .15s ease, transform .05s ease;
}
button:hover { filter: brightness(1.04); }
button:active { transform: translateY(1px); }
button.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: #fafafa; }
button.subtle { background: var(--orange-50); color: var(--orange-600); }
button.danger { background: var(--red); }
button.danger.ghost { background: #fff; color: var(--red); border: 1px solid #f3c9c9; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--orange); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 5px; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #fff3e9 0%, #f6f7f9 55%);
  padding: 20px;
}
.login-card {
  width: 360px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 30px 26px;
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-brand h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 1px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 12px; }
.login-form .row { margin-bottom: 14px; }
.login-form .hint { font-size: 11px; color: var(--muted); margin-top: 4px; min-height: 14px; }
.login-form .phone-row { display: flex; gap: 8px; margin-bottom: 10px; }
.login-form .phone-row input { flex: 1; }
.login-form .primary.full { width: 100%; margin-top: 2px; }
.login-or { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 14px; }
.login-or::before, .login-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.login-or span { padding: 0 10px; }
.login-msg {
  background: var(--orange-50);
  color: var(--orange-600);
  border: 1px solid #ffd9b8;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  margin-bottom: 14px;
}
.wechat-btn {
  width: 100%;
  background: #07c160;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
}
.wechat-btn:hover { background: #06ad56; filter: none; }
.wechat-btn:disabled { opacity: .6; cursor: not-allowed; }
.wechat-btn .wx-ic { font-size: 18px; }

/* ---------- App shell ---------- */
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-box #user-name { font-weight: 600; }
.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--orange-50);
  color: var(--orange-600);
  font-weight: 600;
}
.role-badge.admin { background: #1f2329; color: #fff; }
.user-box button { padding: 6px 12px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: transparent;
  color: var(--muted);
  border-radius: 10px 10px 0 0;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}
.tab.active { color: var(--orange-600); background: var(--orange-50); }
.tab:not(.active):hover { background: #f3f4f6; color: var(--text); }

main { padding: 18px 20px 60px; max-width: 1180px; margin: 0 auto; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .group { display: flex; align-items: center; gap: 6px; }
.toolbar .group label { margin: 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 14px; }

/* ---------- Schedule ---------- */
.week-nav { display: flex; align-items: center; gap: 12px; }
.week-nav .range { font-weight: 600; min-width: 200px; text-align: center; }
.view-toggle { display: inline-flex; background: #f0f1f3; border-radius: 10px; padding: 3px; }
.view-toggle button { background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; font-weight: 600; }
.view-toggle button.active { background: #fff; color: var(--orange-600); box-shadow: var(--shadow); }

.sched-scroll { overflow-x: auto; }
table.sched {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 720px;
}
table.sched th, table.sched td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  text-align: center;
  font-size: 12.5px;
}
table.sched th:first-child, table.sched td:first-child {
  border-left: 1px solid var(--line);
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
  min-width: 120px;
}
table.sched thead th {
  background: #fafafa;
  font-weight: 600;
  color: var(--muted);
  position: sticky;
  top: 0;
}
table.sched thead th:first-child { z-index: 3; }
table.sched .date-col .d { font-weight: 700; color: var(--text); }
table.sched .date-col .w { font-size: 11px; color: var(--muted); display: block; }
table.sched .date-col.today .d { color: var(--orange-600); }
.cell { min-height: 38px; border-radius: 8px; display: flex; align-items: center; justify-content: center; gap: 4px; cursor: pointer; flex-direction: column; }
.cell:hover { background: var(--orange-50); }
.cell .shift { font-weight: 600; }
.cell.rest .shift { color: var(--green); }
.cell.rest { background: var(--green-50); }
.cell.empty { color: var(--muted); }
.cell.fixed .tag { font-size: 10px; color: var(--muted); }
.cell .pending { font-size: 10px; color: var(--orange-600); background: var(--orange-50); border-radius: 6px; padding: 0 5px; }
.cell.rule-limited { outline: 1px dashed var(--red); }
.cell.rule-forbidden { background: var(--red-50); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Tickets ---------- */
.ticket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.ticket {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .15s ease, transform .05s ease;
}
.ticket:hover { border-color: var(--orange); }
.ticket h3 { margin: 0 0 6px; font-size: 15px; }
.ticket .meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.ticket .desc { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pill { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600; }
.pill.p-low { background: #eef1f4; color: #5b6470; }
.pill.p-normal { background: var(--blue-50); color: var(--blue); }
.pill.p-high { background: #fff2e0; color: #d97706; }
.pill.p-urgent { background: var(--red-50); color: var(--red); }
.pill.s-open { background: var(--orange-50); color: var(--orange-600); }
.pill.s-in_progress { background: var(--blue-50); color: var(--blue); }
.pill.s-resolved { background: var(--green-50); color: var(--green); }
.pill.s-closed { background: #eef1f4; color: #5b6470; }
.att-badge { font-size: 11px; color: var(--muted); }

/* ---------- Admin tables ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafafa; }
table.list tr:hover td { background: #fcfcfd; }
table.list .actions { display: flex; gap: 6px; }
table.list .actions button { padding: 5px 10px; font-size: 12px; }
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtabs button { background: #f0f1f3; color: var(--muted); }
.subtabs button.active { background: var(--orange); color: #fff; }
.empty-state { text-align: center; color: var(--muted); padding: 30px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(20, 23, 28, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 18px;
  width: 460px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 22px;
}
.modal.wide { width: 600px; }
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal .field { margin-bottom: 14px; }
.modal .field-row { display: flex; gap: 10px; }
.modal .field-row > div { flex: 1; }
.modal .modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  transition: border-color .15s ease, background .15s ease;
  cursor: pointer;
}
.dropzone.drag { border-color: var(--orange); background: var(--orange-50); color: var(--orange-600); }
.dropzone small { display: block; margin-top: 4px; font-size: 11px; }
.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.file-item { display: flex; align-items: center; gap: 10px; background: #fafafa; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; }
.file-item img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.file-item .fi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fi-x { color: var(--red); background: none; padding: 2px 6px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; align-items: flex-end; }
.toast {
  padding: 10px 15px;
  border-radius: 10px;
  background: #1f2329;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  animation: toastIn .18s ease;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: #d97706; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.kpi-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.kpi {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  min-width: 130px;
  flex: 1;
}
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .v.orange { color: var(--orange-600); }
.kpi .v.green { color: var(--green); }
.kpi .v.blue { color: var(--blue); }
.kpi .v.red { color: var(--red); }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.flx { display: flex; gap: 10px; align-items: center; }
.flx.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.check-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.check-list label { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: var(--text); padding: 4px; cursor: pointer; }
.check-list label:hover { background: #fafafa; border-radius: 6px; }
.check-list input { width: auto; }
