:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-2: #f0f2f1;
  --border: #dde2df;
  --text: #1c2421;
  --muted: #5d6a65;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e3efea;
  --note-bg: #fff8e1;
  --note-border: #ecd8a0;
  --danger: #b3261e;
  --focus: #2f6f5e55;

  --st-new: #b7791f;
  --st-open: #c53030;
  --st-pending: #2b6cb0;
  --st-hold: #2d3748;
  --st-solved: #718096;
  --st-closed: #a0aec0;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1a201e;
    --surface-2: #222a27;
    --border: #2e3834;
    --text: #e4ebe8;
    --muted: #94a39d;
    --accent: #5fb39a;
    --accent-text: #0d1311;
    --accent-soft: #1f3a32;
    --note-bg: #2e2915;
    --note-border: #574b23;
    --danger: #f2827a;
    --focus: #5fb39a66;
    --st-hold: #a0aec0;
    --st-closed: #5a6672;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Buttons and fields */
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.linkish:hover { text-decoration: underline; }
.field {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 8px;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

/* Shell */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo img { width: 22px; height: 22px; }
.search { flex: 1; max-width: 520px; }
.topbar .spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 52px); }
.sidebar { border-right: 1px solid var(--border); padding: 12px 8px; background: var(--surface); }
.sidebar h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 10px 6px; }
.view-link {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px; color: var(--text);
}
.view-link:hover { background: var(--surface-2); text-decoration: none; }
.view-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.view-link.active .count { color: var(--accent); }
.main { min-width: 0; padding: 20px 24px 40px; }

/* Ticket list */
.list-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.list-head h1 { font-size: 20px; margin: 0; }
.table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 84px 1fr 150px 90px; gap: 12px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text);
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); text-decoration: none; }
.row .subject { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { text-align: right; font-variant-numeric: tabular-nums; }
.row.unread .subject::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--st-new); margin-right: 7px; vertical-align: 2px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.more { display: flex; justify-content: center; padding: 12px; }

.pill {
  display: inline-block; min-width: 64px; text-align: center; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: #fff;
}
.pill.new { background: var(--st-new); }
.pill.open { background: var(--st-open); }
.pill.pending { background: var(--st-pending); }
.pill.hold { background: var(--st-hold); color: var(--surface); }
.pill.solved { background: var(--st-solved); }
.pill.closed { background: var(--st-closed); }
.brand { font-size: 11px; font-weight: 650; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--muted); margin-left: 6px; }

