/* CS Agent surfaces use the existing YDS palette and spacing scale. */
.cs-widget-root, .cs-agent-page {
  --cs-ink: var(--text-primary);
  --cs-muted: var(--text-secondary);
  --cs-paper: var(--surface-paper);
  --cs-border: var(--border-default);
  color: var(--cs-ink);
}
.cs-widget-root { position: relative; z-index: 800; }
.cs-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 810;
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px;
  padding: 0 18px; border: 0; border-radius: 999px; color: var(--color-primary-contrast);
  background: var(--color-primary); box-shadow: var(--shadow-12);
  font: inherit; font-weight: 600; cursor: pointer; transition: transform .18s ease, opacity .18s ease;
}
.cs-fab:hover { transform: translateY(-2px); }
.cs-fab:focus-visible, .cs-modal button:focus-visible, .cs-modal a:focus-visible,
.cs-agent-page button:focus-visible, .cs-agent-page a:focus-visible,
.cs-agent-page input:focus-visible, .cs-agent-page select:focus-visible,
.cs-agent-page textarea:focus-visible { outline: 3px solid var(--color-primary-light); outline-offset: 2px; }
.cs-fab-mark { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid currentColor; border-radius: 50%; font-size: 15px; }
.cs-backdrop {
  position: fixed; inset: 0; z-index: 820; display: grid; place-items: center;
  padding: 20px; background: color-mix(in srgb, var(--neutral-90) 48%, transparent);
}
.cs-modal {
  width: min(560px, 100%); max-height: min(88dvh, 820px); overflow: auto;
  background: var(--cs-paper); border: 1px solid var(--cs-border); border-radius: var(--radius-container);
  box-shadow: var(--shadow-12); animation: cs-rise .2s ease both;
}
.cs-modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 18px; border-bottom: 1px solid var(--neutral-20); }
.cs-modal-head h2 { margin: 0; font-size: var(--text-h3-size); }
.cs-modal-kicker { display: block; margin-bottom: 5px; color: var(--color-primary); font-size: var(--text-caption1-size); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.cs-modal-body { padding: 22px 24px 24px; }
.cs-close {
  flex: 0 0 auto; display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--cs-border); border-radius: 50%; color: var(--cs-ink); background: transparent; cursor: pointer;
}
.cs-form { display: grid; gap: 17px; }
.cs-field { display: grid; gap: 7px; }
.cs-field label, .cs-field-label { font-size: var(--text-caption1-size); font-weight: 600; }
.cs-field select, .cs-field textarea, .cs-field input[type="file"], .cs-admin-select, .cs-reply textarea {
  box-sizing: border-box; width: 100%; border: 1px solid var(--neutral-30); border-radius: var(--radius-md);
  color: var(--text-primary); background: var(--surface-paper); font: inherit;
}
.cs-field select { min-height: 42px; padding: 8px 12px; }
.cs-field textarea { min-height: 132px; padding: 11px 12px; resize: vertical; }
.cs-field textarea:focus, .cs-field select:focus, .cs-admin-select:focus, .cs-reply textarea:focus { outline: 2px solid var(--color-primary-light); border-color: var(--color-primary); }
.cs-help { color: var(--cs-muted); font-size: var(--text-caption1-size); }
.cs-widget-config { margin: 0 0 12px; padding: 10px 12px; border-left: 3px solid var(--color-warning); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--color-warning-dark); background: var(--color-warning-lighter); font-size: var(--text-caption1-size); }
.cs-file-wrap { padding: 12px; border: 1px dashed var(--neutral-40); border-radius: var(--radius-md); background: var(--neutral-10); }
.cs-files { display: grid; gap: 7px; margin: 8px 0 0; padding: 0; list-style: none; }
.cs-file { display: flex; justify-content: space-between; align-items: center; gap: 8px; overflow-wrap: anywhere; font-size: var(--text-caption1-size); }
.cs-file button { flex: 0 0 auto; border: 0; color: var(--color-error-dark); background: transparent; cursor: pointer; font: inherit; text-decoration: underline; }
.cs-context { padding: 10px 12px; border-left: 3px solid var(--color-primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--neutral-10); color: var(--cs-muted); font-family: var(--font-mono); font-size: var(--text-caption1-size); overflow-wrap: anywhere; }
.cs-form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding-top: 3px; }
.cs-notice { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--color-error-light); border-radius: var(--radius-md); color: var(--color-error-dark); background: var(--color-error-lighter); }
.cs-receipt {
  display: grid; gap: 12px; padding: 16px; border: 1px solid var(--color-primary-light);
  border-radius: var(--radius-md); background: var(--color-primary-lighter);
}
.cs-receipt-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }
.cs-receipt-id { font-family: var(--font-mono); font-size: var(--text-caption1-size); overflow-wrap: anywhere; }
.cs-receipt-message { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.cs-receipt-result { padding-top: 10px; border-top: 1px solid var(--color-primary-light); white-space: pre-wrap; overflow-wrap: anywhere; }
.cs-status {
  display: inline-flex; align-items: center; min-height: 24px; padding: 2px 9px; border: 1px solid var(--neutral-30);
  border-radius: 99px; background: var(--neutral-10); color: var(--text-secondary);
  font-size: var(--text-caption1-size); font-weight: 600; text-transform: none;
}
.cs-status[data-status="answered"] { border-color: var(--color-success-light); background: var(--color-success-lighter); color: var(--color-success-dark); }
.cs-status[data-status="needs_review"] { border-color: var(--color-warning-light); background: var(--color-warning-lighter); color: var(--color-warning-dark); }
.cs-status[data-status="waiting_configuration"] { border-color: var(--color-info-light); background: var(--color-info-lighter); color: var(--color-info-dark); }
.cs-receipt-list { display: grid; gap: 8px; }
.cs-receipt-list button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--cs-border); border-radius: var(--radius-md); background: var(--surface-paper); text-align: left; cursor: pointer; }
.cs-receipt-list button:hover { background: var(--neutral-10); }
.cs-receipt-list button span:first-child { overflow-wrap: anywhere; }
.cs-empty { padding: 18px; color: var(--cs-muted); text-align: center; border: 1px dashed var(--neutral-30); border-radius: var(--radius-md); }

