:root {
  color-scheme: light;
  --bg: #f2f5f5;
  --card: #ffffff;
  --text: #142326;
  --muted: #68777a;
  --border: #dce4e5;
  --primary: #123f46;
  --primary-dark: #0d3035;
  --primary-soft: #e8f1f1;
  --success: #1e6a45;
  --success-soft: #edf8f2;
  --warning: #8a5a00;
  --warning-soft: #fff7e4;
  --danger: #9c2e2e;
  --danger-soft: #fff0f0;
  --shadow: 0 18px 55px rgba(21, 43, 47, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(18, 63, 70, .09), transparent 34rem),
    var(--bg);
}

button, input, select, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  font-weight: 760;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}

button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .52; cursor: not-allowed; }

button.secondary {
  background: #edf1f2;
  color: var(--text);
}

button.secondary:hover { background: #e1e7e8; }
button.compact { padding: 8px 11px; font-size: .86rem; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(18, 63, 70, .1);
}

label {
  font-size: .85rem;
  font-weight: 780;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 7px;
  font-size: clamp(2rem, 4vw, 3.1rem);
  letter-spacing: -.045em;
  line-height: 1.04;
}
h2 { margin-bottom: 6px; font-size: 1.22rem; }
h3 { margin-bottom: 6px; }

.page-shell {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0 52px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--primary);
  font-size: .71rem;
  font-weight: 850;
  letter-spacing: .15em;
}

.subtitle, .muted, .section-heading p, .connect-card p, .settings-card > p {
  color: var(--muted);
}

.subtitle { margin-bottom: 0; }

.status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--success-soft);
  color: var(--success);
  font-size: .77rem;
  font-weight: 800;
}

.badge.neutral { background: #ebeff0; color: #516063; }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.card {
  border: 1px solid rgba(216, 225, 226, .9);
  border-radius: 19px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(520px, 100%);
  margin: 70px auto 0;
  padding: 27px;
}

.stack { display: grid; gap: 10px; }

.tabs {
  display: flex;
  gap: 7px;
  margin-bottom: 18px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255,255,255,.8);
  width: fit-content;
}

.tab {
  background: transparent;
  color: var(--muted);
  padding: 9px 13px;
}

.tab:hover { background: #edf1f2; color: var(--text); }
.tab.active { background: var(--primary); color: white; }
.lock-tab { margin-left: 8px; }

.connect-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 25px;
  padding: 28px;
}

.connect-card p { margin-bottom: 0; max-width: 700px; }

.support-grid {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(430px, 1fr) minmax(330px, 420px);
  gap: 16px;
  align-items: start;
}

.inbox-column, .conversation-column, .order-panel, .draft-panel,
.order-search-card, .order-results-card, .settings-card {
  padding: 20px;
}

.inbox-column, .conversation-column {
  height: calc(100vh - 185px);
  min-height: 650px;
}

.inbox-column {
  position: sticky;
  top: 15px;
  overflow: hidden;
}

.conversation-column {
  overflow-y: auto;
}

.right-column {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 15px;
  max-height: calc(100vh - 185px);
  overflow-y: auto;
  padding-bottom: 3px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.section-heading p { margin-bottom: 0; font-size: .88rem; }

.email-list {
  display: grid;
  gap: 7px;
  max-height: calc(100% - 70px);
  overflow-y: auto;
  padding-right: 3px;
}

.email-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 13px;
  background: #f7f9f9;
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.email-item:hover { background: #edf2f2; }
.email-item.active { border-color: var(--primary); background: var(--primary-soft); }
.email-item.unread .email-sender,
.email-item.unread .email-subject { font-weight: 850; }

.email-topline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.email-sender, .email-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-sender { font-weight: 700; font-size: .9rem; }
.email-date { flex: 0 0 auto; color: var(--muted); font-size: .73rem; }
.email-subject { margin-bottom: 4px; font-size: .87rem; font-weight: 700; }
.email-summary {
  color: var(--muted);
  font-size: .79rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.conversation-heading {
  padding-bottom: 17px;
  border-bottom: 1px solid var(--border);
}

.customer-name {
  margin-bottom: 4px;
  color: var(--primary);
  font-weight: 800;
}

.thread-list {
  display: grid;
  gap: 13px;
  padding: 18px 0;
}

.thread-message {
  max-width: 90%;
  border-radius: 15px;
  padding: 15px;
  background: #f6f8f8;
  border: 1px solid var(--border);
}

.thread-message.outbound {
  justify-self: end;
  background: var(--primary-soft);
}

.thread-message-header {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 10px;
  font-size: .8rem;
}

.thread-message-header p { margin-bottom: 2px; }
.thread-message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  font-size: .93rem;
}

.history-panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.history-panel summary {
  cursor: pointer;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.history-item {
  padding: 12px;
  border-radius: 12px;
  background: #f7f9f9;
}

.history-item p { margin-bottom: 4px; }
.history-subject { font-weight: 780; }
.history-summary { color: var(--muted); font-size: .86rem; }

.draft-panel label {
  display: block;
  margin: 12px 0 7px;
}

.button-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.button-row button { flex: 1; }

.notice {
  margin: 13px 0 0;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: .87rem;
  line-height: 1.4;
}

.notice.success { background: var(--success-soft); color: var(--success); }
.notice.warning { background: var(--warning-soft); color: var(--warning); }
.notice.error { background: var(--danger-soft); color: var(--danger); }

.empty {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
}

.large-empty { min-height: 390px; }
.small-empty { min-height: 170px; }
.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 13px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.65rem;
}

.orders-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 17px;
  align-items: start;
}

.order-search-card {
  position: sticky;
  top: 15px;
}

.order-list { display: grid; gap: 13px; }

.order-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: white;
}