/* Ticket view */
.ticket { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.ticket-head { margin-bottom: 14px; }
.ticket-head .crumbs { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.ticket-head h1 { font-size: 20px; margin: 0; cursor: text; border-radius: 4px; }
.ticket-head h1:hover { background: var(--surface-2); }
.ticket-head input { font-size: 20px; font-weight: 650; }
.banner.flag { background: var(--note-bg); border-color: var(--note-border); overflow-wrap: anywhere; }
.spell { font-size: 12px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.spell:empty { display: none; }
.spell mark { background: #fde68a; color: #1c2421; text-decoration: underline wavy var(--danger); padding: 0 2px; border-radius: 2px; }
.agent-row { grid-template-columns: 1fr 120px 140px 120px; }
.agent-row.paused { opacity: 0.6; }
.banner.dup { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; background: var(--note-bg); border-color: var(--note-border); }
.banner.dup .btn { margin-left: auto; padding: 3px 10px; }
.summary { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); white-space: pre-wrap; }
.banner { padding: 8px 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 12px; }

.msg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; }
.msg.note { background: var(--note-bg); border-color: var(--note-border); }
.msg.auto { opacity: 0.8; }
.msg-head { display: flex; gap: 10px; align-items: center; padding: 10px 14px 0; }
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 650; font-size: 13px; color: var(--muted);
}
.msg.note .avatar { background: var(--note-border); color: var(--text); }
.msg-head .name { font-weight: 600; }
.msg-head .meta { flex: 1; min-width: 0; }
.msg-head .meta div { overflow-wrap: anywhere; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); margin-left: 6px; font-weight: 500; }
.msg.note .tag { background: var(--note-border); color: var(--text); }
.msg-body { padding: 10px 14px 12px 54px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-actions { padding: 0 14px 10px 54px; display: flex; gap: 14px; font-size: 12px; }
.msg iframe { display: block; width: calc(100% - 68px); margin: 10px 14px 12px 54px; border: 1px solid var(--border); border-radius: 6px; background: #fff; min-height: 120px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 12px 54px; }
.att { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px 4px 4px; background: var(--surface); color: var(--text); max-width: 260px; }
.att:hover { text-decoration: none; border-color: var(--accent); }
.att img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; background: var(--surface-2); }
.att .icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 4px; background: var(--surface-2); font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-atts { padding: 8px 0 0; }
.composer-atts:empty { display: none; }
.composer-atts .att .icon { width: 30px; height: 30px; }
.composer-atts .att.uploading { opacity: 0.6; }
.composer-atts .linkish { font-size: 16px; line-height: 1; padding: 0 2px; color: var(--muted); }

.composer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px 12px; box-shadow: var(--shadow); }
.composer.note { background: var(--note-bg); border-color: var(--note-border); }
.composer.reply { border-color: var(--accent); }
.tabs { display: flex; gap: 4px; margin: 0 -12px 10px; padding: 0 8px; border-bottom: 1px solid var(--border); }
.composer.note .tabs { border-color: var(--note-border); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 8px 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.composer.note .tabs button.active { border-bottom-color: var(--st-new); }
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.send-mode { font-size: 12px; padding: 6px 10px; border-radius: 6px; margin-bottom: 8px; background: var(--note-bg); border: 1px solid var(--note-border); }
.fill-ins { font-size: 12px; color: var(--danger); min-height: 0; margin-top: 4px; }
.fill-ins code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; margin: 0 3px; color: var(--text); }
.msg.outbound { border-left: 3px solid var(--accent); }
.tag.warn { background: var(--note-bg); color: var(--text); border: 1px solid var(--note-border); }
.tag.bad { background: var(--danger); color: #fff; }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.mailbox-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.mailbox { margin-bottom: 14px; }
.mailbox.paused { opacity: 0.75; }
.mailbox-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.mailbox-address { font-weight: 650; font-size: 15px; overflow-wrap: anywhere; }
.mailbox-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.mailbox .banner { margin: 0 0 10px; }
.steps { padding-left: 18px; margin: 0 0 12px; }
.steps li { margin-bottom: 4px; }
.policy summary { cursor: pointer; padding: 4px 0; font-weight: 600; }
.policy-body { white-space: pre-wrap; font-size: 12px; padding: 4px 0 8px; }
.tpl-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
.tpl-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 6px 10px; }
.tpl-list h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 12px 10px 4px; }
.tpl-item { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 7px 10px; cursor: pointer; }
.tpl-item:hover { background: var(--surface-2); }
.tpl-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tpl-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.tpl-body { min-height: 320px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.composer textarea { min-height: 90px; resize: vertical; background: var(--surface); }
.composer.reply textarea { min-height: 180px; }
.bar { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 12px; flex-wrap: wrap; }
.composer .label { font-weight: 600; margin-bottom: 6px; }

.props { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.card h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
.card.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.prop { margin-bottom: 10px; }
.prop:last-child { margin-bottom: 0; }
.prop label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.events { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.events li { padding: 4px 0; border-top: 1px solid var(--border); }
.events li:first-child { border-top: 0; }
.inline-form { display: flex; gap: 6px; margin-top: 6px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 1000px) {
  .ticket, .tpl-layout, .mailbox-layout { grid-template-columns: 1fr; }
  .tpl-grid { grid-template-columns: 1fr; }
  .props { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { display: flex; overflow-x: auto; gap: 4px; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar h2 { display: none; }
  .view-link { flex: none; gap: 8px; }
  .main { padding: 16px; }
  .row { grid-template-columns: 1fr auto; }
  .row .pill-cell, .row .assignee { display: none; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; row-gap: 8px; }
  .topbar .search { order: 5; flex-basis: 100%; max-width: none; }
  .topbar select { max-width: 150px; }
  .me .name { display: none; }
  .msg-body, .msg-actions, .atts { padding-left: 14px; }
  .msg iframe { width: calc(100% - 28px); margin-left: 14px; }
}

/* Settings -> Website chat */
.cs-intro { max-width: 760px; margin: -4px 0 14px; }
.cs-actions { display: flex; align-items: center; gap: 10px; }
.cs-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.cs-edit { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cs-side { position: sticky; top: 64px; }
.cs-card textarea.field { resize: vertical; }
.cs-menu { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.cs-item { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.cs-item.off { opacity: 0.6; }
.cs-item-head { display: flex; align-items: center; gap: 8px; }
.cs-item-head .field { font-weight: 600; flex: 1; min-width: 0; }
.cs-item-tools { display: flex; gap: 4px; }
.cs-switch { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.cs-grid { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: start; }
.cs-grid > label { padding-top: 7px; }
.cs-row { display: flex; gap: 8px; }
.cs-msg { margin-bottom: 10px; }
.cs-msg label { font-weight: 600; font-size: 13px; }
.cs-history { list-style: none; margin: 0 0 8px; padding: 0; font-size: 13px; }
.cs-history li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.cs-preview { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 10px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 90px); overflow-y: auto; }
.cs-preview-head { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.cs-bot, .cs-me { padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; font-size: 13px; max-width: 90%; }
.cs-bot { background: var(--surface-2); align-self: flex-start; }
.cs-me { background: var(--accent); color: var(--accent-text); align-self: flex-end; }
.cs-opts { display: flex; flex-wrap: wrap; gap: 5px; }
.cs-opt { border: 1px solid var(--accent); color: var(--accent); background: none; border-radius: 14px; padding: 3px 9px; font-size: 12px; cursor: pointer; text-align: left; }
.cs-form { border: 1px dashed var(--border); border-radius: 8px; padding: 8px; font-size: 12px; color: var(--muted); }
@media (max-width: 1100px) { .cs-layout { grid-template-columns: 1fr; } .cs-side { position: static; order: -1; } .cs-preview { max-height: 320px; } }
pre.headers { font-size: 11px; line-height: 1.4; max-height: 320px; overflow: auto; background: var(--surface-2); border-radius: 6px; padding: 8px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 0; }
.presence { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.presence:empty { display: none; }
.presence .banner { margin: 0; }

/* Settings -> API access, and AI drafts in the reply box */
.api-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.api-row .field { flex: 1; min-width: 180px; }
.api-integration { margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.api-integration.paused { opacity: 0.7; }
.api-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.api-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.api-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.api-table tr.muted td { color: var(--muted); }
.api-token-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--border); padding-top: 10px; }
.api-scopes { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.api-scopes label { display: flex; align-items: center; gap: 6px; }
.api-secret { flex-direction: column; align-items: stretch !important; gap: 6px !important; margin-bottom: 12px; }
.api-code { display: flex; gap: 8px; align-items: flex-start; }
.api-code code, .api-code pre { flex: 1; margin: 0; font-size: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; word-break: break-all; }
.api-code .btn { margin-left: 0 !important; }
.ai-drafts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ai-drafts:empty { display: none; }
.ai-draft { border: 1px dashed var(--accent); border-radius: 8px; padding: 8px 10px; background: var(--surface); }
.ai-draft-body { white-space: pre-wrap; font-size: 13px; margin: 6px 0; max-height: 220px; overflow-y: auto; }
.ai-draft-note { margin-top: 2px; }
.ai-draft-actions { display: flex; gap: 6px; }
.api-steps { margin: 0 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.api-steps .api-code { margin-top: 4px; }
.api-h2 { font-size: 16px; margin: 20px 0 4px; }
section.card + section.card { margin-top: 12px; }

/* Orders (NetSuite) and warranty pre-check cards */
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.order + .order { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.order-head { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.error-text { color: var(--danger, #b42318); }
.card.warranty summary { cursor: pointer; list-style-position: outside; }
.card.warranty[open] summary { margin-bottom: 8px; }
.warranty-form { display: flex; flex-direction: column; gap: 6px; }
.warranty-form .prop { display: grid; grid-template-columns: 1fr; gap: 2px; }
.warranty-form .prop label { font-size: 12px; color: var(--muted); }
.warranty-form .known { margin: 0 0 4px; padding-left: 16px; }
.warranty-result:not(:empty) { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.decision { font-size: 14px; }
.ws-decision { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.ws-decision legend { font-size: 12px; color: var(--muted); padding: 0 4px; }

/* Settings -> Integrations */
.integ-layout { max-width: 720px; display: grid; gap: 16px; }
.integ-field .integ-status { display: flex; gap: 10px; align-items: baseline; margin-top: 4px; }
.integ-warn { border-color: var(--note-border); background: var(--note-bg); }
.integ-cmd { font-size: 12px; padding: 8px 10px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); overflow-x: auto; }
.integ-ok { color: var(--accent); font-weight: 600; }
.integ-actions { display: flex; gap: 8px; }
.integ-help { margin: 4px 0 12px; }
.integ-log { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.order-note { margin: 6px 0; padding: 6px 8px; border-radius: 6px; background: var(--note-bg); border: 1px solid var(--note-border); }
.order-head .tag { margin-left: 6px; }
