/* ============================================================
   Xiehe Nexus — component library
   Every interactive target is >= 44px tall on touch.
   ============================================================ */

/* ---------- buttons --------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 42px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-sm);
  font-size: var(--fs-small);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform 60ms var(--ease);
  text-decoration: none;
}
.btn:active:not([disabled]) {
  transform: translateY(1px);
}
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn .icon {
  flex: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--on-accent);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}
.btn-ghost:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(0.94);
}

.btn-quiet-danger {
  background: transparent;
  border-color: var(--line);
  color: var(--danger);
}
.btn-quiet-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-sm {
  min-height: 34px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-meta);
  border-radius: var(--r-xs);
}
.btn-lg {
  min-height: 50px;
  padding: 0 var(--sp-6);
  font-size: var(--fs-body);
  border-radius: var(--r-md);
}
.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--ink);
}
.icon-btn[aria-expanded="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.icon-btn .indicator {
  position: absolute;
  top: 7px;
  right: 7px;
  min-width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- chips, tags, badges --------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: var(--fs-meta);
  font-weight: 500;
  transition: all var(--dur-fast) var(--ease);
}
button.chip:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}
.chip.is-on {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--r-xs);
  background: var(--surface-muted);
  border: 1px solid var(--line-soft);
  color: var(--ink-2);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.01em;
}
a.tag:hover,
button.tag:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px 8px;
  border-radius: var(--r-xs);
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-brand   { background: var(--accent-soft);  color: var(--accent); }
.badge-gold   { background: var(--warning-soft); color: var(--warning); }
.badge-crimson{ background: var(--danger-soft);  color: var(--danger); }
.badge-azure  { background: var(--info-soft);    color: var(--info); }
.badge-neutral{ background: var(--surface-muted);color: var(--ink-3); border: 1px solid var(--line-soft); }

.eyebrow {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.eyebrow .en {
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow .zh {
  font-size: var(--fs-meta);
  color: var(--ink-3);
}
.eyebrow::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- avatars --------------------------------------- */
/* `[style]` raises specificity so a descendant text rule in a view cannot
   repaint the initials — every avatar carries an inline background colour. */
.avatar,
.avatar[style] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: var(--r-pill);
  color: #fff;
  font-size: var(--fs-meta);
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}
.avatar-photo { object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-micro); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-lead); }
.avatar-xl { width: 76px; height: 76px; font-size: var(--fs-h2); }

.avatar-stack {
  display: inline-flex;
}
.avatar-stack .avatar {
  margin-left: -8px;
  box-shadow: 0 0 0 2px var(--surface);
}
.avatar-stack .avatar:first-child {
  margin-left: 0;
}

/* ---------- cards ----------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}
.card-pad {
  padding: var(--sp-5) var(--sp-6);
}
.card-hover {
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
  transform: translateY(-2px);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2,
.card-head h3 {
  font-size: var(--fs-card);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
}
.card-sub {
  color: var(--ink-3);
  font-size: var(--fs-meta);
  margin-top: 2px;
}

.section-title {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  font-weight: 600;
  line-height: var(--lh-tight);
}

.meta {
  color: var(--ink-3);
  font-size: var(--fs-meta);
}
.meta-dot::before {
  content: "·";
  margin: 0 var(--sp-2);
  color: var(--line-strong);
}

/* ---------- forms ----------------------------------------- */
.field {
  display: block;
  margin-bottom: var(--sp-4);
}
.field > .label {
  display: block;
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: var(--sp-2);
}
.field > .hint {
  display: block;
  font-size: var(--fs-meta);
  color: var(--ink-3);
  margin-top: var(--sp-2);
}
.field > .error {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-size: var(--fs-meta);
  color: var(--danger);
  margin-top: var(--sp-2);
  font-weight: 500;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: var(--fs-body);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--ink-3);
}
.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--line-strong);
}
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}
.textarea {
  min-height: 132px;
  resize: vertical;
  line-height: var(--lh-body);
}
.select {
  appearance: none;
  padding-right: var(--sp-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--ink);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  min-height: 44px;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .track {
  width: 44px;
  height: 26px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  position: relative;
  transition: background var(--dur) var(--ease);
  flex: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: var(--r-pill);
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track {
  background: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(18px);
}
.switch input:focus-visible + .track {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.searchbox {
  position: relative;
  flex: 1;
  min-width: 0;
}
.searchbox > .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.searchbox .input {
  min-height: 40px;
  padding-left: 38px;
  background: var(--bg-sunken);
  border-color: transparent;
}
.searchbox .input:focus {
  background: var(--surface);
  border-color: var(--accent);
}

/* ---------- segmented control / tabs ---------------------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
}
.segmented button {
  min-height: 34px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-xs);
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--ink-3);
  transition: all var(--dur-fast) var(--ease);
}
.segmented button:hover {
  color: var(--ink);
}
.segmented button.is-on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tabs button:hover {
  color: var(--ink);
}
.tabs button[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- table ----------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  font-size: var(--fs-small);
  min-width: 620px;
}
.table th {
  text-align: left;
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr:hover {
  background: var(--surface-muted);
}

/* ---------- status dot ------------------------------------ */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-meta);
  font-weight: 600;
}
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: currentColor;
  flex: none;
}
.status-ok { color: var(--success); }
.status-warn { color: var(--warning); }
.status-bad { color: var(--danger); }
.status-idle { color: var(--ink-3); }