.order-header {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.order-header p { margin-bottom: 0; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.chip {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 8px;
  background: #edf1f2;
  color: #3e4d50;
  font-size: .72rem;
  font-weight: 800;
}

.chip.success { background: var(--success-soft); color: var(--success); }
.chip.warning { background: var(--warning-soft); color: var(--warning); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

.order-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.info-block {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.info-block:nth-child(odd) { border-right: 1px solid var(--border); }
.info-block.full { grid-column: 1 / -1; border-right: 0; }

.info-block h4 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: .7rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.info-block p, .info-block ul { margin-bottom: 0; }
.info-block ul { padding-left: 18px; }

.tracking-list { display: grid; gap: 8px; }

.tracking-item {
  padding: 10px;
  border-radius: 10px;
  background: #f7f9f9;
}

.tracking-item p { margin-bottom: 3px; }
.tracking-item a { color: var(--primary); font-weight: 750; }

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 17px;
}

.connection-list {
  display: grid;
  gap: 0;
  margin: 0;
}

.connection-list div {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.connection-list dt {
  margin-bottom: 4px;
  font-size: .78rem;
  font-weight: 800;
  color: var(--muted);
}

.connection-list dd { margin: 0; }

.privacy-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .support-grid {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  }

  .right-column {
    position: static;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 800px) {
  .page-shell { width: min(100% - 18px, 1500px); padding-top: 18px; }
  .topbar, .connect-card, .order-header { align-items: flex-start; flex-direction: column; }
  .status-row, .chip-row { justify-content: flex-start; }
  .tabs { width: 100%; overflow-x: auto; }
  .support-grid, .orders-grid, .settings-grid, .right-column { grid-template-columns: 1fr; }
  .inbox-column, .conversation-column { position: static; height: auto; min-height: 480px; }
  .right-column { grid-column: auto; }
  .order-search-card { position: static; }
  .order-details { grid-template-columns: 1fr; }
  .info-block:nth-child(odd) { border-right: 0; }
}

/* ---------- Support workspace layout repair ---------- */

[hidden] {
  display: none !important;
}

#supportWorkspace.support-grid {
  display: grid;
  grid-template-columns:
    minmax(270px, 320px)
    minmax(500px, 1fr)
    minmax(340px, 390px);
  gap: 16px;
  align-items: stretch;
  height: calc(100dvh - 185px);
  min-height: 680px;
  overflow: hidden;
}

#supportWorkspace > *,
.right-column > * {
  min-width: 0;
}

.inbox-column,
.conversation-column,
.right-column {
  position: relative;
  top: auto;
  width: auto;
  height: 100%;
  min-height: 0;
  max-height: none;
}

.inbox-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inbox-column .section-heading {
  flex: 0 0 auto;
}

.email-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.email-item {
  min-width: 0;
  overflow: hidden;
}

.email-sender,
.email-subject,
.email-summary {
  max-width: 100%;
}

.conversation-column {
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.conversation-heading {
  position: sticky;
  top: -20px;
  z-index: 2;
  margin: -20px -20px 0;
  padding: 20px 20px 17px;
  background: rgba(255, 255, 255, 0.98);
}

.thread-message {
  width: fit-content;
  max-width: min(94%, 860px);
}

.thread-message-body {
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: normal;
}

.right-column {
  display: grid;
  grid-template-rows:
    minmax(250px, 0.9fr)
    minmax(410px, 1.1fr);
  gap: 16px;
  overflow: hidden;
  padding: 0;
}

.order-panel,
.draft-panel {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.draft-panel {
  display: flex;
  flex-direction: column;
}

.draft-panel #draftText {
  flex: 1 1 240px;
  min-height: 220px;
}

.draft-panel #saveZohoDraftButton {
  flex: 0 0 auto;
  margin-top: 10px;
}

#customerOrderResults.notice {
  display: block;
  min-height: auto;
}

@media (max-width: 1280px) {
  #supportWorkspace.support-grid {
    grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .inbox-column,
  .conversation-column {
    height: min(760px, calc(100dvh - 190px));
    min-height: 600px;
  }

  .right-column {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: none;
    height: auto;
    overflow: visible;
  }

  .order-panel,
  .draft-panel {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 820px) {
  #supportWorkspace.support-grid {
    grid-template-columns: 1fr;
  }

  .inbox-column,
  .conversation-column,
  .right-column {
    height: auto;
    min-height: 0;
  }

  .inbox-column {
    max-height: 520px;
  }

  .conversation-column {
    min-height: 520px;
  }

  .right-column {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .conversation-heading {
    position: static;
    margin: -20px -20px 0;
  }
}

/* =========================================================
   FINAL EMAIL WORKSPACE LAYOUT
   Stable desktop layout with safe wrapping in every column
   ========================================================= */

#supportWorkspace.support-grid {
  grid-template-columns: 290px minmax(0, 1fr) 370px;
  gap: 18px;
  height: calc(100dvh - 190px);
  min-height: 680px;
  overflow: hidden;
}

#supportWorkspace,
#supportWorkspace *,
.order-card,
.order-card *,
.thread-message,
.thread-message *,
.email-item,
.email-item * {
  min-width: 0;
}

.inbox-column,
.conversation-column,
.right-column {
  height: 100%;
  min-height: 0;
  max-height: none;
}

.inbox-column,
.conversation-column,
.order-panel,
.draft-panel {
  padding: 18px;
}

/* Inbox: readable rows rather than compressed strips */
.email-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 5px;
}

.email-item {
  display: block;
  flex: 0 0 auto;
  min-height: 76px;
  padding: 11px 12px;
  overflow: hidden;
}

.email-topline {
  align-items: baseline;
}

.email-sender,
.email-subject {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-summary {
  display: -webkit-box;
  min-width: 0;
  max-width: 100%;
  line-height: 1.35;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Conversation: full-width readable messages */
.conversation-column {
  overflow-y: auto;
  overflow-x: hidden;
}

.thread-list {
  width: 100%;
}

.thread-message {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.thread-message.outbound {
  width: min(92%, 850px);
  margin-left: auto;
}

.thread-message-header {
  align-items: flex-start;
}

.thread-message-header > * {
  min-width: 0;
}

.thread-message-header p,
.thread-message-body {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.thread-message-body {
  white-space: pre-wrap;
}

/* Right side: two independently scrollable cards */
.right-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(280px, 43%) minmax(390px, 57%);
  gap: 18px;
  overflow: hidden;
}

.order-panel,
.draft-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Shopify card must be one column inside the narrow sidebar */
.order-card {
  width: 100%;
}

.order-header {
  display: block;
}

.order-header .chip-row {
  justify-content: flex-start;
  margin-top: 10px;
}

.order-details {
  display: block;
}

.info-block,
.info-block:nth-child(odd),
.info-block.full {
  display: block;
  width: 100%;
  border-right: 0;
}

.info-block p,
.info-block li,
.tracking-item,
.tracking-item p,
.tracking-item a {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.info-block p + p {
  margin-top: 5px;
}

.info-block ul {
  margin-top: 0;
  padding-left: 18px;
}

/* Reply editor: no controls sitting on top of one another */
.draft-panel {
  display: flex;
  flex-direction: column;
}

.draft-panel label {
  flex: 0 0 auto;
}

#extraInstruction {
  flex: 0 0 auto;
  min-height: 92px;
}

.button-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  flex: 0 0 auto;
}

.button-row button {
  width: 100%;
  min-width: 0;
}

#draftText {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-height: 240px;
  max-height: none;
}

#saveZohoDraftButton,
#draftNotice {
  flex: 0 0 auto;
}

/* Prevent headings and values from overflowing their cards */
.section-heading,
.conversation-heading,
.customer-name,
#conversationSubject,
#conversationMeta,
#customerLookupLabel,
#shopName {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Medium screens: inbox above, conversation and tools below */
@media (max-width: 1250px) {
  #supportWorkspace.support-grid {
    grid-template-columns: 280px minmax(0, 1fr);
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .inbox-column,
  .conversation-column {
    height: 720px;
  }

  .right-column {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: none;
    height: auto;
    overflow: visible;
  }

  .order-panel,
  .draft-panel {
    height: auto;
    min-height: 520px;
    overflow: visible;
  }
}

/* Narrow screens: simple vertical stack */
@media (max-width: 820px) {
  #supportWorkspace.support-grid {
    display: block;
  }

  .inbox-column,
  .conversation-column,
  .right-column,
  .order-panel,
  .draft-panel {
    width: 100%;
    height: auto;
    min-height: 0;
    margin-bottom: 16px;
  }

  .inbox-column {
    max-height: 520px;
  }

  .conversation-column {
    min-height: 500px;
  }

  .right-column {
    display: block;
  }

  .order-panel,
  .draft-panel {
    min-height: 0;
  }
}


/* Support Brain */
.support-brain-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr);
  align-items: start;
}

.support-brain-card {
  min-width: 0;
}

.settings-section {
  padding: 20px 0;
  border-top: 1px solid var(--line, #e5e7eb);
}

.settings-section:first-of-type {
  border-top: 0;
}

.settings-section textarea,
.settings-section input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

.field-help {
  margin: 5px 0 10px;
  color: var(--muted, #667085);
  font-size: 13px;
  line-height: 1.45;
}

.compact-heading {
  align-items: flex-start;
}

.product-knowledge-list {
  display: grid;
  gap: 14px;
}

.product-knowledge-card {
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  padding: 16px;
  background: #fafbfc;
}

.product-knowledge-card label {
  display: block;
  margin-top: 12px;
}

.product-knowledge-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.danger-link {
  border: 0;
  background: transparent;
  color: #b42318;
  padding: 4px;
  box-shadow: none;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.toggle-row span {
  display: grid;
  gap: 4px;
}

.toggle-row small {
  color: var(--muted, #667085);
}

.email-template-preview {
  background: #f5f7f9;
  border-radius: 14px;
  padding: 22px;
}

.email-template-preview > div {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 22px;
  font-size: 14px;
  line-height: 1.6;
}

.email-template-preview img {
  display: block;
  width: 150px;
  max-width: 60%;
  height: auto;
  margin: 0 auto 18px;
}

.settings-subheading {
  margin-top: 28px;
}

.draft-review-meta {
  display: grid;
  gap: 5px;
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #f6f8fa;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.warning-text {
  color: #9a6700;
}

@media (max-width: 1050px) {
  .support-brain-grid {
    grid-template-columns: 1fr;
  }
}


/* Learning Review */
.learning-review {
  margin-top: 24px;
}

.learning-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
}

.learning-controls select {
  width: auto;
  min-width: 90px;
}

.learning-suggestion-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.learning-suggestion-card {
  padding: 17px;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  background: #fff;
}

.learning-suggestion-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.learning-suggestion-head h3 {
  margin: 8px 0 0;
  font-size: 17px;
}

.confidence-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-size: 12px;
}

.learning-suggestion-card textarea {
  width: 100%;
  box-sizing: border-box;
  margin: 7px 0 10px;
}

.learning-suggestion-card details {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #f8fafc;
}

.learning-suggestion-card summary {
  cursor: pointer;
  font-weight: 700;
}

.learning-examples blockquote {
  margin: 9px 0 0;
  padding: 8px 10px;
  border-left: 3px solid #d0d5dd;
  color: #475467;
  font-size: 13px;
}

.learning-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 650px) {
  .learning-suggestion-head,
  .learning-controls,
  .learning-actions {
    align-items: stretch;
    flex-direction: column;
  }
}


/* Learning scan control alignment */
.learning-review > .section-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
}

#scanSentEmailsButton {
  display: inline-flex;
  width: auto;
  min-width: 150px;
  max-width: 190px;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  align-self: start;
}

.learning-controls {
  justify-content: flex-start;
}

@media (max-width: 700px) {
  .learning-review > .section-heading {
    grid-template-columns: 1fr;
  }

  #scanSentEmailsButton {
    width: 100%;
    max-width: none;
  }
}


.learning-progress {
  margin: 14px 0 18px;
  padding: 13px;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 10px;
  background: #f8fafc;
}

.learning-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e7ec;
}

#learningProgressBar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: #344054;
  transition: width .25s ease;
}

#learningProgressBar.indeterminate {
  animation: learning-progress-pulse 1.4s ease-in-out infinite alternate;
}

#learningProgressText {
  margin: 8px 0 0;
  color: #475467;
  font-size: 13px;
}

@keyframes learning-progress-pulse {
  from { width: 15%; transform: translateX(0); }
  to { width: 45%; transform: translateX(120%); }
}


