:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #1d2530;
  --muted: #68727f;
  --accent: #1f6f5c;
  --accent-dark: #175748;
  --accent-soft: #e4f2ee;
  --nav: #16302a;
  --nav-text: #cfe0db;
  --open: #c2410c;
  --open-bg: #ffedd5;
  --pending: #1d4ed8;
  --pending-bg: #dbeafe;
  --solved: #4b5563;
  --solved-bg: #e5e7eb;
  --note: #fff8db;
  --note-line: #ecd98a;
  --danger: #b42318;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  padding: 7px 12px; line-height: 1.2;
}
.btn:hover { background: #f1f3f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }

/* Login / configuração inicial */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: 100%; max-width: 380px; }
.card h1 { font-size: 20px; margin: 0 0 4px; }
.card p { color: var(--muted); margin: 0 0 12px; }
.card .btn { width: 100%; margin-top: 16px; padding: 10px; }
.error { color: var(--danger); margin-top: 10px; min-height: 18px; }

/* Estrutura */
.layout { display: grid; grid-template-columns: 210px 350px 1fr; height: 100vh; }
.nav { background: var(--nav); color: var(--nav-text); display: flex; flex-direction: column; padding: 14px 10px; min-width: 0; }
.brand { color: #fff; font-weight: 700; font-size: 15px; padding: 2px 8px 2px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--nav-text); overflow: hidden; text-overflow: ellipsis; }
.nav .new { margin: 14px 4px 12px; background: #fff; color: var(--nav); border: 0; border-radius: 6px; padding: 8px; font-weight: 600; }
.nav-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: none; border: 0; color: inherit; text-align: left; padding: 8px 10px; border-radius: 6px;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-item .count { font-size: 12px; background: rgba(255,255,255,.14); border-radius: 10px; padding: 1px 7px; }
.nav hr { border: 0; border-top: 1px solid rgba(255,255,255,.12); margin: 10px 4px; width: calc(100% - 8px); }
.nav .spacer { flex: 1; }
.nav .who { font-size: 12px; padding: 6px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-status { font-size: 11px; padding: 6px 10px; line-height: 1.35; }
.mail-status.bad { color: #ffc9c0; }

.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0 0 8px; font-size: 15px; }
.list-body { overflow-y: auto; flex: 1; }
.row { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
.row:hover { background: #f7f8fa; }
.row.active { background: var(--accent-soft); }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--open); margin-right: 6px; }
.row .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subject { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .snippet { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 32px 16px; text-align: center; }

.badge { font-size: 11px; font-weight: 700; border-radius: 4px; padding: 2px 6px; }
.badge.open { color: var(--open); background: var(--open-bg); }
.badge.pending { color: var(--pending); background: var(--pending-bg); }
.badge.solved { color: var(--solved); background: var(--solved-bg); }

.badge.dept { color: #5b21b6; background: #ede9fe; font-weight: 600; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.t-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 12px 18px; }
.t-head h1 { font-size: 17px; margin: 0 0 4px; overflow-wrap: anywhere; }
.t-head .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.t-head .controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.t-head .controls label { margin: 0; display: flex; align-items: center; gap: 6px; }
.t-head .controls select { width: auto; }
.back { display: none; }
.thread { flex: 1; overflow-y: auto; padding: 16px 18px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; max-width: 860px; }
.msg.out { border-left: 3px solid var(--accent); }
.msg.note { background: var(--note); border-color: var(--note-line); }
.msg-head { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.msg.note .msg-head { border-color: var(--note-line); }
.msg-head .tag { color: var(--muted); font-weight: 400; }
.msg-head time { color: var(--muted); font-size: 12px; }
.msg-body { padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg iframe { width: 100%; border: 0; display: block; min-height: 60px; }
.atts { padding: 0 12px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.att { font-size: 12px; border: 1px solid var(--line); border-radius: 5px; padding: 4px 8px; text-decoration: none; background: #fff; color: var(--text); }
.others { max-width: 860px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.others button { background: none; border: 0; color: var(--accent); padding: 0; text-decoration: underline; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 18px 14px; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 5px 8px; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--accent); border-color: var(--accent); }
.composer.note-mode textarea { background: var(--note); border-color: var(--note-line); }
.composer textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.c-bar { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.c-bar select { width: auto; max-width: 270px; }
.c-bar .grow { flex: 1; }
.files { font-size: 12px; color: var(--muted); margin-top: 6px; }
.files span { margin-right: 10px; }
.files button { border: 0; background: none; color: var(--danger); padding: 0 2px; }

.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

/* Configurações */
.settings { overflow-y: auto; padding: 20px; grid-column: 2 / 4; }
.settings section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 0 0 16px; max-width: 820px; }
.settings h2 { font-size: 16px; margin: 0 0 4px; }
.settings .hint { color: var(--muted); margin: 0 0 10px; font-size: 13px; }
.settings table { width: 100%; border-collapse: collapse; }
.settings td, .settings th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.settings th { font-size: 12px; color: var(--muted); }
.settings td.actions { text-align: right; white-space: nowrap; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; margin-top: 10px; }

/* Modal e avisos */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--panel); border-radius: 10px; padding: 20px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin: 0 0 6px; font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2530; color: #fff; padding: 9px 14px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 180px 290px 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; gap: 2px; }
  .nav .brand small, .nav hr, .nav .spacer, .mail-status, .nav .who { display: none; }
  .nav .new { margin: 0 6px; padding: 6px 10px; }
  .nav-item { width: auto; padding: 6px 8px; gap: 6px; }
  .layout.has-ticket .list, .layout:not(.has-ticket) .main { display: none; }
  .settings { grid-column: 1; }
  .back { display: inline-block; margin-bottom: 8px; }
}
