/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .45rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap;
  min-height: 34px;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .25rem .55rem; min-height: 28px; font-size: .82rem; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--text-2); position: relative; }
.icon-btn:hover { background: var(--hover); }
.icon-btn .dot { position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .65rem; display: grid; place-items: center; padding: 0 3px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn[aria-pressed='true'] { background: color-mix(in srgb, var(--brand) 14%, var(--surface)); border-color: var(--brand); z-index: 1; }

/* ---------- Forms ---------- */
.input, select.input, textarea.input {
  width: 100%; padding: .45rem .65rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); min-height: 34px;
}
textarea.input { resize: vertical; min-height: 80px; }
.input:focus { border-color: var(--brand); outline: none; box-shadow: var(--focus); }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.field label, .label { font-size: .78rem; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: .74rem; color: var(--muted); }
.req::after { content: ' *'; color: var(--bad); }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.switch { position: relative; display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { left: 16px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: .75rem 1rem; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: .5rem; }
.card-head h2, .card-head h3 { margin: 0; font-size: .95rem; }
.card-body { padding: 1rem; }
.card-body.tight { padding: .5rem; }

.kpi { padding: .9rem 1rem; }
.kpi .kpi-label { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.kpi .kpi-value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-foot { font-size: .75rem; color: var(--muted); margin-top: .15rem; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: var(--neutral-bg); color: var(--text-2); white-space: nowrap; line-height: 1.5;
}
.badge svg { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.accent { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-strong); }
[data-theme='dark'] .badge.accent { color: var(--brand-accent); }
.badge.outline { background: transparent; border: 1px solid var(--border); }
.prio { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; }
.prio::before { content: ''; width: 9px; height: 9px; border-radius: 2px; background: var(--muted); }
.prio.p1::before { background: #8fbf9f; } .prio.p2::before { background: #4f8fd8; }
.prio.p3::before { background: #e39b2d; } .prio.p4::before { background: #d64545; }
.channel-pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; color: #fff; }
.channel-pill.whatsapp { background: var(--ch-whatsapp); }
.channel-pill.messenger { background: var(--ch-messenger); }
.channel-pill.instagram { background: var(--ch-instagram); }
.channel-pill svg { width: 11px; height: 11px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex-shrink: 0; color: #fff; }
.avatar.sm { width: 26px; height: 26px; font-size: .68rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table th { text-align: left; font-weight: 600; color: var(--text-2); font-size: .78rem; padding: .6rem .75rem; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr:hover { background: var(--hover); }
.table tr.selected { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th button.sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: .25rem; align-items: center; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border-soft); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .6rem .8rem; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; display: inline-flex; gap: .35rem; align-items: center; }
.tabs button[aria-selected='true'] { color: var(--brand-strong); border-bottom-color: var(--brand); }
[data-theme='dark'] .tabs button[aria-selected='true'] { color: var(--brand-accent); }
.tabs .count { font-size: .7rem; background: var(--surface-3); border-radius: 999px; padding: 0 .4rem; }
.seg-tabs { display: flex; gap: .25rem; overflow-x: auto; }
.seg-tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .2rem .65rem; font-size: .8rem; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: .3rem; }
.seg-tabs button[aria-pressed='true'] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11, 20, 26, .5); display: grid; place-items: center; z-index: 200; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column; }
.modal.wide { width: min(820px, 100%); }
.modal-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: .5rem; }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; }
.modal-foot { padding: .75rem 1.25rem; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: .5rem; }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 300; }
.toast { background: var(--text); color: var(--surface); padding: .65rem .9rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: 360px; font-size: .86rem; display: flex; gap: .5rem; align-items: flex-start; animation: toast-in .2s ease-out; }
.toast.ok { border-left: 4px solid var(--brand-accent); }
.toast.bad { border-left: 4px solid var(--bad); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Popover / dropdown ---------- */
.popover { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 100; min-width: 240px; }
.menu { list-style: none; margin: 0; padding: .35rem; }
.menu button, .menu a { display: flex; width: 100%; gap: .5rem; align-items: center; text-align: left; padding: .45rem .6rem; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--hover); }
.notif-item { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: .6rem .8rem; border-bottom: 1px solid var(--border-soft); font-size: .84rem; cursor: pointer; }
.notif-item.unread { background: color-mix(in srgb, var(--brand) 7%, transparent); }
.notif-item:hover { background: var(--hover); }