/* Organised Support Brain v4 */
.brain-heading { align-items: flex-start; }
.brain-tabs {
  display: flex;
  gap: 6px;
  margin: 18px 0 0;
  padding: 5px;
  overflow-x: auto;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  background: #f8fafc;
}
.brain-tab {
  width: auto;
  flex: 0 0 auto;
  padding: 9px 13px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #475467;
  box-shadow: none;
  white-space: nowrap;
}
.brain-tab.active { background: #fff; color: #101828; box-shadow: 0 1px 3px rgba(16,24,40,.12); }
.brain-panel { min-width: 0; }
.first-section { border-top: 0 !important; padding-top: 18px; }
.settings-section h3 { margin: 0; }
.settings-section code { padding: 2px 5px; border-radius: 5px; background: #f2f4f7; }
.variable-list, .knowledge-editor-list { display: grid; gap: 12px; }
.variable-row {
  padding: 14px;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 11px;
  background: #fafbfc;
}
.variable-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(170px, .7fr); gap: 12px; }
.variable-row label, .knowledge-card-body label { display: grid; gap: 6px; }
.knowledge-editor-card {
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.knowledge-editor-card > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  background: #fafbfc;
}
.knowledge-editor-card > summary::-webkit-details-marker { display: none; }
.knowledge-editor-card > summary::after { content: "+"; flex: 0 0 auto; font-size: 20px; color: #667085; }
.knowledge-editor-card[open] > summary::after { content: "−"; }
.knowledge-card-summary-title { font-weight: 750; color: #101828; overflow-wrap: anywhere; }
.knowledge-card-summary-meta { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; background: #eef2f6; color: #475467; font-size: 12px; }
.knowledge-card-body { display: grid; gap: 14px; padding: 16px; border-top: 1px solid var(--line, #e5e7eb); }
.knowledge-card-grid { display: grid; gap: 12px; align-items: end; }
.knowledge-card-grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.knowledge-card-grid.three { grid-template-columns: minmax(0, 1.35fr) minmax(180px, .8fr) auto; }
.toggle-inline { display: flex !important; align-items: center; gap: 8px !important; padding-bottom: 11px; }
.toggle-inline input { width: 18px; height: 18px; }
.knowledge-card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flow-intro { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.route-tester { display: grid; gap: 12px; margin-top: 18px; padding: 16px !important; border: 1px solid var(--line, #e5e7eb) !important; border-radius: 12px; background: #f8fafc; }
.compact-toggle { margin: 0; }
.route-test-result { display: grid; gap: 5px; padding: 12px; border-radius: 9px; background: #fff; border: 1px solid #d0d5dd; font-size: 13px; }
.product-picker { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(220px, 1fr) auto auto; gap: 10px; align-items: center; }
.product-picker button { width: auto; white-space: nowrap; }
.product-knowledge-list > .empty { margin-top: 12px; }
.brain-save-bar {
  position: sticky;
  bottom: 10px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-top: 20px;
  padding: 14px;
  border: 1px solid #d0d5dd;
  border-radius: 12px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 8px 24px rgba(16,24,40,.12);
  backdrop-filter: blur(8px);
}
.brain-save-bar > button { width: auto; flex: 0 0 auto; }
.brain-health { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.brain-health.healthy { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.brain-health.warning { background: #fffaeb; color: #93370d; border: 1px solid #fedf89; }
.brain-health.unhealthy { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }
.brain-health ul { margin: 8px 0 0; padding-left: 18px; }
.brain-sidebar { position: sticky; top: 18px; }
.safety-list p { margin: 0 0 10px; }
.safety-list p:last-child { margin-bottom: 0; }
@media (max-width: 1150px) {
  .product-picker { grid-template-columns: 1fr 1fr; }
  .brain-sidebar { position: static; }
}
@media (max-width: 760px) {
  .variable-main, .knowledge-card-grid.two, .knowledge-card-grid.three, .product-picker { grid-template-columns: 1fr; }
  .flow-intro, .brain-save-bar { align-items: stretch; flex-direction: column; }
  .brain-save-bar > button { width: 100%; }
  .toggle-inline { padding-bottom: 0; }
}

/* =========================================================
   MOBILE TOUCH + SCROLL REPAIR
   One continuous page scroll; no nested scroll traps.
   ========================================================= */
@media (max-width: 900px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
    overscroll-behavior-y: auto;
  }

  body {
    min-height: 100dvh;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  .page-shell {
    width: min(100% - 16px, 1500px);
    overflow: visible;
  }

  #appView,
  main,
  .tab-panel,
  #supportWorkspace,
  #ordersTab,
  #settingsTab,
  .support-grid,
  .orders-grid,
  .settings-grid,
  .right-column {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #supportWorkspace.support-grid,
  .support-grid,
  .orders-grid,
  .settings-grid,
  .right-column {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  .inbox-column,
  .conversation-column,
  .right-column,
  .order-panel,
  .draft-panel,
  .order-search-card,
  .brain-sidebar {
    position: static !important;
    top: auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior: auto !important;
    scrollbar-gutter: auto !important;
  }

  .email-list {
    display: flex;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior: auto !important;
    scrollbar-gutter: auto !important;
    padding-right: 0;
  }

  .conversation-heading {
    position: static !important;
    top: auto !important;
  }

  .brain-save-bar {
    position: static !important;
    bottom: auto !important;
    z-index: auto;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .tabs,
  .brain-tabs {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    overscroll-behavior-block: auto;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar,
  .brain-tabs::-webkit-scrollbar {
    display: none;
  }

  textarea,
  #draftText,
  #extraInstruction,
  #routeTestText,
  .settings-card textarea,
  .knowledge-editor-card textarea,
  .learning-suggestion-card textarea {
    height: auto;
    max-height: none !important;
    overflow-y: hidden !important;
    resize: none;
    touch-action: pan-y;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  button,
  input,
  select,
  summary,
  label {
    touch-action: manipulation;
  }

  .topbar,
  .connect-card,
  .order-header,
  .flow-intro,
  .brain-save-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row,
  .knowledge-card-grid.two,
  .knowledge-card-grid.three,
  .variable-main,
  .product-picker {
    grid-template-columns: 1fr !important;
  }
}


/* =========================================================
   EXPANDED ORDER + REPLY WORKSPACES
   ========================================================= */

.workspace-card-heading {
  align-items: flex-start;
  gap: 12px;
}

.expand-button {
  flex: 0 0 auto;
  width: auto;
  min-width: 78px;
}

.compact-order-list {
  gap: 10px;
}

.compact-order-card .order-header {
  padding: 13px;
}

.compact-order-card .order-header h3 {
  font-size: 1rem;
}

.compact-order-card .chip-row {
  margin-top: 8px;
}

.compact-order-body {
  display: grid;
  gap: 12px;
  padding: 13px;
}

.compact-order-facts {
  display: grid;
  gap: 7px;
}

.compact-order-facts p {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  font-size: .84rem;
}

.compact-order-facts span {
  color: var(--muted);
}

.compact-order-facts strong {
  text-align: right;
  overflow-wrap: anywhere;
}

.compact-product-list h4 {
  margin-bottom: 5px;
}

.compact-product-list ul {
  margin: 0;
  padding-left: 18px;
  font-size: .83rem;
}

.full-width {
  width: 100%;
}

.prompt-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.prompt-shortcut {
  width: auto;
  padding: 7px 10px;
  font-size: .76rem;
}

body.dialog-open {
  overflow: hidden;
}

.workspace-dialog {
  width: min(1180px, calc(100vw - 28px));
  max-width: none;
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: transparent;
  box-shadow: 0 28px 90px rgba(21, 34, 36, .28);
}

.workspace-dialog::backdrop {
  background: rgba(20, 29, 31, .58);
  backdrop-filter: blur(4px);
}

.dialog-shell {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 28px);
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 20px;
  overflow: hidden;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.dialog-header h2 {
  margin: 2px 0 0;
}

.dialog-close {
  width: auto;
  min-width: 76px;
}

.dialog-content {
  min-height: 0;
  padding: 20px;
  overflow: auto;
  overscroll-behavior: contain;
}

.expanded-order-card {
  max-width: 100%;
}

.expanded-order-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.expanded-order-grid .info-block.full {
  grid-column: 1 / -1;
}

.tracking-item-detailed {
  padding: 15px;
  border: 1px solid var(--border);
}

.tracking-item-head,
.track17-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.tracking-number {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.tracking-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.shopify-event-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.shopify-event-section h5 {
  margin: 0 0 10px;
}

.tracking-timeline {
  display: grid;
  gap: 0;
}

.tracking-event {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  padding: 0 0 15px;
}

.tracking-event::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 12px;
  bottom: -2px;
  width: 2px;
  background: var(--border);
}

.tracking-event:last-child::before {
  display: none;
}

.tracking-event p {
  margin: 0 0 3px;
}

.tracking-dot {
  position: relative;
  z-index: 1;
  width: 13px;
  height: 13px;
  margin-top: 3px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.track17-result {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #cfdadb;
  border-radius: 12px;
  background: #f5fafa;
}

.latest-tracking-event {
  margin: 10px 0;
  padding: 10px;
  border-radius: 9px;
  background: white;
}

.track17-events {
  margin-top: 12px;
}

.track17-events summary {
  cursor: pointer;
  font-weight: 800;
}

.expanded-draft-grid {
  display: grid;
  grid-template-columns: minmax(290px, .75fr) minmax(0, 1.65fr);
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.expanded-prompt-column,
.expanded-editor-column {
  min-height: 0;
  padding: 20px;
  overflow: auto;
}

.expanded-prompt-column {
  border-right: 1px solid var(--border);
  background: #f8fafa;
}

.expanded-prompt-column label,
.expanded-editor-column label {
  display: block;
  margin: 0 0 7px;
}

.expanded-prompt-column select {
  margin-bottom: 6px;
}

#expandedExtraInstruction {
  min-height: 210px;
  resize: vertical;
}

.expanded-shortcuts {
  margin-bottom: 14px;
}

#expandedGenerateDraftButton {
  width: 100%;
}

.expanded-editor-column {
  display: flex;
  flex-direction: column;
}

#expandedDraftText {
  flex: 1 1 auto;
  width: 100%;
  min-height: 430px;
  resize: vertical;
  font-size: 1rem;
  line-height: 1.65;
}

.expanded-draft-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.expanded-draft-actions button:first-child {
  flex: 1;
}

@media (max-width: 800px) {
  .workspace-dialog {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }

  .dialog-shell {
    max-height: 100dvh;
    border-radius: 0;
  }

  .dialog-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 15px;
  }

  .dialog-content {
    padding: 12px;
  }

  .expanded-order-grid,
  .expanded-draft-grid {
    display: block;
  }

  .expanded-prompt-column,
  .expanded-editor-column {
    overflow: visible;
    padding: 15px;
  }

  .expanded-prompt-column {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  #expandedExtraInstruction {
    min-height: 150px;
  }

  #expandedDraftText {
    min-height: 58dvh;
  }

  .expanded-draft-actions {
    flex-direction: column;
  }
}


/* =========================================================
   PROMPT-FIRST SUPPORT + SIMPLE TICKET WORKFLOW
   ========================================================= */

.ticket-filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 10px 0 12px;
}

.ticket-filter {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 8px 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7f9f9;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 800;
}

.ticket-filter:hover {
  background: var(--primary-soft);
}

.ticket-filter.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.ticket-filter span {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.2);
  font-size: .69rem;
}

.email-item.complete {
  opacity: .68;
}

.email-state-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 18px;
  margin-top: 7px;
}

.email-state {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: .65rem;
  font-weight: 850;
}

.email-state.replied {
  background: #e9f2ff;
  color: #245b9e;
}

.email-state.complete {
  background: var(--success-soft);
  color: var(--success);
}

.conversation-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.conversation-status-row .customer-name {
  margin: 0;
}

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

.ticket-status {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 850;
}

.ticket-status.open {
  background: var(--warning-soft);
  color: var(--warning);
}

.ticket-status.complete {
  background: var(--success-soft);
  color: var(--success);
}

.prompt-first-help {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 10px;
  background: #f5f8f8;
}

.draft-panel input[type="text"],
.expanded-prompt-column input[type="text"] {
  width: 100%;
}

.new-email-card {
  grid-column: 1 / -1;
}

.new-email-fields {
  display: grid;
  grid-template-columns: minmax(140px, 190px) minmax(0, 1fr);
  gap: 10px 14px;
  align-items: start;
}

.new-email-fields > label {
  padding-top: 10px;
  font-weight: 800;
}

.new-email-fields > input,
.new-email-fields > textarea,
.new-email-fields > .prompt-shortcuts,
.new-email-fields > .button-row,
.new-email-fields > button,
.new-email-fields > .notice {
  grid-column: 2;
}

.new-email-fields #newEmailBody {
  min-height: 320px;
  line-height: 1.6;
}

.new-email-fields #newEmailTo[readonly] {
  background: #f5f7f7;
}

.new-email-fields .button-row {
  margin-top: 0;
}

@media (max-width: 800px) {
  .conversation-status-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .ticket-actions {
    width: 100%;
    justify-content: space-between;
  }

  .new-email-fields {
    grid-template-columns: 1fr;
  }

  .new-email-fields > label,
  .new-email-fields > input,
  .new-email-fields > textarea,
  .new-email-fields > .prompt-shortcuts,
  .new-email-fields > .button-row,
  .new-email-fields > button,
  .new-email-fields > .notice {
    grid-column: 1;
  }

  .new-email-fields > label {
    padding-top: 2px;
  }

  .new-email-fields #newEmailBody {
    min-height: 52dvh;
  }

  .ticket-filters {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 6px 0;
    background: var(--surface);
  }
}


/* =========================================================
   CONTROLLED LEARNING + DO NOT DO
   ========================================================= */

.learn-command-help {
  margin: 7px 0 10px;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.45;
}

.learn-command-help code,
.learning-command-guide code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef2f2;
  color: #27383a;
  font-size: .92em;
}

.learned-style-intro {
  padding-bottom: 14px;
}

.learned-style-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 0 18px 18px;
}

.learned-rule-section {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fafcfc;
}

.learned-rule-section.positive {
  border-top: 4px solid #5c8d83;
}

.learned-rule-section.negative {
  border-top: 4px solid #a14949;
  background: #fffafa;
}

.danger-eyebrow {
  color: #9d3939;
}

.learned-rule-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.learned-rule-card {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.learned-rule-card.avoid {
  border-color: #e5caca;
}

.learned-rule-card textarea {
  width: 100%;
  min-height: 76px;
  margin-top: 7px;
  resize: vertical;
}

.learned-rule-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.learning-command-guide {
  margin: 0 18px 18px;
  padding: 16px;
  border: 1px dashed #bdcaca;
  border-radius: 13px;
  background: #f8fbfb;
}

.learning-command-guide pre {
  margin: 12px 0;
  padding: 12px;
  overflow-x: auto;
  border-radius: 9px;
  background: #1f2c2e;
  color: #f3f7f7;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
  line-height: 1.55;
}

@media (max-width: 800px) {
  .learned-style-columns {
    grid-template-columns: 1fr;
    padding: 0 12px 12px;
  }

  .learning-command-guide {
    margin: 0 12px 12px;
  }

  .learned-rule-section {
    padding: 13px;
  }
}

/* =========================================================
   ZOHO DELIVERY ACTIONS
   ========================================================= */

.delivery-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.expanded-draft-actions.delivery-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.schedule-panel {
  margin-top: 12px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7f9f9;
}

.schedule-panel label {
  display: block;
  margin-bottom: 7px;
  font-weight: 800;
}

.schedule-panel input[type="datetime-local"] {
  width: 100%;
}

.schedule-panel .button-row {
  margin-top: 10px;
}

@media (max-width: 800px) {
  .delivery-actions,
  .expanded-draft-actions.delivery-actions {
    grid-template-columns: 1fr;
  }
}


.understanding-check {
  display: block;
  flex-basis: 100%;
  padding: 9px 11px;
  border: 1px solid #b9d9d1;
  border-radius: 9px;
  background: #f0faf7;
  color: #23473f;
  line-height: 1.45;
}


.operator-check {
  display: block;
  flex-basis: 100%;
  padding: 9px 11px;
  border: 1px solid #c7d2f0;
  border-radius: 9px;
  background: #f4f6fd;
  color: #293a68;
  line-height: 1.45;
}

/* =========================================================
   V11 — COMFI MAILBOX UI OVERHAUL
   ========================================================= */

:root {
  --ink: #0c1113;
  --ink-soft: #161d20;
  --blue: #1f6f7a;
  --blue-dark: #154f57;
  --blue-soft: #eaf6f7;
  --canvas: #f3f5f5;
  --surface: #ffffff;
  --line: #e3e7e8;
  --line-strong: #d2d9da;
  --copy: #172124;
  --copy-muted: #6b777a;
  --rail-width: 190px;
  --mail-list-width: 340px;
  --context-width: 330px;
  --radius: 14px;
  --shadow-soft: 0 12px 32px rgba(10, 20, 23, .07);
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  overflow: hidden;
  background: var(--canvas);
  color: var(--copy);
}
body.login-active { overflow: auto; }
button { border-radius: 9px; }
input, select, textarea { border-radius: 9px; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

/* Login */
.login-screen {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(360px, .95fr) minmax(460px, 1.05fr);
  background: #fff;
}
.login-brand-panel {
  position: relative;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(40px, 6vw, 84px);
  overflow: hidden;
  color: white;
  background:
    radial-gradient(circle at 75% 20%, rgba(44,142,155,.42), transparent 34%),
    linear-gradient(150deg, #050708 0%, #11191c 58%, #173a40 100%);
}
.login-brand-panel::after {
  content: "";
  position: absolute;
  right: -170px;
  bottom: -180px;
  width: 480px;
  height: 480px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 50%;
  box-shadow: 0 0 0 65px rgba(255,255,255,.025), 0 0 0 130px rgba(255,255,255,.018);
}
.login-logo { width: 150px; filter: brightness(0) invert(1); }
.login-brand-panel h1 {
  max-width: 620px;
  margin: 0 0 20px;
  font-size: clamp(3rem, 6vw, 5.6rem);
  line-height: .95;
  letter-spacing: -.065em;
}
.login-brand-panel p { max-width: 620px; color: rgba(255,255,255,.72); font-size: 1.08rem; }
.login-kicker { margin-bottom: 16px; font-size: .73rem !important; letter-spacing: .18em; font-weight: 850; color: #71c4cf !important; }
.login-feature-row { display: flex; gap: 9px; flex-wrap: wrap; position: relative; z-index: 1; }
.login-feature-row span { padding: 8px 11px; border: 1px solid rgba(255,255,255,.12); border-radius: 999px; color: rgba(255,255,255,.72); font-size: .76rem; font-weight: 760; }
.login-form-panel { display: grid; place-items: center; padding: 36px; background: #f7f8f8; }
.login-card {
  width: min(440px, 100%);
  margin: 0;
  padding: 38px;
  border: 1px solid #e2e6e7;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 26px 80px rgba(12,24,27,.1);
}
.login-card-logo { width: 120px; margin-bottom: 34px; }
.login-card h2 { margin-bottom: 8px; font-size: 2rem; letter-spacing: -.04em; }
.login-card form { margin-top: 28px; }
.login-card input { padding: 14px; }
.login-card button { padding: 14px 16px; }

/* Main shell */
.application {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
}
.app-rail {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 20px 13px 14px;
  color: white;
  background: var(--ink);
  border-right: 1px solid #20282b;
}
.rail-brand { display: flex; align-items: center; gap: 8px; padding: 5px 9px 24px; }
.rail-brand img { width: 92px; filter: brightness(0) invert(1); }
.rail-brand span { color: #8e9a9d; font-size: .71rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.compose-button {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  background: #fff;
  color: #0d1416;
  box-shadow: 0 8px 22px rgba(0,0,0,.2);
}
.compose-button:hover { background: #eaf2f3; color: #0d1416; }
.compose-button span { font-size: 1.15rem; }
.rail-nav { display: grid; gap: 5px; }
.rail-nav .tab {
  display: grid;
  grid-template-columns: 24px minmax(0,1fr) auto;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 10px 11px;
  background: transparent;
  color: #9da8aa;
  text-align: left;
  border-radius: 9px;
}
.rail-nav .tab:hover { background: #182124; color: #fff; }
.rail-nav .tab.active { background: #202a2d; color: #fff; }
.rail-nav .tab b { min-width: 22px; padding: 2px 6px; border-radius: 999px; background: #303b3e; font-size: .68rem; text-align: center; }
.rail-nav .tab.active b { background: var(--blue); }
.nav-icon { font-size: .94rem; text-align: center; }
.rail-status { display: grid; gap: 6px; margin-top: auto; padding: 14px 9px; border-top: 1px solid #242d30; }
.status-dot { position: relative; padding-left: 15px; color: #96a1a4; font-size: .72rem; font-weight: 720; }
.status-dot::before { content: ""; position: absolute; left: 0; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: #3aaa6f; box-shadow: 0 0 0 3px rgba(58,170,111,.12); }
.status-dot.warning::before, .status-dot.neutral::before { background: #9aa4a6; box-shadow: none; }
.status-dot.danger::before { background: #d65353; }
.rail-lock { width: 100%; padding: 9px; background: transparent; color: #788487; font-size: .74rem; }
.rail-lock:hover { background: #182124; color: #fff; }
.app-content { min-width: 0; min-height: 0; background: var(--canvas); }
.tab-panel { height: 100%; min-height: 0; }

/* Three-panel inbox */
.inbox-view { overflow: hidden; }
.mail-workspace {
  display: grid;
  grid-template-columns: var(--mail-list-width) minmax(440px, 1fr) var(--context-width);
  height: 100%;
  min-height: 0;
  background: #fff;
}
.mail-list-panel,
.conversation-panel,
.context-panel { min-width: 0; min-height: 0; }
.mail-list-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f8f9f9;
}
.panel-header {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.panel-header h2 { margin: 1px 0 0; font-size: 1.04rem; }
.panel-header .eyebrow { margin-bottom: 1px; }
.icon-button { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; background: #f0f3f3; color: #344144; font-size: 1.05rem; }
.icon-button:hover { background: #e4eaeb; color: #111; }
.mail-search { display: flex; align-items: center; gap: 7px; margin: 11px 12px 7px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #8a9497; }
.mail-search input { border: 0; box-shadow: none; padding: 9px 0; background: transparent; font-size: .82rem; }
.mail-search input:focus { box-shadow: none; }
.ticket-filters { display: flex; gap: 3px; margin: 5px 12px 9px; padding: 3px; border-radius: 9px; background: #eceff0; }
.ticket-filter { flex: 1; display: flex; justify-content: center; align-items: center; gap: 5px; padding: 7px 5px; border-radius: 7px; background: transparent; color: #697578; font-size: .7rem; }
.ticket-filter:hover { background: #fff; color: #172124; }
.ticket-filter.active { background: #fff; color: #111719; box-shadow: 0 1px 5px rgba(13,26,29,.08); }
.ticket-filter span { min-width: 18px; padding: 1px 5px; border-radius: 99px; background: #dde3e4; font-size: .62rem; }
.email-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); }
.email-item {
  display: block;
  width: 100%;
  padding: 13px 15px;
  border: 0;
  border-bottom: 1px solid #e8ebec;
  border-radius: 0;
  background: transparent;
  color: var(--copy);
  text-align: left;
}
.email-item:hover { background: #f0f5f5; }
.email-item.active { background: #e8f2f3; box-shadow: inset 3px 0 0 var(--blue); }
.email-item.unread .email-sender,
.email-item.unread .email-subject { font-weight: 850; color: #0d1719; }
.email-item.complete { opacity: .62; }
.email-topline { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.email-sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; font-weight: 720; }
.email-date { flex: 0 0 auto; color: #899396; font-size: .67rem; }
.email-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px; font-size: .79rem; font-weight: 690; }
.email-summary { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: #758083; font-size: .72rem; line-height: 1.35; }
.email-state-row { display: flex; gap: 5px; margin-top: 7px; }
.email-state { padding: 3px 6px; border-radius: 999px; font-size: .6rem; font-weight: 800; }
.email-state.replied { background: #e9f0ff; color: #355d9b; }
.email-state.complete { background: #eaf6ef; color: #2c7049; }

.conversation-panel { position: relative; overflow: hidden; background: #fff; }
.conversation-placeholder { height: 100%; display: grid; place-content: center; justify-items: center; padding: 40px; text-align: center; color: var(--copy-muted); }
.placeholder-icon { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 16px; border-radius: 15px; background: var(--blue-soft); color: var(--blue); font-size: 1.35rem; }
.conversation-placeholder h2 { color: var(--copy); font-size: 1.25rem; }
.conversation-content { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.conversation-header {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  min-height: 84px;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
}
.conversation-identity { display: flex; min-width: 0; align-items: center; gap: 12px; }
.avatar { display: grid; flex: 0 0 38px; width: 38px; height: 38px; place-items: center; border-radius: 50%; background: #11191b; color: #fff; font-size: .85rem; font-weight: 850; }
.customer-name { margin: 0 0 2px; font-size: .76rem; font-weight: 800; color: #3a484b; }
.conversation-header h1 { overflow: hidden; margin: 0 0 2px; text-overflow: ellipsis; white-space: nowrap; font-size: 1.15rem; letter-spacing: -.025em; }
.conversation-header .muted { margin: 0; font-size: .68rem; }
.ticket-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.ticket-status { padding: 5px 8px; border-radius: 999px; font-size: .65rem; font-weight: 850; }
.ticket-status.open { background: #fff4dc; color: #855800; }
.ticket-status.complete { background: #e9f6ee; color: #267045; }
.thread-list { display: grid; gap: 13px; padding: 22px clamp(18px, 4vw, 48px); background: #f6f8f8; }
.thread-message { max-width: 82%; padding: 15px 17px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 4px 13px rgba(15,30,34,.035); }
.thread-message.inbound { justify-self: start; border-top-left-radius: 4px; }
.thread-message.outbound { justify-self: end; border-color: #cde1e3; border-top-right-radius: 4px; background: #eef7f8; }
.thread-message-header { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 10px; padding-bottom: 9px; border-bottom: 1px solid rgba(218,225,226,.7); }
.thread-message-header p { margin: 0; font-size: .7rem; }
.thread-message-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .86rem; line-height: 1.65; }
.history-panel { margin: 0 clamp(18px,4vw,48px) 20px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.history-panel summary { cursor: pointer; padding: 11px 13px; color: #526063; font-size: .75rem; font-weight: 760; }
.history-list { padding: 0 13px 13px; }

.reply-composer { margin: 0 clamp(18px,4vw,48px) 42px; padding: 20px; border: 1px solid var(--line-strong); border-radius: 14px; background: #fff; box-shadow: var(--shadow-soft); }
.reply-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.reply-heading h2 { margin: 0; font-size: 1.08rem; }
.composer-help { margin: 0 0 13px; padding: 9px 11px; border-radius: 8px; background: #f3f7f7; color: #536164; font-size: .73rem; line-height: 1.45; }
.reply-composer label { display: block; margin: 11px 0 5px; font-size: .72rem; }
.reply-composer textarea, .reply-composer input { font-size: .84rem; }
.reply-composer #draftText { min-height: 230px; line-height: 1.6; }
.prompt-shortcuts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.prompt-shortcut { width: auto; padding: 6px 9px; border: 1px solid var(--line); background: #f6f8f8; color: #526063; font-size: .67rem; }
.generate-row, .delivery-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.generate-row button:first-child { flex: 1; }
.delivery-actions { justify-content: flex-end; }
.draft-review-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; padding: 9px; border-radius: 8px; background: #f5f7f7; font-size: .68rem; }
.schedule-panel { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #f8fafa; }

.context-panel { overflow-y: auto; border-left: 1px solid var(--line); background: #f8f9f9; }
.context-panel > .muted { padding: 12px 16px 0; font-size: .72rem; }
#customerOrderResults { padding: 12px; }
.context-safety { display: grid; gap: 7px; margin: 4px 13px 18px; padding: 12px; border: 1px solid #dce6e7; border-radius: 10px; background: #fff; }
.context-safety span { padding-left: 17px; position: relative; color: #657174; font-size: .68rem; }
.context-safety span::before { content: "✓"; position: absolute; left: 0; color: var(--blue); font-weight: 900; }
.compact-order-card { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.compact-order-card + .compact-order-card { margin-top: 10px; }
.order-header { display: flex; justify-content: space-between; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.order-header h3 { margin: 0 0 3px; font-size: .9rem; }
.chip-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.chip { padding: 3px 6px; border-radius: 99px; background: #edf1f2; color: #556164; font-size: .58rem; font-weight: 800; }
.compact-order-body { display: grid; gap: 10px; padding: 12px; }
.compact-order-facts p { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 5px; font-size: .7rem; }
.compact-product-list h4 { margin: 0 0 5px; font-size: .72rem; }
.compact-product-list ul { margin: 0; padding-left: 17px; font-size: .68rem; }
.order-card-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
.order-card-actions button { padding: 8px 7px; font-size: .68rem; }
.order-card-actions button:only-child { grid-column: 1 / -1; }

/* General pages */
.page-view { overflow-y: auto; padding: 28px clamp(20px,4vw,54px) 50px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; max-width: 1200px; margin: 0 auto 22px; }
.page-header h1 { margin: 0 0 6px; font-size: 2rem; }
.page-header p { margin: 0; color: var(--copy-muted); }
.orders-layout { display: grid; max-width: 1200px; margin: auto; gap: 16px; }
.order-search-card, .order-results-card { padding: 18px; }
.search-order-form { display: grid; grid-template-columns: 160px minmax(220px,1fr) auto; gap: 8px; }
.order-results-card #manualOrderResults { margin-top: 10px; }
.order-results-card .compact-order-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(280px,1fr)); gap: 12px; }

/* Scheduled */
.scheduled-list { display: grid; max-width: 1000px; margin: auto; gap: 10px; }
.scheduled-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 5px 18px rgba(15,28,31,.04); overflow: hidden; }
.scheduled-card.attention { border-color: #e8b5b5; }
.scheduled-card-main { display: grid; grid-template-columns: 190px minmax(0,1fr) auto; width: 100%; align-items: center; gap: 16px; padding: 16px 18px; background: #fff; color: var(--copy); text-align: left; }
.scheduled-card-main:hover { background: #f6f9f9; color: var(--copy); }
.scheduled-time { display: flex; align-items: center; gap: 8px; color: #304043; font-size: .75rem; }
.scheduled-time span { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 8px; background: var(--blue-soft); color: var(--blue); }
.scheduled-copy h3 { margin: 0 0 3px; font-size: .9rem; }
.scheduled-copy p, .scheduled-copy span { margin: 0; color: var(--copy-muted); font-size: .7rem; }
.scheduled-chevron { color: #9ba4a6; font-size: 1.5rem; }

/* Settings */
.settings-shell { display: grid; grid-template-columns: 200px minmax(0,1fr); max-width: 1320px; margin: auto; gap: 16px; }
.settings-nav { position: sticky; top: 0; align-self: start; display: grid; gap: 5px; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.settings-nav-button { width: 100%; padding: 10px 11px; background: transparent; color: #5f6b6e; text-align: left; font-size: .76rem; }
.settings-nav-button:hover { background: #f2f5f5; color: #111; }
.settings-nav-button.active { background: #11191b; color: #fff; }
.settings-content { min-width: 0; }
.settings-view { min-width: 0; }
.support-brain-grid { display: block; }
.support-brain-card { padding: 0 !important; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow-soft); overflow: hidden; }
.brain-heading { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.brain-heading h2 { font-size: 1.25rem; }
.knowledge-toolbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfb; }
.knowledge-toolbar input { flex: 1; }
.knowledge-toolbar button { width: auto; }
.brain-tabs { display: flex; gap: 5px; overflow-x: auto; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.brain-tab { flex: 0 0 auto; padding: 7px 10px; background: #f0f3f3; color: #5a676a; font-size: .69rem; }
.brain-tab.active { background: #11191b; color: #fff; }
.brain-panel { padding: 16px 18px 6px; border-bottom: 1px solid var(--line); }
.brain-panel:last-of-type { border-bottom: 0; }
.settings-section { padding: 15px 0; border-top: 1px solid var(--line); }
.settings-section.first-section { border-top: 0; }
.settings-section textarea { font-size: .8rem; }
.variable-list, .knowledge-editor-list, .learned-rule-list { display: grid; gap: 9px; }
.variable-row, .faq-card, .flow-card, .product-knowledge-card, .learned-rule-card { border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.variable-row { padding: 10px; }
.faq-card > summary, .flow-card > summary, .product-knowledge-card > summary { padding: 11px; }
.brain-save-bar { position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); }
.brain-health, #knowledgeNotice { margin: 12px 16px; }
.settings-simple-card { padding: 20px; margin-bottom: 14px; }
.settings-simple-card h2 { font-size: 1.12rem; }
.setting-explainer { display: grid; gap: 8px; margin-top: 14px; }
.setting-explainer p { margin: 0; padding: 10px 12px; border-radius: 9px; background: #f5f7f7; color: #5b686b; font-size: .78rem; }
#automaticReplyExclusions { min-height: 360px; margin: 12px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; }
.settings-connection-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.connection-list { display: grid; gap: 9px; }
.connection-list div { display: grid; grid-template-columns: 100px 1fr; gap: 10px; padding: 10px; border-radius: 8px; background: #f5f7f7; }
.connection-list dt { font-weight: 800; font-size: .73rem; }
.connection-list dd { margin: 0; color: #667275; font-size: .73rem; }
.scope-note { margin-top: 14px; color: #805800; font-size: .72rem; }
.file-button { display: inline-flex; align-items: center; justify-content: center; padding: 11px 15px; border-radius: 9px; background: var(--blue); color: #fff; cursor: pointer; font-size: .82rem; }

/* Connect state */
.connect-state { height: 100%; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.connect-state img { width: 130px; margin-bottom: 24px; }
.connect-state h2 { font-size: 1.4rem; }
.connect-state p { max-width: 450px; color: var(--copy-muted); }

/* Dialogs */
.workspace-dialog { width: min(1040px, calc(100vw - 30px)); max-width: none; max-height: calc(100dvh - 30px); padding: 0; border: 0; border-radius: 16px; background: transparent; box-shadow: 0 28px 100px rgba(0,0,0,.25); }
.workspace-dialog::backdrop { background: rgba(4,8,9,.55); backdrop-filter: blur(3px); }
.dialog-shell { max-height: calc(100dvh - 30px); overflow: hidden; border-radius: 16px; background: #fff; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 21px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 1px 0 0; }
.dialog-close { width: auto; }
.compose-body, .scheduled-edit-body { max-height: calc(100dvh - 100px); overflow-y: auto; padding: 20px 22px 26px; }
.compose-fields, .scheduled-edit-body { display: grid; gap: 8px; }
.compose-fields label, .scheduled-edit-body label { margin-top: 7px; }
.compose-fields #newEmailBody, #scheduledEditBody { min-height: 300px; line-height: 1.6; }
.scheduled-editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.danger-button { background: #a43a3a; }
.danger-button:hover { background: #832c2c; }

/* Existing expanded dialogs */
.expanded-order-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
.expanded-order-grid .full { grid-column: 1 / -1; }
.dialog-content { max-height: calc(100dvh - 105px); overflow-y: auto; padding: 18px; }
.expanded-draft-grid { display: grid; grid-template-columns: 340px minmax(0,1fr); max-height: calc(100dvh - 100px); overflow: hidden; }
.expanded-prompt-column, .expanded-editor-column { overflow-y: auto; padding: 20px; }
.expanded-prompt-column { border-right: 1px solid var(--line); background: #f7f9f9; }
.expanded-editor-column { display: flex; flex-direction: column; }
#expandedDraftText { min-height: 430px; flex: 1; line-height: 1.65; }

/* Mobile/tablet */
@media (max-width: 1180px) {
  :root { --rail-width: 74px; --mail-list-width: 300px; --context-width: 300px; }
  .rail-brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .rail-brand img { width: 42px; object-fit: cover; object-position: left; }
  .rail-brand span, .rail-nav .tab span:not(.nav-icon), .rail-lock { display: none; }
  .compose-button { width: 46px; height: 46px; margin-left: auto; margin-right: auto; padding: 0; font-size: 0; }
  .compose-button span { font-size: 1.2rem; }
  .rail-nav .tab { grid-template-columns: 1fr; justify-items: center; padding: 11px 5px; }
  .rail-nav .tab b { position: absolute; transform: translate(15px,-13px); }
  .rail-status { padding-left: 0; padding-right: 0; }
  .status-dot { overflow: hidden; width: 10px; height: 10px; padding: 0; margin: auto; font-size: 0; }
}

@media (max-width: 940px) {
  body { overflow: auto; }
  .application { display: block; height: auto; min-height: 100dvh; padding-bottom: 66px; }
  .app-rail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: block; width: 100%; height: 64px; padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border: 0; border-top: 1px solid #252d30; }
  .rail-brand, .compose-button, .rail-status, .rail-lock { display: none; }
  .rail-nav { display: grid; grid-template-columns: repeat(4,1fr); height: 100%; gap: 3px; }
  .rail-nav .tab { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 4px; font-size: .62rem; }
  .rail-nav .tab span:not(.nav-icon) { display: block; }
  .rail-nav .tab b { position: absolute; transform: translate(12px,-15px); }
  .app-content, .tab-panel { height: auto; min-height: calc(100dvh - 66px); }
  .mail-workspace { display: block; height: auto; }
  .mail-list-panel, .conversation-panel, .context-panel { min-height: auto; border: 0; }
  .mail-list-panel { min-height: calc(100dvh - 66px); }
  .email-list { overflow: visible; }
  .conversation-panel, .context-panel { display: none; }
  .mail-workspace.mobile-conversation-open .mail-list-panel { display: none; }
  .mail-workspace.mobile-conversation-open .conversation-panel { display: block; }
  .mail-workspace.mobile-context-open .conversation-panel { display: none; }
  .mail-workspace.mobile-context-open .context-panel { display: block; min-height: calc(100dvh - 66px); }
  .conversation-content { height: auto; overflow: visible; }
  .conversation-header { position: sticky; top: 0; }
  .thread-list { padding: 16px 12px; }
  .thread-message { max-width: 94%; }
  .reply-composer, .history-panel { margin-left: 12px; margin-right: 12px; }
  .context-panel { overflow: visible; }
  .page-view { padding: 20px 12px 86px; }
  .page-header { align-items: flex-start; }
  .search-order-form { grid-template-columns: 1fr; }
  .settings-shell { grid-template-columns: 1fr; }
  .settings-nav { position: static; display: flex; overflow-x: auto; }
  .settings-nav-button { flex: 0 0 auto; width: auto; }
  .settings-connection-grid { grid-template-columns: 1fr; }
  .scheduled-card-main { grid-template-columns: 1fr auto; }
  .scheduled-time { grid-column: 1 / -1; }
  .login-screen { display: block; background: #f5f7f7; }
  .login-brand-panel { display: none; }
  .login-form-panel { min-height: 100dvh; padding: 20px; }
  .login-card { padding: 28px 22px; }
  .workspace-dialog { width: 100vw; max-height: 100dvh; border-radius: 0; }
  .dialog-shell { max-height: 100dvh; border-radius: 0; }
  .compose-body, .scheduled-edit-body, .dialog-content { max-height: calc(100dvh - 78px); }
  .expanded-draft-grid, .expanded-order-grid { display: block; max-height: calc(100dvh - 78px); overflow-y: auto; }
  .expanded-prompt-column, .expanded-editor-column { overflow: visible; border-right: 0; }
}

@media (max-width: 560px) {
  .conversation-header { align-items: flex-start; padding: 11px 12px; }
  .conversation-identity { align-items: flex-start; }
  .avatar { width: 32px; height: 32px; flex-basis: 32px; }
  .conversation-header h1 { max-width: 46vw; font-size: .95rem; }
  .ticket-actions { flex-direction: column; align-items: flex-end; gap: 4px; }
  .ticket-actions button { padding: 6px 8px; font-size: .64rem; }
  .reply-composer { padding: 14px; }
  .delivery-actions button { flex: 1 1 30%; padding: 10px 7px; font-size: .72rem; }
  .scheduled-editor-actions { flex-direction: column; }
  .knowledge-toolbar { flex-direction: column; }
  .knowledge-toolbar button { width: 100%; }
  .brain-tabs { padding-left: 10px; padding-right: 10px; }
}
.mobile-only { display: none; }
@media (max-width: 940px) {
  .mobile-only { display: inline-grid; }
  .conversation-header { grid-template-columns: auto minmax(0,1fr) auto; }
  .mobile-back { flex: 0 0 34px; }
}


/* V11 finishing touches */
.knowledge-choice-dialog { width: min(760px, calc(100vw - 30px)); }
.knowledge-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 20px;
  overflow-y: auto;
}
.knowledge-choice-grid button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 3px 12px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--copy);
  text-align: left;
  box-shadow: none;
}
.knowledge-choice-grid button:hover { border-color: #77aeb5; background: #f3f9fa; }
.knowledge-choice-grid button > span {
  grid-row: 1 / span 2;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 10px;
  background: #11191b;
  color: #fff;
  font-size: .68rem;
  font-weight: 850;
  text-transform: uppercase;
}
.knowledge-choice-grid strong { font-size: .88rem; }
.knowledge-choice-grid small { color: var(--copy-muted); line-height: 1.4; }
.mobile-compose-fab { display: none; }

@media (max-width: 940px) {
  .mobile-compose-fab {
    position: fixed;
    right: 17px;
    bottom: calc(77px + env(safe-area-inset-bottom));
    z-index: 54;
    display: grid;
    width: 50px;
    height: 50px;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    font-size: 1.45rem;
    box-shadow: 0 12px 30px rgba(14, 91, 102, .32);
  }
  .knowledge-choice-grid { grid-template-columns: 1fr; padding: 14px; }
}


.knowledge-library-panel { padding: 18px !important; }
.knowledge-library-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.knowledge-library-header h3 { margin: 0 0 4px; }
.knowledge-library-list { display: grid; gap: 8px; }
.knowledge-library-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.knowledge-library-item:hover { border-color: #afc9cd; background: #fbfdfd; }
.knowledge-library-item.danger { border-left: 3px solid #b84a4a; }
.knowledge-library-copy { min-width: 0; }
.knowledge-library-copy > span { display: inline-block; margin-bottom: 3px; color: var(--blue); font-size: .61rem; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.knowledge-library-item.danger .knowledge-library-copy > span { color: #a23d3d; }
.knowledge-library-copy h4 { overflow: hidden; margin: 0 0 3px; color: #182124; font-size: .83rem; text-overflow: ellipsis; white-space: nowrap; }
.knowledge-library-copy p { display: -webkit-box; overflow: hidden; margin: 0; color: var(--copy-muted); font-size: .71rem; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
@media (max-width: 560px) {
  .knowledge-library-item { grid-template-columns: minmax(0,1fr); }
  .knowledge-library-item button { width: 100%; }
}


/* =========================================================
   OUTBOUND ATTACHMENTS
   ========================================================= */
.attachment-area {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.attachment-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

.attachment-button {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 38px;
  padding-inline: 13px;
}

.attachment-button::before {
  content: "📎";
  margin-right: 7px;
  font-size: .95rem;
}

.attachment-limit {
  color: var(--muted);
  font-size: .76rem;
}

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

.attachment-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 320px);
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #f7f9fa;
}

.attachment-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: #eaf3ff;
  color: #1768c5;
  font-weight: 900;
  transform: rotate(-45deg);
}

.attachment-copy {
  display: grid;
  min-width: 0;
}

.attachment-copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: .78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-copy small {
  color: var(--muted);
  font-size: .68rem;
}

.attachment-remove {
  display: grid;
  width: 26px;
  height: 26px;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
}

.attachment-remove:hover {
  background: #e8ecef;
  color: var(--text);
}

.scheduled-edit-body .attachment-area,
.compose-fields .attachment-area {
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .attachment-chip {
    max-width: 100%;
    flex: 1 1 100%;
  }

  .attachment-limit {
    flex-basis: 100%;
  }
}


/* Latest-message-first conversation view */
.thread-history-toggle {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7f8f8;
  overflow: hidden;
}

.thread-history-toggle > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: .82rem;
  font-weight: 800;
  list-style: none;
}

.thread-history-toggle > summary::-webkit-details-marker {
  display: none;
}

.thread-history-toggle > summary::before {
  content: "›";
  margin-right: 3px;
  font-size: 1.15rem;
  transition: transform .16s ease;
}

.thread-history-toggle[open] > summary::before {
  transform: rotate(90deg);
}

.thread-history-count {
  margin-left: auto;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}

.thread-history-messages {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
}

.thread-history-messages .thread-message:first-child {
  margin-top: 12px;
}

.latest-customer-message {
  border: 1px solid rgba(28, 116, 255, .25);
  box-shadow: 0 8px 24px rgba(18, 35, 50, .06);
}

.latest-message-label {
  width: fit-content;
  margin: -2px 0 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .03em;
  text-transform: uppercase;
}

@media (max-width: 800px) {
  .thread-history-toggle > summary {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .thread-history-count {
    width: 100%;
    margin-left: 22px;
  }
}


.zoho-connection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 16px 0 10px;
}

.danger-outline {
  border-color: #d7a8a8 !important;
  color: #a32828 !important;
  background: #fff !important;
}

.danger-outline:hover {
  border-color: #a32828 !important;
  background: #fff4f4 !important;
}


/* V17: mobile conversation header formatting repair */
@media (max-width: 940px) {
  .conversation-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 8px 10px;
    min-height: 0;
    padding: 10px 12px;
  }

  .conversation-header .mobile-back {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
  }

  .conversation-identity {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    align-items: flex-start;
  }

  .conversation-identity > div:last-child {
    width: 100%;
    min-width: 0;
  }

  .conversation-header h1 {
    width: 100%;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .98rem;
  }

  .conversation-header .customer-name,
  .conversation-header .muted {
    width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: normal;
    white-space: normal;
    line-height: 1.35;
  }

  .ticket-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    gap: 7px;
  }

  .ticket-actions button {
    width: auto;
    white-space: nowrap;
  }
}

@media (max-width: 520px) {
  .conversation-header {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .conversation-identity {
    gap: 9px;
  }

  .conversation-header .avatar {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .conversation-header .muted {
    font-size: .66rem;
  }

  .ticket-actions {
    padding-left: 44px;
  }

  .thread-list {
    padding-top: 12px;
  }
}


/* V18 brand and email defaults */
.rail-brand { justify-content: center; }
.rail-brand img { max-width: 118px; }
#defaultEmailSubject { width: 100%; margin-top: 8px; }


/* V19: responsive status and settings badge repairs */
@media (max-width: 1180px) and (min-width: 941px) {
  .rail-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px 0;
  }

  .rail-status .badge,
  .rail-status .status-dot {
    display: block;
    width: 11px;
    min-width: 11px;
    height: 11px;
    min-height: 11px;
    margin: 0;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 50%;
    background: #3aaa6f;
    color: transparent;
    font-size: 0;
    box-shadow: 0 0 0 3px rgba(58,170,111,.13);
  }

  .rail-status .neutral,
  .rail-status .warning {
    background: #9aa4a6;
    box-shadow: none;
  }

  .rail-status .danger {
    background: #d65353;
    box-shadow: 0 0 0 3px rgba(214,83,83,.12);
  }

  .rail-status .status-dot::before {
    display: none;
  }
}

.brain-heading > div {
  min-width: 0;
}

#knowledgeStatusBadge {
  flex: 0 0 auto;
  max-width: 150px;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}

.ai-model-card select {
  width: 100%;
  margin: 8px 0 8px;
}

.ai-model-card button {
  margin-top: 10px;
}

@media (max-width: 600px) {
  .brain-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
  }

  #knowledgeStatusBadge {
    max-width: 92px;
    padding: 6px 8px;
    font-size: .62rem;
    overflow-wrap: normal;
    word-break: normal;
  }
}

/* =========================================================
   V21 OPERATOR-CHOICE DRAFTING + SIMPLIFIED SETTINGS
   ========================================================= */
.simplified-settings-shell {
  grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
}

.simplified-settings-nav {
  align-content: start;
}

.simplified-settings-content {
  min-width: 0;
}

.simplified-settings-content .settings-view {
  display: grid;
  gap: 16px;
}

.settings-global-save {
  position: sticky;
  bottom: 12px;
  z-index: 6;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px 16px;
  align-items: center;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.95);
  box-shadow: 0 12px 28px rgba(16,31,35,.1);
  backdrop-filter: blur(12px);
}

.settings-global-save .brain-health,
.settings-global-save .notice {
  margin: 0;
}

.operator-rule-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.operator-rule-strip span {
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef7f8;
  color: #175c64;
  font-size: .75rem;
  font-weight: 800;
}

.reply-decision-dialog {
  padding: 0;
}

.reply-decision-shell {
  width: min(720px, calc(100vw - 28px));
  max-height: min(780px, calc(100dvh - 28px));
}

.reply-decision-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow-y: auto;
}

.reply-choice-list {
  display: grid;
  gap: 10px;
}

.reply-choice-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.reply-choice-card:hover {
  border-color: #78aeb4;
  background: #f6fbfb;
}

.reply-choice-card:has(input:checked) {
  border-color: #167f8e;
  background: #eef8f9;
  box-shadow: inset 0 0 0 1px #167f8e;
}

.reply-choice-card input {
  margin-top: 4px;
}

.reply-choice-card span {
  display: grid;
  gap: 4px;
}

.reply-choice-card strong {
  color: var(--copy);
  font-size: .9rem;
}

.reply-choice-card small {
  color: var(--copy-muted);
  line-height: 1.45;
}

.reply-other-box {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafa;
}

.reply-other-box span {
  font-size: .78rem;
  font-weight: 800;
}

.decision-summary-card {
  padding: 14px;
  border: 1px solid #b7dcce;
  border-radius: 12px;
  background: #f0faf5;
}

.decision-summary-card.excluded {
  border-color: #e3c9c9;
  background: #fff7f7;
}

.decision-summary-card ul {
  display: grid;
  gap: 7px;
  margin: 8px 0 0;
  padding-left: 20px;
}

.settings-chat-log {
  display: grid;
  gap: 10px;
  max-height: 330px;
  margin: 15px 0 12px;
  padding: 12px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f6f8f8;
}

.assistant-chat-message {
  width: fit-content;
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: .84rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.assistant-chat-message.assistant {
  justify-self: start;
  border-top-left-radius: 3px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(14,29,33,.05);
}

.assistant-chat-message.user {
  justify-self: end;
  border-top-right-radius: 3px;
  background: #e8f5f6;
}

.assistant-proposal {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.assistant-proposal-head,
.knowledge-history-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.assistant-change-list,
.knowledge-history-list {
  display: grid;
  gap: 10px;
}

.assistant-change-card,
.knowledge-history-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.assistant-change-card > div:first-child p,
.knowledge-history-card p {
  margin: 4px 0 0;
  color: var(--copy-muted);
  font-size: .74rem;
}

.assistant-diff {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 11px;
}

.assistant-diff > div {
  min-width: 0;
  padding: 9px;
  border-radius: 9px;
  background: #f6f8f8;
}

.assistant-diff span {
  display: block;
  margin-bottom: 5px;
  color: var(--copy-muted);
  font-size: .66rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.assistant-diff pre {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  color: var(--copy);
  font: inherit;
  font-size: .73rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.policy-test-card {
  opacity: .82;
}

@media (max-width: 940px) {
  .simplified-settings-shell {
    grid-template-columns: 1fr;
  }

  .simplified-settings-nav {
    position: static;
    display: flex;
    gap: 7px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .simplified-settings-nav::-webkit-scrollbar {
    display: none;
  }

  .simplified-settings-nav .settings-nav-button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .settings-global-save {
    grid-template-columns: 1fr;
    bottom: 78px;
  }
}

@media (max-width: 620px) {
  .reply-decision-shell {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .reply-decision-body {
    padding: 12px;
  }

  .assistant-diff {
    grid-template-columns: 1fr;
  }

  .assistant-chat-message {
    max-width: 94%;
  }

  .knowledge-history-card {
    flex-direction: column;
  }

  .knowledge-history-card button {
    width: 100%;
  }
}

.simplified-variable-main {
  grid-template-columns: minmax(180px, .65fr) minmax(0, 1.35fr);
}

.advanced-field {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: #fafbfb;
}

.advanced-field > summary {
  cursor: pointer;
  color: var(--copy-muted);
  font-size: .72rem;
  font-weight: 800;
}

.advanced-field[open] > summary {
  margin-bottom: 8px;
}

@media (max-width: 680px) {
  .simplified-variable-main {
    grid-template-columns: 1fr;
  }
}


/* V22 ticket usability and softer visual hierarchy */
.mail-list-panel {
  background: #e9edef;
}

.mail-list-panel .panel-header {
  background: #f2f4f5;
}

.mail-search {
  border-color: #d2d9db;
  box-shadow: 0 1px 2px rgba(17, 30, 34, .03);
}

.ticket-filters {
  padding: 5px;
  border: 1px solid #d2d8da;
  background: #dce2e4;
}

.ticket-filter.active {
  box-shadow: 0 2px 7px rgba(13, 26, 29, .1);
}

.email-list {
  background: #eef1f2;
}

.email-item {
  background: rgba(255,255,255,.42);
}

.email-item:hover {
  background: rgba(255,255,255,.76);
}

.email-item.active {
  background: #fff;
}

.thread-list {
  background: #f2f5f4;
}

.shopify-context-header {
  position: sticky;
  top: 0;
  z-index: 4;
}

.shopify-context-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.shopify-data-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 4px 7px;
  border-radius: 999px;
  background: #e7f6ec;
  color: #17713c;
  font-size: .61rem;
  font-weight: 850;
  white-space: nowrap;
}

.shopify-data-badge > span {
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 4px;
  background: #008060;
  color: #fff;
  font-size: .56rem;
}

.full-context-order-list {
  display: grid;
  gap: 12px;
}

.context-panel .expanded-order-card {
  border-color: #cfe2d6;
  box-shadow: 0 5px 18px rgba(0, 128, 96, .05);
}

.context-panel .expanded-order-grid {
  grid-template-columns: 1fr;
}

.context-panel .expanded-order-grid .info-block.full {
  grid-column: auto;
}

.context-panel .expanded-order-card .order-header {
  border-top: 3px solid #008060;
}

.ticket-scheduled-panel {
  margin: 0 clamp(18px,4vw,48px) 16px;
  padding: 14px;
  border: 1px solid #d8e4e6;
  border-radius: 12px;
  background: #f8fbfb;
}

.ticket-scheduled-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}

.ticket-scheduled-heading h2 {
  margin: 0;
  font-size: .94rem;
}

.ticket-scheduled-count {
  min-width: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: .66rem;
  font-weight: 850;
  text-align: center;
}

.ticket-scheduled-list {
  display: grid;
  gap: 7px;
}

.ticket-scheduled-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}

.ticket-scheduled-card.attention {
  border-color: #dfb1b1;
}

.ticket-scheduled-copy {
  min-width: 0;
}

.ticket-scheduled-time,
.ticket-scheduled-copy p {
  margin: 0;
  color: var(--copy-muted);
  font-size: .66rem;
}

.ticket-scheduled-copy h3 {
  overflow: hidden;
  margin: 3px 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .8rem;
}

.ticket-scheduled-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.withdraw-scheduled {
  border-color: #e0bbbb !important;
  color: #a33333 !important;
}

.original-email-toggle {
  margin-top: 12px;
  border-top: 1px dashed #d5dcde;
}

.original-email-toggle summary {
  cursor: pointer;
  padding-top: 9px;
  color: #687578;
  font-size: .68rem;
  font-weight: 760;
}

.original-email-body {
  max-height: 360px;
  overflow: auto;
  margin-top: 8px;
  padding: 11px;
  border-radius: 8px;
  background: #f4f6f6;
  color: #5b686b;
  white-space: pre-wrap;
  font-size: .72rem;
  line-height: 1.55;
}

@media (max-width: 940px) {
  .ticket-scheduled-panel {
    margin-left: 12px;
    margin-right: 12px;
  }

  .ticket-scheduled-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .ticket-scheduled-actions {
    width: 100%;
  }

  .ticket-scheduled-actions button {
    flex: 1;
  }
}


/* V23: compact, task-focused Shopify order context */
.context-panel {
  --shopify-green: #008060;
  --shopify-green-dark: #006e52;
  --shopify-green-soft: #e8f5ee;
}

.context-panel > .muted {
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.full-context-order-list {
  padding: 12px;
}

.context-panel .shopify-summary-card {
  overflow: hidden;
  border: 1px solid #cfe1d6;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(0, 128, 96, .055);
}

.shopify-summary-header {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 3px solid var(--shopify-green);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfdfc);
}

.shopify-order-heading,
.shopify-section-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.shopify-order-heading > div {
  min-width: 0;
}

.shopify-summary-kicker {
  margin: 0 0 1px;
  color: var(--shopify-green-dark);
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.shopify-summary-header h3 {
  margin: 0;
  font-size: 1.02rem;
}

.shopify-summary-header .chip-row {
  gap: 5px;
}

.shopify-summary-header .chip {
  padding: 4px 7px;
  font-size: .62rem;
}

.shopify-section-icon {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  background: var(--shopify-green-soft);
  color: var(--shopify-green-dark);
}

.shopify-section-icon svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.shopify-pound-icon {
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.shopify-summary-sections {
  display: grid;
}

.shopify-summary-section {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.shopify-summary-section:last-child {
  border-bottom: 0;
}

.shopify-section-heading {
  margin-bottom: 10px;
}

.shopify-section-heading h4 {
  margin: 0;
  color: #263437;
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .025em;
}

.shopify-customer-row {
  display: grid;
  gap: 2px;
  padding-left: 40px;
}

.shopify-customer-row strong {
  font-size: .88rem;
}

.shopify-customer-row a {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: .72rem;
  text-decoration: none;
}

.shopify-customer-row a:hover {
  color: var(--shopify-green-dark);
  text-decoration: underline;
}

.shopify-money-grid {
  display: grid;
  gap: 7px;
  padding-left: 40px;
}

.shopify-money-grid > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.shopify-money-grid span {
  color: var(--muted);
  font-size: .7rem;
}

.shopify-money-grid strong {
  font-size: .87rem;
  white-space: nowrap;
}

.shopify-money-grid .refund-value strong {
  color: var(--danger);
}

.shopify-product-rows {
  display: grid;
  gap: 9px;
}

.shopify-product-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid #e1e8e3;
  border-radius: 10px;
  background: #fbfcfb;
}

.shopify-product-thumb {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #dfe7e1;
  border-radius: 9px;
  background: #fff;
}

.shopify-product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.shopify-product-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #7a9184;
}

.shopify-product-placeholder svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
}

.shopify-product-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.shopify-product-copy strong {
  overflow-wrap: anywhere;
  font-size: .78rem;
  line-height: 1.3;
}

.shopify-product-copy span {
  color: var(--muted);
  font-size: .67rem;
}

.shopify-delivery-summary,
.shopify-delivery-empty {
  display: grid;
  gap: 7px;
  padding-left: 40px;
}

.shopify-delivery-topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.shopify-delivery-topline > div {
  display: grid;
  gap: 2px;
}

.shopify-delivery-topline strong {
  font-size: .88rem;
}

.shopify-delivery-topline span:not(.chip),
.shopify-delivery-empty span {
  color: var(--muted);
  font-size: .68rem;
}

.shopify-delivery-summary > p {
  display: grid;
  grid-template-columns: 64px minmax(0,1fr);
  gap: 8px;
  margin: 0;
  font-size: .72rem;
}

.shopify-delivery-summary > p > span {
  color: var(--muted);
}

.shopify-delivery-summary > p > strong {
  overflow-wrap: anywhere;
}

.shopify-tracking-link {
  width: fit-content;
  margin-top: 2px;
  color: var(--shopify-green-dark);
  font-size: .73rem;
  font-weight: 850;
}

.shopify-tracking-history {
  margin-top: 5px;
  border-top: 1px solid #e1e8e3;
  padding-top: 8px;
}

.shopify-tracking-history > summary {
  cursor: pointer;
  color: #4d6258;
  font-size: .68rem;
  font-weight: 800;
}

.shopify-tracking-history .shopify-event-timeline {
  margin-top: 10px;
}

.shopify-exception-section {
  background: #fff9f1;
}

.shopify-exception-section .alert-icon {
  background: #fff0d9;
  color: #9a5f00;
}

.shopify-exception-section p {
  margin: 4px 0 0 40px;
  font-size: .72rem;
}

@media (max-width: 940px) {
  .full-context-order-list {
    padding: 10px;
  }

  .shopify-summary-header,
  .shopify-summary-section {
    padding-left: 12px;
    padding-right: 12px;
  }
}
