:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f9fafb;
  --blue: #1677ff;
  --blue-dark: #0958d9;
  --green: #52c41a;
  --red: #ff4d4f;
  --amber: #faad14;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 12px rgba(15, 23, 42, 0.06);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(22, 119, 255, 0.12), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(82, 196, 26, 0.08), transparent 35%),
    linear-gradient(180deg, #eef4ff 0%, var(--bg) 100%);
}

.login-card {
  width: min(420px, 100%);
  padding: 32px 28px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo,
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--blue), #69b1ff);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(22, 119, 255, 0.28);
}

.login-brand h1 {
  margin-top: 14px;
  font-size: 22px;
}

.login-brand p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-form input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.login-form input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.login-btn {
  height: 42px;
  margin-top: 4px;
  border-radius: 8px;
  font-size: 15px;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 0 0 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -16px 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 18px;
}

.topbar-brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.topbar-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
}

.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

.pill {
  padding: 7px 13px;
  border-radius: 999px;
  color: #fff;
  background: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.pill.on {
  background: var(--green);
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(520px, 1fr);
  gap: 14px;
  align-items: stretch;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(680px, 1.35fr) minmax(420px, 0.65fr);
  gap: 14px;
  align-items: start;
}

.hidden {
  display: none !important;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.detail-header h2 {
  margin-right: auto;
}

.back-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.detail-badges {
  display: flex;
  gap: 8px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.status-form {
  display: grid;
  gap: 14px;
}

.status-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.status-form select,
.status-form textarea,
.status-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.status-form input[readonly] {
  background: var(--soft);
}

.modal-panel-wide {
  width: min(1100px, 100%);
  max-height: min(88vh, 900px);
}

.record-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.record-summary div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.record-summary label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.record-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.record-filters label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.record-filters input,
.record-filters select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.record-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.record-table-wrap {
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.record-table th,
.record-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.record-table th {
  position: sticky;
  top: 0;
  background: var(--soft);
  z-index: 1;
}

.phone-search label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.phone-search input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.phone-result {
  display: grid;
  gap: 12px;
}

.phone-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.phone-info-grid label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.phone-info-main {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fafcff 0%, #fff 100%);
}

.phone-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}

.phone-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 14px;
}

.level-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.level-tag-0 {
  background: #fef2f2;
  color: #dc2626;
}

.level-tag-1 {
  background: #fef9c3;
  color: #a16207;
}

.level-tag-2 {
  background: #eff6ff;
  color: #1d4ed8;
}

.level-tag-3 {
  background: #f0fdf4;
  color: #15803d;
}

.level-tag-4,
.level-tag-5 {
  background: #f5f3ff;
  color: #7c3aed;
}

.phone-status {
  display: inline-flex;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.phone-status-offline {
  background: #fef2f2;
  color: #dc2626;
}

.phone-status-online {
  background: #f0fdf4;
  color: #16a34a;
}

.modal-error {
  min-height: 18px;
  color: #b45309;
  font-size: 13px;
  line-height: 1.5;
}

.modal-error.error,
.modal-error:not(:empty) {
  color: var(--danger, #dc2626);
}

.status-current {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
}

.detail-section {
  margin-bottom: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.detail-section-title {
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 800;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 10px 16px;
}

.info-item label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.info-item div {
  color: var(--ink);
  line-height: 1.5;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.tool-card {
  display: grid;
  gap: 4px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  color: var(--ink);
  text-align: left;
}

.tool-card strong {
  font-size: 15px;
}

.tool-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.tool-hold { border-color: #fdba74; background: #fff7ed; }
.tool-supplement { border-color: #93c5fd; background: #eff6ff; }
.tool-record { border-color: #86efac; background: #f0fdf4; }
.tool-status { border-color: #c4b5fd; background: #f5f3ff; }

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: min(86vh, 860px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  flex-wrap: wrap;
  background: #fafafa;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  overflow: auto;
}

.hold-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.hold-summary div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.hold-summary label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.hold-summary strong {
  font-size: 18px;
}

.hold-list {
  display: grid;
  gap: 8px;
}

.hold-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.hold-toolbar .primary {
  margin-left: auto;
}

.hold-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.hold-row-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff7ed;
  color: #c2410c;
  font-size: 12px;
}

.tool-placeholder {
  color: var(--muted);
  line-height: 1.7;
}

.tool-placeholder-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.detail-content {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.6;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  max-height: 320px;
  overflow: auto;
}

.history-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.history-head span {
  color: var(--muted);
  font-size: 12px;
}

.history-action {
  font-weight: 700;
}

.history-comment {
  margin-top: 6px;
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
}

.reply-box {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.mini-btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

.panel {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stats div {
  min-height: 74px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.stats span {
  display: block;
  font-size: 26px;
  font-weight: 800;
}

.stats label,
label {
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

button,
input {
  height: 36px;
  border-radius: 7px;
  font: inherit;
}

button {
  border: 0;
  color: #fff;
  background: #64748b;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  filter: brightness(1.03);
}

button.primary {
  background: var(--blue);
}

button.primary:hover {
  background: var(--blue-dark);
}

button.danger {
  background: var(--red);
}

button.secondary,
button.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover,
button.ghost:hover {
  border-color: #cbd5e1;
  background: var(--soft);
  filter: none;
}

label {
  display: grid;
  gap: 5px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.config-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.7fr;
  gap: 10px;
  align-items: end;
}

.token-field,
.comment-field,
.keywords-field {
  grid-column: span 1;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
}

.check input {
  width: 18px;
  height: 18px;
}

.save-btn {
  width: 100%;
}

.error {
  min-height: 18px;
  margin-top: 8px;
  color: var(--red);
}

.tickets {
  display: grid;
}

.ticket-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.ticket-tabs .tab {
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
}

.ticket-tabs .tab.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.ticket-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ticket-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ticket-table th,
.ticket-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.ticket-table th {
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.ticket-table tbody tr:hover,
.ticket-table tbody tr.selected {
  background: #f8fbff;
}

.ticket-table tbody tr.selected {
  box-shadow: inset 3px 0 0 var(--blue);
}

.ticket-table .title-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--blue);
  font-weight: 600;
}

.ticket-table .empty-row {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

.action-cell {
  display: flex;
  gap: 8px;
}

.link-btn {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
}

.link-btn.reply-btn {
  color: var(--green);
}

.ticket-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.ticket-pagination button {
  height: 32px;
  padding: 0 14px;
}

.ticket-pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.priority-high,
.priority-urgent {
  color: #b45309;
  font-weight: 700;
}

.priority-medium {
  color: #2563eb;
  font-weight: 700;
}

.priority-low {
  color: var(--muted);
}

.ticket {
  display: grid;
  grid-template-columns: 72px minmax(220px, 1fr) 94px 154px;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.ticket:hover,
.ticket.selected {
  background: #f8fbff;
}

.ticket.selected {
  box-shadow: inset 3px 0 0 var(--blue);
}

.reply-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.reply-meta {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  line-height: 1.5;
}

.reply-meta-line,
.reply-meta-desc {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.reply-meta-desc {
  color: var(--ink);
}

.reply-field {
  margin-bottom: 10px;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  resize: vertical;
  min-height: 96px;
}

.reply-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.reply-status {
  min-height: 18px;
  margin-top: 8px;
  color: var(--green);
  font-weight: 700;
}

.reply-status.error {
  color: var(--red);
}

.reply-status:empty {
  display: none;
}

.ticket-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket small {
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  justify-content: center;
  min-width: 72px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.status-pending,
.claimable {
  background: #fef3c7;
  color: #92400e;
}

.status-processing {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-resolved {
  background: #dcfce7;
  color: #166534;
}

.logs {
  height: 620px;
  overflow: auto;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
}

.log {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.log time {
  color: var(--muted);
  white-space: nowrap;
}

.panel-title span.token-expired {
  color: var(--red);
  font-weight: 700;
}

.token-alert-body {
  display: grid;
  gap: 10px;
  line-height: 1.7;
}

.token-alert-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.transfer-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 1100px) {
  .dashboard,
  .content-grid,
  .config-grid,
  .detail-info-grid,
  .tool-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .stats,
  .actions,
  .ticket,
  .log {
    grid-template-columns: 1fr 1fr;
  }

  .ticket-title {
    grid-column: span 2;
  }

  .ticket small {
    text-align: left;
  }
}
