:root {
  --bg: #F3F6F8;
  --surface: #FFFFFF;
  --surface-alt: #EAEEF2;
  --border: #DCE2E7;
  --ink: #16212C;
  --ink-soft: #56636F;
  --navy: #10283F;
  --accent: #F5821F;
  --accent-ink: #FFFFFF;
  --teal: #163A5C;
  --teal-soft: #E4EAF0;
  --amber: #B45309;
  --amber-soft: #FCE7D2;
  --green: #2F7A4D;
  --green-soft: #E3EFE6;
  --violet: #5B3FA6;
  --violet-soft: #ECE6F8;
  --note: #FFF7E0;
  --note-border: #F0D68A;
  --mine: #E4EAF0;
  --shadow: 0 1px 2px rgba(16,24,32,0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0F1B27; --surface: #16283A; --surface-alt: #1C2F42; --border: #26384A;
    --ink: #EEF3F6; --ink-soft: #9FB0BE; --navy: #0B1D2E; --accent: #FF9A44; --accent-ink: #1B1007;
    --teal: #6FA8DC; --teal-soft: #1E3550; --amber: #FFB46B; --amber-soft: #3A2A18;
    --green: #6FC28E; --green-soft: #1F3126; --violet: #B9A4F0; --violet-soft: #2B2445;
    --note: #3A3218; --note-border: #6B5A23; --mine: #1E3550; --shadow: 0 1px 2px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1B27; --surface: #16283A; --surface-alt: #1C2F42; --border: #26384A;
  --ink: #EEF3F6; --ink-soft: #9FB0BE; --navy: #0B1D2E; --accent: #FF9A44; --accent-ink: #1B1007;
  --teal: #6FA8DC; --teal-soft: #1E3550; --amber: #FFB46B; --amber-soft: #3A2A18;
  --green: #6FC28E; --green-soft: #1F3126; --violet: #B9A4F0; --violet-soft: #2B2445;
  --note: #3A3218; --note-border: #6B5A23; --mine: #1E3550; --shadow: 0 1px 2px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--teal); }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }

/* Barra superior */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 700; letter-spacing: .2px; }
.topbar .brand small { display: block; font-weight: 400; opacity: .7; font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar a, .topbar button.link { color: #fff; opacity: .85; text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.topbar a:hover, .topbar button.link:hover { opacity: 1; text-decoration: underline; }

.container { max-width: 820px; margin: 0 auto; padding: 20px 16px 48px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* Botões e campos */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 9px 14px; font: 600 14px/1.2 inherit; font-family: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-alt); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--teal); }
.btn:disabled { opacity: .6; cursor: default; }
label.field { display: block; font-weight: 600; font-size: 14px; }
label.field > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: var(--surface); color: var(--ink); font: 15px/1.4 inherit; font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.error { background: var(--amber-soft); color: var(--amber); border-radius: 8px; padding: 9px 12px; font-size: 14px; }
.notice { background: var(--teal-soft); color: var(--teal); border-radius: 8px; padding: 9px 12px; font-size: 14px; word-break: break-all; }

/* Selos */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.pill.gray { background: var(--surface-alt); color: var(--ink-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }

/* Lista de chamados */
.tickets { list-style: none; margin: 0; padding: 0; }
.tickets li + li { border-top: 1px solid var(--border); }
.ticket-row { display: block; padding: 13px 16px; color: inherit; text-decoration: none; cursor: pointer; }
.ticket-row:hover { background: var(--surface-alt); }
.ticket-row.active { background: var(--teal-soft); }
.ticket-row .subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-row .meta { font-size: 13px; color: var(--ink-soft); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.empty { padding: 32px 16px; text-align: center; color: var(--ink-soft); }

/* Conversa */
.thread { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.msg { max-width: 82%; border-radius: 12px; padding: 10px 13px; background: var(--surface-alt); align-self: flex-start; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg.internal { background: var(--note); border: 1px dashed var(--note-border); align-self: stretch; max-width: none; }
.msg.system { align-self: center; background: transparent; color: var(--ink-soft); font-size: 13px; padding: 2px 8px; text-align: center; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-bottom: 3px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .files { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg .files a { font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; text-decoration: none; }
.composer { border-top: 1px solid var(--border); padding: 12px 16px; }
.composer textarea { min-height: 80px; }

/* Login */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { font-weight: 700; font-size: 20px; color: var(--ink); }

/* Painel de atendimento */
.desk { display: grid; grid-template-columns: 230px 380px 1fr; height: calc(100vh - 52px); }
.desk > * { min-height: 0; }
.side { border-right: 1px solid var(--border); background: var(--surface); overflow: auto; padding: 12px 0; }
.side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); padding: 10px 16px 4px; }
.side button { display: flex; width: 100%; justify-content: space-between; border: 0; background: none; padding: 7px 16px; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.side button:hover { background: var(--surface-alt); }
.side button.active { background: var(--teal-soft); color: var(--teal); font-weight: 700; }
.side .count { color: var(--ink-soft); font-size: 13px; }
.listpane { border-right: 1px solid var(--border); overflow: auto; background: var(--surface); }
.listpane .filters { padding: 10px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; display: grid; gap: 8px; }
.detail { overflow: auto; display: flex; flex-direction: column; }
.detail-head { padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.detail-head select { width: auto; padding: 5px 8px; font-size: 14px; }
.detail-body { display: grid; grid-template-columns: 1fr 280px; flex: 1; min-height: 0; }
.convo { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.convo .thread { flex: 1; }
.profile { border-left: 1px solid var(--border); padding: 14px 16px; overflow: auto; background: var(--surface); font-size: 14px; }
.profile h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); }
.profile .appbox { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.profile dl { margin: 4px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 13px; }
.profile dt { color: var(--ink-soft); }
.profile dd { margin: 0; overflow-wrap: anywhere; }
.page { padding: 20px; overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); }
.back-link { display: none; }

@media (max-width: 1100px) {
  .detail-body { grid-template-columns: 1fr; }
  .profile { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 860px) {
  .desk { grid-template-columns: 1fr; height: auto; }
  .side { display: flex; overflow-x: auto; padding: 0; border-right: 0; border-bottom: 1px solid var(--border); }
  .side h3 { display: none; }
  .side button { width: auto; white-space: nowrap; gap: 6px; }
  .desk.has-ticket .listpane { display: none; }
  .desk:not(.has-ticket) .detail { display: none; }
  .back-link { display: inline-flex; }
  .msg { max-width: 92%; }
}