/* ---------- Lists (inbox) ---------- */
.list-item { display: flex; gap: .65rem; padding: .7rem .75rem; border-bottom: 1px solid var(--border-soft); cursor: pointer; align-items: flex-start; width: 100%; text-align: left; background: none; border-left: 3px solid transparent; border-top: 0; border-right: 0; color: inherit; }
.list-item:hover { background: var(--hover); }
.list-item[aria-current='true'] { background: var(--surface-3); border-left-color: var(--brand); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-top { display: flex; gap: .4rem; align-items: center; }
.list-item .li-name { font-weight: 600; flex: 1; min-width: 0; }
.list-item .li-time { font-size: .72rem; color: var(--muted); }
.list-item .li-preview { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.list-item.unread .li-preview { color: var(--text); font-weight: 600; }
.unread-badge { background: var(--brand-accent); color: #0b141a; min-width: 20px; height: 20px; border-radius: 999px; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; padding: 0 6px; }

/* ---------- Chat bubbles (carried over from the WA app) ---------- */
.thread-head { background: var(--surface); border-bottom: 1px solid var(--border-soft); padding: .55rem .9rem; display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 6%; display: flex; flex-direction: column; gap: .35rem; min-height: 0; }
.msg { max-width: min(560px, 78%); padding: .45rem .65rem .35rem; border-radius: 8px; box-shadow: 0 1px .5px rgba(11,20,26,.13); position: relative; word-wrap: break-word; white-space: pre-wrap; }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.msg.note { background: var(--bubble-note); align-self: center; max-width: 85%; border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent); }
.msg .meta { display: flex; gap: .3rem; justify-content: flex-end; align-items: center; font-size: .68rem; color: var(--muted); margin-top: .15rem; }
.msg .by { font-size: .72rem; font-weight: 600; color: var(--brand-strong); margin-bottom: .1rem; }
[data-theme='dark'] .msg .by { color: var(--brand-accent); }
.msg .tick { width: 16px; height: 11px; }
.msg .tick.read { color: #53bdeb; }
.sys-msg { align-self: center; background: var(--surface); color: var(--muted); font-size: .74rem; padding: .25rem .65rem; border-radius: 8px; box-shadow: var(--shadow); text-align: center; max-width: 85%; }
.day-sep { align-self: center; background: var(--surface); color: var(--muted); font-size: .72rem; padding: .2rem .6rem; border-radius: 8px; margin: .4rem 0; box-shadow: var(--shadow); }
.flow-card { border: 1px solid var(--border-soft); border-radius: 8px; padding: .5rem .6rem; background: var(--surface-2); margin-top: .25rem; white-space: normal; }
.flow-card dl { display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; margin: .3rem 0 0; font-size: .82rem; }
.flow-card dt { color: var(--muted); }
.flow-card dd { margin: 0; font-weight: 600; }
.tpl-btn { display: block; text-align: center; border-top: 1px solid var(--border-soft); padding: .35rem; margin: .35rem -.65rem -.35rem; color: #027eb5; font-size: .85rem; }
.composer { background: var(--surface-2); border-top: 1px solid var(--border-soft); padding: .55rem .75rem; display: flex; flex-direction: column; gap: .4rem; }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; }
.composer .mode-switch button { font-size: .8rem; }
.composer.note-mode textarea { background: var(--bubble-note); }
.window-banner { font-size: .78rem; padding: .35rem .6rem; border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn); display: flex; align-items: center; gap: .4rem; }

/* ---------- Masked values ---------- */
.masked { display: inline-flex; align-items: center; gap: .3rem; font-variant-numeric: tabular-nums; }
.masked .reveal-btn { border: 0; background: none; padding: 2px; cursor: pointer; color: var(--muted); border-radius: 4px; display: inline-grid; }
.masked .reveal-btn:hover { color: var(--brand); background: var(--hover); }
.masked .reveal-btn:disabled { cursor: not-allowed; opacity: .5; }
.masked.revealed { color: var(--brand-strong); }
[data-theme='dark'] .masked.revealed { color: var(--brand-accent); }

/* ---------- Timeline ---------- */
.timeline { display: flex; flex-direction: column; gap: .75rem; }
.tl-item { border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); padding: .75rem .9rem; }
.tl-item.private { background: var(--bubble-note); border-color: color-mix(in srgb, var(--warn) 30%, var(--border-soft)); }
.tl-item.system { background: var(--surface-2); }
.tl-item.customer { border-left: 3px solid var(--ch-whatsapp); }
.tl-item.reply { border-left: 3px solid var(--brand); }
.tl-item.email_dept { border-left: 3px solid var(--info); }
.tl-head { display: flex; gap: .5rem; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: .35rem; flex-wrap: wrap; }
.tl-head strong { color: var(--text); }
.tl-body { white-space: pre-wrap; font-size: .88rem; }

/* ---------- Properties panel ---------- */
.props .field { margin-bottom: .6rem; }
.props-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.sla-card { border-radius: var(--radius); padding: .75rem .9rem; border: 1px solid var(--border-soft); background: var(--surface); }
.sla-row { display: flex; justify-content: space-between; font-size: .8rem; padding: .2rem 0; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: .3rem; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress.warn > span { background: var(--warn); } .progress.bad > span { background: var(--bad); }

/* ---------- Kanban cards ---------- */
.kcard { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: .6rem .7rem; box-shadow: var(--shadow); cursor: grab; }
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .5; }
.kcard:focus-visible { box-shadow: var(--focus); }
.kcard .k-title { font-weight: 600; font-size: .86rem; margin-bottom: .25rem; }
.kcard .k-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .75rem; color: var(--muted); }
.kcard select { font-size: .74rem; padding: .1rem .3rem; min-height: 24px; margin-top: .35rem; width: 100%; }