/* ---------- progress / meter ------------------------------ */
.meter {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width var(--dur-slow) var(--ease);
}
.meter.is-warn > span { background: var(--warning); }
.meter.is-bad > span { background: var(--danger); }

.spinner {
  width: 16px;
  height: 16px;
  border-radius: var(--r-pill);
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: xn-spin 700ms linear infinite;
  flex: none;
}
.spinner-lg { width: 26px; height: 26px; border-width: 2.5px; }

/* ---------- skeleton -------------------------------------- */
.skeleton {
  border-radius: var(--r-xs);
  background: linear-gradient(
    90deg,
    var(--bg-sunken) 25%,
    var(--surface-muted) 37%,
    var(--bg-sunken) 63%
  );
  background-size: 420px 100%;
  animation: xn-shimmer 1.3s linear infinite;
}
.skeleton-line { height: 12px; margin-bottom: var(--sp-3); }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-title { height: 20px; width: 70%; margin-bottom: var(--sp-4); }
.skeleton-avatar { width: 38px; height: 38px; border-radius: var(--r-pill); }

/* ---------- empty / error state --------------------------- */
.state {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  max-width: 46ch;
  margin: 0 auto;
}
.state .state-mark {
  width: 46px;
  height: 46px;
  margin: 0 auto var(--sp-4);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.state.is-error .state-mark {
  background: var(--danger-soft);
  color: var(--danger);
}
.state h3 {
  font-size: var(--fs-h3);
  font-weight: 650;
  margin-bottom: var(--sp-2);
}
.state p {
  color: var(--ink-2);
  margin-bottom: var(--sp-5);
}

/* ---------- callout --------------------------------------- */
.callout {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  font-size: var(--fs-small);
  line-height: var(--lh-snug);
}
.callout .icon { flex: none; margin-top: 1px; }
.callout strong { display: block; margin-bottom: 2px; }
.callout-info    { background: var(--info-soft);    border-color: transparent; color: var(--info); }
.callout-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.callout-warn    { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.callout-danger  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.callout-info p, .callout-success p, .callout-warn p, .callout-danger p { color: inherit; opacity: 0.92; }

/* ---------- dropdown -------------------------------------- */
.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  z-index: var(--z-drop);
  overflow: hidden;
  animation: xn-rise var(--dur) var(--ease);
}
.dropdown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--fs-meta);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-3);
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--fs-small);
  color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease);
}
.dropdown-item:hover {
  background: var(--surface-muted);
  color: var(--ink);
}
.dropdown-sep {
  height: 1px;
  background: var(--line-soft);
}

/* ---------- modal ----------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--sp-8) var(--sp-4);
  overflow-y: auto;
  animation: xn-fade-in var(--dur) var(--ease);
  backdrop-filter: blur(2px);
}
.modal {
  width: min(660px, 100%);
  background: var(--surface-raised);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: xn-rise var(--dur-slow) var(--ease);
  margin: auto 0;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: 600;
}
.modal-body {
  padding: var(--sp-6);
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--line-soft);
  background: var(--surface-muted);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  flex-wrap: wrap;
}
.modal-foot .spacer { flex: 1; }

/* ---------- toasts ---------------------------------------- */
.toast-region {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
  width: min(520px, calc(100% - 32px));
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-small);
  box-shadow: var(--shadow-lg);
  animation: xn-rise var(--dur) var(--ease);
}
.toast .icon { flex: none; }
.toast span { flex: 1; }
.toast button {
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.toast-danger { background: var(--danger); color: #fff; }
.toast-danger button { color: #fff; text-decoration: underline; }

/* ---------- connection banner ----------------------------- */
.conn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--fs-meta);
  font-weight: 600;
  text-align: center;
}
.conn-banner.is-offline {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- file rows ------------------------------------- */
.file-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-muted);
}
.file-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: var(--r-xs);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
}
.file-chip .file-name {
  display: block;
  font-weight: 600;
  font-size: var(--fs-small);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- dropzone -------------------------------------- */
.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-muted);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  cursor: pointer;
}
.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-softer);
}
.dropzone .dz-mark {
  width: 42px;
  height: 42px;
  margin: 0 auto var(--sp-3);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.dropzone h4 {
  font-size: var(--fs-body);
  font-weight: 650;
  margin-bottom: var(--sp-1);
}
.dropzone p {
  color: var(--ink-3);
  font-size: var(--fs-meta);
}

.upload-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin-top: var(--sp-3);
  background: var(--surface);
}
.upload-row .grow { flex: 1; min-width: 0; }
.upload-row .name {
  font-size: var(--fs-small);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-row .meter { margin-top: 6px; }
.upload-row.is-error { border-color: var(--danger); background: var(--danger-soft); }
.upload-row.is-done { border-color: var(--accent-border); }