.cs-agent-page { min-height: 100dvh; padding: 28px clamp(16px, 4vw, 56px) 48px; background: var(--neutral-10); }
.cs-admin-shell { width: min(1320px, 100%); margin: 0 auto; }
.cs-admin-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.cs-admin-brand { display: flex; align-items: center; gap: 14px; }
.cs-admin-brand img { width: 30px; height: 30px; }
.cs-admin-brand h1 { margin: 0; }
.cs-admin-brand p { margin: 4px 0 0; color: var(--cs-muted); }
.cs-config-banner { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 22px; padding: 15px 18px; border: 1px solid var(--color-warning-light); border-radius: var(--radius-container); color: var(--color-warning-dark); background: var(--color-warning-lighter); }
.cs-config-banner strong { display: block; margin-bottom: 3px; }
.cs-config-banner > div { display: grid; gap: 7px; }
.cs-config-banner small { color: var(--cs-muted); }
.cs-config-facts { display: flex; flex-wrap: wrap; gap: 7px; }
.cs-config-facts span { padding: 3px 8px; border: 1px solid var(--color-warning-light); border-radius: 99px; background: var(--surface-paper); font-size: var(--text-caption1-size); }
.cs-admin-panel { display: grid; grid-template-columns: minmax(270px, .9fr) minmax(0, 1.6fr); min-height: 620px; overflow: hidden; border: 1px solid var(--cs-border); border-radius: var(--radius-container); background: var(--surface-paper); box-shadow: var(--shadow-8); }
.cs-inbox { min-width: 0; border-right: 1px solid var(--neutral-20); }
.cs-inbox-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 18px; border-bottom: 1px solid var(--neutral-20); }
.cs-inbox-head h2 { margin: 0; font-size: var(--text-h4-size); }
.cs-admin-select { width: auto; min-height: 36px; padding: 5px 30px 5px 10px; }
.cs-inbox-list { display: grid; max-height: 66dvh; overflow-y: auto; }
.cs-inbox-item { display: grid; gap: 8px; width: 100%; padding: 16px 18px; border: 0; border-bottom: 1px solid var(--neutral-20); background: transparent; text-align: left; cursor: pointer; }
.cs-inbox-item:hover, .cs-inbox-item[aria-current="true"] { background: var(--neutral-10); }
.cs-inbox-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cs-inbox-item p { margin: 0; color: var(--text-secondary); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-wrap; }
.cs-detail { min-width: 0; padding: clamp(18px, 3vw, 32px); }
.cs-detail-empty { min-height: 420px; display: grid; place-items: center; color: var(--cs-muted); text-align: center; }
.cs-detail h2 { margin: 0; overflow-wrap: anywhere; }
.cs-detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0 22px; color: var(--cs-muted); font-size: var(--text-caption1-size); }
.cs-delivery-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -10px 0 18px; color: var(--cs-muted); font-size: var(--text-caption1-size); }
.cs-detail-message { margin: 0 0 24px; padding: 18px; border-radius: var(--radius-md); background: var(--neutral-10); white-space: pre-wrap; overflow-wrap: anywhere; }
.cs-detail-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--neutral-20); }
.cs-detail-section h3 { margin: 0 0 12px; font-size: var(--text-h5-size); }
.cs-attachment-list, .cs-audit-list { display: grid; gap: 8px; padding: 0; list-style: none; }
.cs-attachment-list li, .cs-audit-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--neutral-20); border-radius: var(--radius-md); overflow-wrap: anywhere; }
.cs-attachment-list button { border: 0; color: var(--color-primary); background: transparent; cursor: pointer; font: inherit; text-decoration: underline; }
.cs-admin-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cs-admin-actions form { display: grid; align-content: start; gap: 9px; }
.cs-admin-actions label { font-weight: 600; }
.cs-admin-actions textarea, .cs-reply textarea { min-height: 92px; padding: 10px 12px; resize: vertical; }
.cs-admin-actions .yds-btn { justify-self: start; }
.cs-admin-error { margin: 0 0 14px; padding: 11px 14px; border-radius: var(--radius-md); color: var(--color-error-dark); background: var(--color-error-lighter); border: 1px solid var(--color-error-light); }
.cs-admin-paging { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; }
.cs-admin-paging span { color: var(--cs-muted); font-size: var(--text-caption1-size); }
.cs-auth-bar { display: flex; align-items: center; gap: 12px; }
.cs-auth-bar #logout { display: inline-flex; }
.cs-loading-lines { display: grid; gap: 12px; padding: 18px; }
.cs-skeleton { height: 52px; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--neutral-10), var(--neutral-20), var(--neutral-10)); background-size: 200% 100%; animation: cs-shimmer 1.5s ease-in-out infinite; }
.cs-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
body.app-signed-out .cs-agent-page, body.app-signed-out .cs-widget-root { display: none !important; }
body .cs-widget-root.cs-auth-locked { display: none !important; }
@keyframes cs-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cs-shimmer { to { background-position: -200% 0; } }
@media (max-width: 760px) {
  .cs-admin-header { align-items: flex-start; flex-direction: column; }
  .cs-admin-panel { grid-template-columns: 1fr; }
  .cs-inbox { border-right: 0; border-bottom: 1px solid var(--neutral-20); }
  .cs-inbox-list { max-height: 40dvh; }
  .cs-detail-empty { min-height: 220px; }
}
@media (max-width: 520px) {
  .cs-fab { right: 14px; bottom: 14px; }
  .cs-backdrop { padding: 0; align-items: end; }
  .cs-modal { max-height: 94dvh; border-radius: var(--radius-container) var(--radius-container) 0 0; }
  .cs-modal-head { padding: 19px 18px 14px; }
  .cs-modal-body { padding: 17px 18px 22px; }
  .cs-admin-actions { grid-template-columns: 1fr; }
  .cs-auth-bar { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .cs-modal, .cs-skeleton { animation: none; }
  .cs-fab { transition: none; }
}