/* ---------- Charts (single series, one hue; see README "Charts") ---------- */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: .5rem; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.bars .bar span.fill { width: 100%; max-width: 26px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar:hover span.fill, .bars .bar:focus-visible span.fill { background: var(--brand-strong); }
.bars .bar .x { font-size: .65rem; color: var(--muted); margin-top: .25rem; height: 1rem; }
.hbars { display: flex; flex-direction: column; gap: .5rem; }
.hbar { display: grid; grid-template-columns: 150px minmax(0, 1fr) 44px; gap: .5rem; align-items: center; font-size: .82rem; }
.hbar .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--brand); border-radius: 0 4px 4px 0; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.chart-tip { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); font-size: .72rem; padding: .2rem .45rem; border-radius: 4px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 2; }
.bars .bar:hover .chart-tip, .bars .bar:focus-visible .chart-tip { opacity: 1; }

/* ---------- Template preview (WhatsApp phone) ---------- */
.phone { width: 300px; max-width: 100%; border-radius: 22px; border: 8px solid #1f2c33; background-color: var(--chat-bg); background-image: var(--doodle); background-size: 300px auto; padding: 1rem .6rem; min-height: 360px; }
.phone .msg { max-width: 100%; }
.tpl-header { font-weight: 700; margin-bottom: .25rem; }
.tpl-media { height: 120px; border-radius: 6px; background: linear-gradient(135deg, #b8d8cf, #e6efe9); display: grid; place-items: center; color: #4a6b60; margin-bottom: .35rem; font-size: .8rem; }
.tpl-footer { font-size: .72rem; color: var(--muted); margin-top: .25rem; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty svg { margin: 0 auto .5rem; width: 40px; height: 40px; opacity: .5; }
.callout { border: 1px solid var(--border-soft); background: var(--surface-2); border-radius: var(--radius); padding: .7rem .9rem; font-size: .85rem; }
.callout.info { background: var(--info-bg); border-color: transparent; color: var(--info); }
.callout.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.kbd { font-family: var(--font-mono); font-size: .75rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3rem; background: var(--surface-2); }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .75rem; font-size: .86rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; }
.rule-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .5rem; margin-bottom: .5rem; }
@media (max-width: 760px) { .rule-row { grid-template-columns: 1fr; } }

/* Requester combobox */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% - 1.4rem); max-height: 15rem; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 8px); box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: .25rem; }
.combo-list[hidden] { display: none; }
.combo-opt { display: block; width: 100%; text-align: left; padding: .45rem .6rem; border: 0; background: transparent; border-radius: 6px; cursor: pointer; font: inherit; color: inherit; }
.combo-opt:hover, .combo-opt:focus-visible { background: var(--surface-2); }
.combo-add { color: var(--brand, #0b7a5b); font-weight: 600; }
