/* Communications Center & Contacts Directory Styles */

.communications-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.communications-tabs-group {
  display: inline-flex;
  background: #e5ecef;
  border-radius: 6px;
  padding: 3px;
  gap: 2px;
}

.communications-tabs-group .tab-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.communications-tabs-group .tab-button:hover {
  color: var(--ink);
}

.communications-tabs-group .tab-button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.communications-tabs-group .tab-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.08);
  color: inherit;
}

.communications-tabs-group .tab-button.active .tab-badge {
  background: #2563eb;
  color: #fff;
}

.comm-subpane[hidden] {
  display: none !important;
}

/* Contacts Controls */
.contacts-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.contacts-toolbar .search-input {
  min-width: 260px;
}

/* Contacts Metrics Grid */
#contacts-metrics {
  margin-bottom: 20px;
}

/* Contacts Table Wrapper */
.contacts-list-panel {
  margin-bottom: 24px;
}

.contacts-table-wrapper {
  overflow-x: auto;
  border-radius: 6px;
}

.contacts-table {
  width: 100%;
  min-width: 1040px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

.contacts-table th,
.contacts-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-light, #edf2f7);
  vertical-align: middle;
}

.contacts-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-alt, #f8fafc);
  white-space: nowrap;
}

.contacts-table tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.contacts-table tbody tr:hover {
  background: #f1f8f7;
}

/* Contact rows stay 64px tall; longer values remain available in titles and the editor. */
.contacts-table .contact-row {
  height: 64px;
}

