/* 九歌门户内嵌工单页：复用门户的变量与表单控件。 */
.tk-app {
  container: ticket-panel / inline-size;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.tk-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.tk-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.1;
}

.tk-head p {
  margin: 6px 0 0;
  color: var(--fg3);
  font-size: 12px;
  font-style: italic;
}

.tk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tk-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tk-count {
  color: var(--fg3);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tk-select {
  width: auto;
  min-width: 148px;
  max-width: 200px;
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: 12px;
}

.tk-card {
  min-width: 0;
  padding: 24px 26px;
  border: 1px solid var(--line);
  background: transparent;
}

.tk-card h3 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0;
}

.tk-card .sub {
  margin: 0 0 14px;
  color: var(--fg3);
  font-size: 11px;
  font-style: italic;
}

.tk-id {
  color: var(--fg3);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.tk-subject {
  display: block;
  color: var(--fg);
  font-weight: 500;
  line-height: 1.5;
}

.tk-last {
  display: block;
  max-width: 460px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--fg3);
  font-size: 10.5px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tk-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  color: var(--fg3);
  font-size: 9.5px;
  letter-spacing: .06em;
  white-space: nowrap;
}

.tk-status::before {
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  background: currentColor;
  content: "";
}

.tk-status[data-status="ai_replied"],
.tk-status[data-status="resolved"] {
  border-color: var(--ok-stripe);
  color: var(--ok-stripe);
}

.tk-status[data-status="pending_admin"],
.tk-status[data-status="in_progress"] {
  border-color: var(--line-strong);
  color: var(--fg2);
}

.tk-status[data-status="rejected"],
.tk-status[data-status="closed"] {
  border-color: var(--bad-stripe);
  color: var(--bad-stripe);
}

.tk-status[data-status="submitted"],
.tk-status[data-status="triaging"] {
  border-style: dashed;
}

.tk-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 14px;
  color: var(--fg3);
  font-size: 10.5px;
}

.tk-pager-btns {
  display: flex;
  gap: 6px;
}

.tk-empty {
  padding: 54px 18px;
  text-align: center;
  color: var(--fg3);
}

.tk-empty h3 {
  margin: 0 0 4px;
  color: var(--fg2);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 400;
}

.tk-empty p {
  margin: 0;
  font-size: 11.5px;
}

.tk-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.tk-detail-title {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0;
}

.tk-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 7px;
  color: var(--fg3);
  font-size: 10.5px;
}

