:root {
  --app-bg: #f5f7fb;
  --app-primary: #2457a6;
  --app-line: #d8dee8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--app-bg);
  color: #20242c;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

textarea.form-control {
  min-height: 150px;
  resize: vertical;
  line-height: 1.5;
}

#finalReply {
  overflow-y: hidden;
  min-height: 150px;
  max-height: 720px;
}

textarea.template-editor {
  min-height: 220px;
}

textarea.template-notes {
  min-height: 96px;
}

.translation-source-panel {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.translation-source-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  list-style-position: inside;
}

.translation-source-textarea {
  min-height: 120px;
  background: #fff;
}

.analysis-translation {
  white-space: pre-wrap;
  margin-top: 4px;
}

.compact-form-card .form-label {
  margin-bottom: 4px;
}

.app-shell {
  min-height: 100vh;
}

.navbar-brand {
  letter-spacing: 0;
}

.app-navbar {
  display: flex;
  align-items: center;
  gap: 18px;
}

.app-feature-tabs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.app-feature-tabs::-webkit-scrollbar {
  display: none;
}

.app-feature-tabs .nav-item {
  flex: 0 0 auto;
}

.app-feature-tabs .nav-link {
  white-space: nowrap;
}

.nav-label-short {
  display: none;
}

.navbar .dropdown > .btn,
.navbar-toggler {
  min-height: 0;
}

.avatar {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--app-primary);
  color: #fff;
  font-weight: 700;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(36, 87, 166, 0.12), rgba(22, 130, 93, 0.08)),
    var(--app-bg);
}

.login-card {
  width: min(430px, 100%);
  border-radius: 10px;
}

.card,
.rounded-3 {
  border-radius: 8px !important;
}