.contact-cell-content {
  display: flex;
  align-items: center;
  height: 40px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.contact-cell-content > * {
  min-width: 0;
  max-width: 100%;
}

.contacts-table .contact-name-button,
.contacts-table .contact-affiliation-subline,
.contacts-table .contact-direction-text {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.contacts-table .contact-name-button {
  line-height: 20px;
}

.contacts-table .copyable-field {
  min-width: 0;
  max-width: 100%;
  margin: 0;
}

.contacts-table .copyable-field > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contacts-table .copy-icon {
  flex-shrink: 0;
}

.contact-standing-cell {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  max-height: 40px;
  overflow: hidden;
  white-space: normal;
  line-height: 20px;
}

.contact-standing-cell .standing-badge,
.contact-standing-cell .contact-label-tag {
  white-space: nowrap;
  line-height: 16px;
}

.contact-name-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  text-align: left;
  display: inline-block;
  transition: color 0.15s ease, text-decoration 0.15s ease;
}

.contact-name-button.contact-nickname {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.contact-name-button.contact-char-name {
  font-size: 13px;
  color: var(--ink);
}

.contacts-table tr:hover .contact-name-button,
.contact-name-button:hover,
.contact-name-button:focus-visible {
  color: #2563eb;
  text-decoration: underline;
  outline: none;
}

/* Type / Source Badges */
.contact-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.contact-type-badge.badge-fused {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.contact-type-badge.badge-external {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.contact-type-badge.badge-corp {
  background: #f5f3ff;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}

.contact-character-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.contact-affiliation-subline {
  display: block;
  font-size: 11px;
  color: #64748b;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.contact-corp-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #475569;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid #e2e8f0;
}

.contact-alliance-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #1e3a8a;
  background: #eff6ff;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid #bfdbfe;
}

.contact-affiliations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

/* Nickname */
.contact-nickname {
  font-weight: 600;
  color: var(--ink);
  font-size: 13.5px;
}

/* Copyable values */
.copyable-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: background 0.15s ease;
}

.copyable-field:hover {
  background: rgba(0, 0, 0, 0.05);
}

.copyable-field .copy-icon {
  opacity: 0.4;
  width: 12px;
  height: 12px;
  transition: opacity 0.15s ease;
}

.copyable-field:hover .copy-icon {
  opacity: 0.9;
}

/* Direction Tags & Category Badges */
.contact-direction-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.direction-category-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.direction-category-badge.cat-industry {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.direction-category-badge.cat-diplomacy {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.direction-category-badge.cat-combat {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}

.direction-category-badge.cat-production {
  background: #f0f9ff;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.direction-category-badge.cat-other {
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #e2e8f0;
}

.contact-direction-text {
  font-size: 13px;
  color: var(--ink, #1e293b);
  display: inline-block;
  line-height: 1.4;
  white-space: nowrap;
}

.direction-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.direction-tag[data-dir="订购"] {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

.direction-tag[data-dir="运输"] {
  background: #f0f9ff;
  color: #0369a1;
  border-color: #bae6fd;
}

.direction-tag[data-dir="联盟管理"] {
  background: #faf5ff;
  color: #7e22ce;
  border-color: #e9d5ff;
}

.direction-tag[data-dir="外交联络"],
.direction-tag[data-dir="联盟外交"],
.direction-tag[data-dir="军团联络"],
.direction-tag[data-dir="蓝加外交"],
.direction-tag[data-dir="驻军协议"],
.direction-tag[data-dir="商贸外交"] {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.direction-tag[data-dir="军火装备"],
.direction-tag[data-dir="会战主力"],
.direction-tag[data-dir="快速反应"],
.direction-tag[data-dir="特勤截击"],
.direction-tag[data-dir="侦察隐秘"],
.direction-tag[data-dir="战术指挥"] {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

.direction-tag[data-dir="工业蓝图"],
.direction-tag[data-dir="旗舰制造"],
.direction-tag[data-dir="装备制造"],
.direction-tag[data-dir="T2制造"],
.direction-tag[data-dir="常规制造"] {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

.direction-tag[data-dir="矿产收购"],
.direction-tag[data-dir="刷怪"],
.direction-tag[data-dir="挖矿"],
.direction-tag[data-dir="挖坟"],
.direction-tag[data-dir="远征"] {
  background: #f0f9ff;
  color: #0369a1;
  border-color: #bae6fd;
}

/* Standing Badges */
.standing-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.standing-badge.standing-pos {
  background: #dcfce7;
  color: #15803d;
}

.standing-badge.standing-neutral {
  background: #f1f5f9;
  color: #475569;
}

.standing-badge.standing-neg {
  background: #fee2e2;
  color: #b91c1c;
}

.contact-label-tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--muted);
  margin-left: 4px;
}

/* Notes Text */
.contact-notes-cell {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  max-height: 36px;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Action Buttons */
.contacts-table .table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.table-btn {
  border: 1px solid var(--border-light, #d1d5db);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.table-btn:hover {
  background: var(--bg-alt, #f8fafc);
  border-color: var(--border-dark, #9ca3af);
}

.table-btn.table-btn-primary {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #fff;
}

.table-btn.table-btn-primary:hover {
  background: #1d4ed8;
}

.table-btn.table-btn-danger {
  color: #dc2626;
  border-color: #fca5a5;
}

.table-btn.table-btn-danger:hover {
  background: #fee2e2;
  border-color: #ef4444;
}

/* External Contact Modal */
dialog.external-contact-dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel, #fff);
  color: var(--ink);
  max-width: 520px;
  width: min(520px, calc(100% - 32px));
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  max-height: calc(100vh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
}

dialog.external-contact-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.external-contact-dialog .modal-form {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.external-contact-dialog .modal-title {
  margin-bottom: 2px;
}

/* Two-column field row */
.external-contact-dialog .field-row {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 14px !important;
  margin: 0 !important;
}

/* Single field group: label on top, input/select on bottom, aligned */
.external-contact-dialog .form-group {
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
  min-width: 0 !important;
  margin: 0 !important;
}

.external-contact-dialog .form-group label:not(.checkbox-label) {
  display: flex !important;
  align-items: center;
  gap: 4px;
  font-size: 12px !important;
  font-weight: 600 !important;
  color: #45535d !important;
  margin: 0 !important;
  line-height: 1.4;
}

.external-contact-dialog .form-group input:not([type="checkbox"]),
.external-contact-dialog .form-group select,
.external-contact-dialog .form-group textarea {
  width: 100% !important;
  box-sizing: border-box !important;
  font-family: inherit;
  font-size: 13px !important;
  padding: 8px 11px !important;
  height: 38px;
  border: 1px solid #cfd9dc !important;
  border-radius: 4px !important;
  background: #fff !important;
  color: var(--ink, #1e293b) !important;
  margin: 0 !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.external-contact-dialog .form-group textarea {
  height: auto !important;
  min-height: 64px !important;
  resize: vertical;
  line-height: 1.5;
}

.external-contact-dialog .form-group input:not([type="checkbox"]):focus,
.external-contact-dialog .form-group select:focus,
.external-contact-dialog .form-group textarea:focus {
  outline: none;
  border-color: #2563eb !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12) !important;
}

.external-contact-dialog .input-with-action {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.external-contact-dialog .input-with-action input {
  flex: 1;
}

.external-contact-dialog .input-with-action button {
  white-space: nowrap;
  height: 38px;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  flex-shrink: 0;
  margin: 0;
}

.ext-contact-affiliation-preview {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #334155;
  transition: all 0.2s ease;
}

.ext-contact-affiliation-preview[hidden] {
  display: none !important;
}

.ext-contact-affiliation-preview.preview-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.affiliation-detail-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.affiliation-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.aff-detail-label {
  font-size: 10.5px;
  color: #15803d;
  font-weight: 600;
  text-transform: uppercase;
}

.aff-detail-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #14532d;
  word-break: break-word;
}

.ext-contact-affiliation-preview.preview-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.ext-contact-affiliation-preview.preview-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.ext-contact-affiliation-preview .preview-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: ext-spin 0.6s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

.ext-contact-affiliation-preview .preview-spinner[hidden] {
  display: none !important;
}

@keyframes ext-spin {
  to { transform: rotate(360deg); }
}

.external-contact-dialog .modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
}
}