.tk-detail-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tk-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.tk-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.tk-progress {
  display: flex;
  gap: 0;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.tk-step {
  position: relative;
  flex: 1;
  padding-right: 10px;
  color: var(--fg3);
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tk-step .dot {
  display: block;
  width: 7px;
  height: 7px;
  margin-bottom: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
}

.tk-step:not(:last-child)::after {
  position: absolute;
  top: 3px;
  right: 0;
  left: 12px;
  height: 1px;
  background: var(--line);
  content: "";
}

.tk-step.done:not(:last-child)::after {
  background: var(--fg);
}

.tk-step.done .dot,
.tk-step.active .dot {
  border-color: var(--fg);
  background: var(--fg);
}

.tk-step.active {
  color: var(--fg);
  font-weight: 500;
}

.tk-progress[data-terminal="bad"] .tk-step.active .dot {
  border-color: var(--bad-stripe);
  background: var(--bad-stripe);
}

.tk-resolution {
  padding: 13px 15px;
  border-left: 3px solid var(--fg);
  background: var(--surface-2);
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.tk-resolution .k {
  display: block;
  margin-bottom: 4px;
  color: var(--fg3);
  font-size: 8.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.tk-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tk-msg {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.tk-msg.admin {
  border-left: 2px solid var(--fg);
  background: transparent;
}

.tk-msg.ai {
  border-left: 2px solid var(--ok-stripe);
}

.tk-msg.system {
  border-left: 2px solid var(--line-strong);
}

.tk-msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tk-msg-author {
  color: var(--fg3);
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.tk-msg-time {
  color: var(--fg3);
  font-size: 9px;
}

.tk-msg-body {
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.tk-meta-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tk-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
}

.tk-meta-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.tk-meta-row .k {
  color: var(--fg3);
}

.tk-meta-row .v {
  text-align: right;
  word-break: break-word;
}

.tk-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tk-att {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.tk-att .tk-file-info {
  flex: 1 1 100px;
}

.tk-reply textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.7;
}

.tk-reply-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.tk-app .field {
  margin-bottom: 0;
}

.tk-app .field > span:first-child {
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: none;
}

.tk-app .field .hint {
  color: var(--fg2);
  font-size: 11.5px;
}

.tk-type-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.tk-type-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--fg2);
  font-size: 12.5px;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.tk-type-option:hover {
  border-color: var(--fg);
  color: var(--fg);
}

.tk-type-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.tk-type-option:has(input:checked) {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.tk-type-option:has(input:focus-visible) {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.tk-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, .7fr);
  gap: 26px;
}

.tk-form-main,
.tk-form-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.tk-textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.7;
}

.tk-form-note {
  margin: 0;
  padding: 8px 12px;
  border-left: 2px solid var(--line-strong);
  color: var(--fg2);
  font-size: 12px;
  line-height: 1.6;
}

.tk-file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tk-form-error {
  min-height: 17px;
  color: var(--bad-stripe);
  font-size: 11px;
}

.tk-form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tk-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  z-index: 60;
  max-width: min(440px, calc(100vw - 24px));
  padding: 9px 14px;
  background: var(--fg);
  color: var(--bg);
  font-size: 11.5px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .16s ease, transform .16s ease;
}

.tk-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tk-toast.err {
  background: var(--bad-stripe);
  color: var(--bg);
}

.tk-list-results {
  min-width: 0;
}

.tk-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg3);
  font-size: 11px;
}

.tk-ticket-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.tk-ticket-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px 14px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.tk-ticket-main,
.tk-file-info {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.tk-ticket-link {
  width: fit-content;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.tk-app [hidden] {
  display: none;
}

.tk-empty .tk-actions {
  justify-content: center;
  margin-top: 14px;
}

.tk-detail-heading {
  min-width: 0;
}

.tk-detail-title {
  overflow-wrap: anywhere;
}

.tk-detail-number {
  margin-top: 12px;
}

.tk-app .btn:focus-visible,
.tk-app .input:focus-visible,
.tk-ticket-link:focus-visible,
.tk-att button:focus-visible,
.tk-file-item button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.tk-ticket-meta,
.tk-ticket-date,
.tk-file-info > span,
.tk-file-status {
  color: var(--fg3);
  font-size: 10.5px;
}

.tk-ticket-meta {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.tk-ticket-date {
  min-width: 126px;
  text-align: right;
  white-space: nowrap;
}

.tk-file-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.tk-file-item[data-invalid] {
  border-color: var(--bad-stripe);
}

.tk-file-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  font-weight: 500;
}

.tk-file-info > .tk-file-issue,
.tk-form-error {
  color: var(--bad-stripe);
}

.tk-file-status {
  min-height: 17px;
  margin: 5px 0 0;
}

#tkAttachmentPreview {
  max-width: 100%;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

#tkAttachmentPreview img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 480px;
  object-fit: contain;
}

.tk-att {
  align-items: center;
}

.tk-att .tk-actions {
  flex: 0 0 auto;
}

@container ticket-panel (max-width: 640px) {
  .tk-ticket-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 10px;
  }

  .tk-ticket-status {
    grid-column: 2;
    grid-row: 1;
  }

  .tk-ticket-meta {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .tk-ticket-date {
    grid-column: 1 / -1;
    grid-row: 3;
    min-width: 0;
    text-align: left;
  }

  .tk-filter {
    width: 100%;
    justify-content: space-between;
  }

  .tk-filter .tk-select {
    width: 0;
    min-width: 0;
    flex: 1;
    max-width: none;
  }

  .tk-att {
    align-items: flex-start;
  }

  .tk-att .tk-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

@container ticket-panel (max-width: 840px) {
  .tk-detail-grid {
    grid-template-columns: 1fr;
  }
}

@container ticket-panel (max-width: 640px) {
  .tk-head h2 {
    font-size: 26px;
  }

  .tk-card {
    padding: 20px 16px;
  }

  .tk-form-grid {
    grid-template-columns: 1fr;
  }

  .tk-detail-title {
    font-size: 25px;
  }

  .tk-progress {
    flex-wrap: wrap;
    gap: 12px 0;
  }

  .tk-step {
    flex: 0 0 50%;
  }

  .tk-step:nth-child(2n)::after {
    display: none;
  }

  .tk-step .dot {
    margin-bottom: 6px;
  }
}