.btn-icon {
  width: 42px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.btn-svg {
  width: 1em;
  height: 1em;
  margin-right: 0.35rem;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-icon .btn-svg {
  margin-right: 0;
}

.btn:disabled,
.btn.disabled,
fieldset:disabled .btn {
  color: #6b7280 !important;
  background-color: #eef1f5 !important;
  border-color: #aeb7c4 !important;
  border-style: dashed;
  opacity: 1;
  cursor: not-allowed;
  box-shadow: inset 0 0 0 1px rgba(107, 114, 128, 0.14);
}

.btn:disabled:hover,
.btn.disabled:hover,
fieldset:disabled .btn:hover {
  color: #6b7280 !important;
  background-color: #eef1f5 !important;
  border-color: #aeb7c4 !important;
  transform: none;
}

.btn:disabled .btn-svg,
.btn.disabled .btn-svg,
fieldset:disabled .btn .btn-svg {
  color: #7b8491;
  stroke: currentColor;
}

.btn[class*="btn-outline-"]:disabled,
.btn[class*="btn-outline-"].disabled,
fieldset:disabled .btn[class*="btn-outline-"] {
  color: #6b7280 !important;
  background-color: #f1f3f6 !important;
  border-color: #aeb7c4 !important;
}

.recommendation {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.recommendation-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.recommendation-tab {
  min-height: 38px;
}

.recommendation-list {
  display: grid;
  gap: 12px;
}

.recommendation-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 12px;
}

.btn-outline-primary .recommendation-tab-count {
  background: rgba(36, 87, 166, 0.1);
}

.recommendation.selected {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 3px rgba(36, 87, 166, 0.12);
}

.recommendation-feedback-status {
  min-height: 18px;
}

.recommendation-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 150px;
  max-width: 190px;
  color: #475569;
  font-size: 12px;
  line-height: 1.35;
}

.recommendation-stats span {
  white-space: nowrap;
}

.template-preview {
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 12px;
  min-height: 180px;
  max-height: 260px;
  overflow: auto;
}

.recommend-template-search {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 88px;
  gap: 8px;
  align-items: end;
}

.recommend-keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.recommend-keyword-item {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  border: 1px solid var(--app-line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.recommend-keyword-btn,
.recommend-keyword-remove {
  border: 0;
  background: transparent;
  color: #2457a6;
  font-size: 13px;
  line-height: 1.4;
}

.recommend-keyword-btn {
  max-width: 220px;
  padding: 4px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recommend-keyword-remove {
  padding: 4px 8px;
  border-left: 1px solid var(--app-line);
  color: #64748b;
}

.recommend-keyword-btn:hover,
.recommend-keyword-remove:hover {
  background: #f8fafc;
}

.recommend-search-results {
  display: grid;
  gap: 10px;
}

.recommend-search-item {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.recommend-search-preview {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 8;
  -webkit-box-orient: vertical;
  margin-top: 6px;
  color: #475569;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.template-table th,
.template-table td {
  padding: 6px 8px;
  font-size: 13px;
}

.template-table {
  table-layout: fixed;
  min-width: 0;
  width: 100%;
}

.template-table .product-column {
  width: 86px;
}

.template-table .category-column {
  width: 120px;
}

.template-table .scenario-column {
  width: 150px;
}

.template-table .status-column {
  width: 72px;
}

.template-table .placeholder-column {
  width: 150px;
}

.template-table .stats-column,
.template-table .recommendation-stats-cell {
  width: 138px;
}

.template-table .actions-column {
  width: 120px;
}

.template-table .preview-column {
  width: auto;
}

.id-column {
  display: none;
}

.template-table .badge {
  font-size: 11px;
  font-weight: 500;
}

.template-cell {
  min-width: 360px;
  max-width: none;
}

.template-preview-link {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  color: #2457a6;
  text-decoration: none;
  max-width: 100%;
  line-height: 1.35;
  word-break: break-word;
}

.template-preview-link:hover {
  text-decoration: underline;
}

.placeholder-cell {
  max-width: 150px;
  white-space: normal;
}

.template-table .recommendation-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 8px;
  min-width: 0;
  max-width: none;
}

.template-table .recommendation-stats span {
  min-width: 0;
  white-space: normal;
  word-break: keep-all;
}

.placeholder-cell .badge {
  display: block;
  width: fit-content;
  margin-bottom: 3px;
}

.compact-text-cell {
  max-width: 150px;
}

.template-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
}

.template-action-btn {
  display: inline-flex;
  width: 30px;
  height: 30px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #475569;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.template-action-btn .btn-svg {
  width: 15px;
  height: 15px;
  margin-right: 0;
  vertical-align: 0;
}

.template-action-btn:hover,
.template-action-btn:focus-visible {
  border-color: #94a3b8;
  background: #f8fafc;
  color: #1e293b;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
  outline: 0;
}

.template-action-btn-disable {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.template-action-btn-disable:hover,
.template-action-btn-disable:focus-visible {
  border-color: #fdba74;
  background: #ffedd5;
  color: #9a3412;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.14);
}

.template-action-btn-enable {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.template-action-btn-enable:hover,
.template-action-btn-enable:focus-visible {
  border-color: #86efac;
  background: #dcfce7;
  color: #166534;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.template-full-preview {
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 14px;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

.template-attachment-section {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.template-attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.template-attachment-card {
  min-width: 0;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.template-attachment-thumb {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid #e5e9f0;
  border-radius: 6px;
  background: #f1f5f9;
}

.template-attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.template-attachment-info {
  min-width: 0;
  margin-top: 6px;
}

.template-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: #334155;
}

.template-attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.template-attachment-actions .btn {
  font-size: 12px;
}

.table th {
  white-space: nowrap;
}

pre.alert {
  white-space: pre-wrap;
}

.reply-preview {
  white-space: pre-wrap;
  background: #f8fafc;
  padding: 14px 16px;
  max-height: 340px;
  overflow: auto;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

.ai-tools-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 16px;
  align-items: start;
}

.ai-tool-textarea,
.ai-tool-output {
  min-height: 300px;
}

.ai-tool-context {
  min-height: 96px;
}

.placeholder-field-list {
  display: grid;
  gap: 10px;
}

.placeholder-field-row {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.placeholder-field-label {
  min-height: 31px;
  display: flex;
  align-items: center;
  color: #334155;
  word-break: break-word;
}

.placeholder-field-control {
  min-width: 0;
}

.template-filterbar {
  display: grid;
  grid-template-columns: 180px 128px minmax(220px, 1fr) 88px;
  gap: 8px;
  align-items: end;
  width: 100%;
  min-width: 0;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.product-tile {
  min-width: 0;
}

.min-w-0 {
  min-width: 0;
}

.template-filterbar .form-label {
  margin-bottom: 4px;
}

.template-filterbar > div,
.template-filterbar .form-control,
.template-filterbar .form-select {
  min-width: 0;
}

@media (max-width: 991.98px) {
  .ai-tools-grid {
    grid-template-columns: 1fr;
  }

  .navbar .container-fluid {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .app-navbar {
    flex-wrap: nowrap;
    gap: 10px;
  }

  .navbar-brand {
    font-size: 16px;
    flex: 0 0 auto;
  }

  .app-feature-tabs {
    gap: 4px;
  }

  .app-feature-tabs .nav-link {
    padding: 9px 6px;
    font-size: 14px;
  }

  .navbar .dropdown {
    flex: 0 0 auto;
  }

  .navbar .dropdown > .btn {
    width: 34px;
    height: 32px;
    padding: 0;
    gap: 6px !important;
    font-size: 13px;
    justify-content: center;
  }

  .avatar {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
}

@media (max-width: 575.98px) {
  .app-navbar {
    gap: 8px;
  }

  .navbar-brand {
    font-size: 15px;
  }

  .nav-label-full {
    display: none;
  }

  .nav-label-short {
    display: inline;
  }

  .app-feature-tabs .nav-link {
    padding-left: 4px;
    padding-right: 4px;
    font-size: 13px;
  }

  main.container-fluid {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .nav-pills {
    width: 100%;
  }

  .nav-pills .nav-item {
    flex: 1 1 auto;
  }

  .nav-pills .nav-link {
    text-align: center;
  }

  .template-filterbar {
    grid-template-columns: 1fr;
  }

  .recommend-template-search {
    grid-template-columns: 1fr;
  }

  .placeholder-field-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .placeholder-field-label {
    min-height: auto;
  }

  .template-table {
    min-width: 1080px;
  }
}

@media (min-width: 576px) and (max-width: 991.98px) {
  .template-filterbar {
    grid-template-columns: 1fr 1fr;
  }

  .template-filterbar .filter-search,
  .template-filterbar .filter-action {
    grid-column: span 2;
  }

  .template-table {
    min-width: 980px;
  }
}

@media (min-width: 1400px) {
  .template-cell {
    min-width: 420px;
    max-width: 680px;
  }
}
