:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1c1e21;
  --dim: #6b7280;
  --border: #e3e6eb;
  --accent: #5856d6;
  --accent-bg: #f0eefe;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; font-size: 16px; color: var(--text); }
.brand span { color: var(--accent); font-weight: 600; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--text); font-weight: 600; }
.me { display: flex; gap: 12px; align-items: center; }
.who { color: var(--dim); font-size: 13px; }

/* Buttons */
.btn-primary { background: var(--accent); color: #fff; border: 0; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: #4744c4; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); padding: 7px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; }

/* Container */
.container { max-width: 1280px; margin: 20px auto; padding: 0 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }

/* KPIs */
.kpis { display: flex; gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px; min-width: 80px; text-align: center; color: var(--text); }
.kpi b { display: block; font-size: 20px; font-weight: 700; }
.kpi span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.kpi:hover { border-color: var(--accent); text-decoration: none; }

/* Filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; background: #fff; padding: 10px; border-radius: var(--radius); border: 1px solid var(--border); align-items: center; }
.filters input[type=search], .filters select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); font: inherit; background: #fff; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }

/* Table */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.tbl th { background: #fafbfc; color: var(--dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: #fafbfc; }
.tbl tbody tr.unread { background: #fffaf0; }
.tbl tbody tr.unread:hover { background: #fff3e0; }
.tbl td.empty { text-align: center; color: var(--dim); padding: 30px; }
.tbl td.nr { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; color: var(--accent); }
.tbl td.subj { font-weight: 600; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl.small th, .tbl.small td { padding: 4px 8px; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }

/* Ticket detail */
.back { display: inline-block; color: var(--accent); margin-bottom: 12px; }
.ticket-head { display: grid; grid-template-columns: 1fr 280px; gap: 20px; background: #fff; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 14px; }
.ticket-head h1 { margin: 4px 0 8px; font-size: 18px; }
.t-nr { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--accent); }
.t-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.t-autor { color: var(--dim); font-size: 13px; }
.dim { color: var(--dim); }
.t-actions { display: flex; flex-direction: column; gap: 8px; }
.t-actions .row select { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: #fff; }

/* Thread */
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.msg { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.msg header { display: flex; gap: 10px; font-size: 12px; margin-bottom: 6px; }
.msg header b { font-size: 13px; color: var(--text); }
.msg .body { white-space: pre-wrap; }
.msg-agent { background: var(--accent-bg); border-color: #d8d3f9; }
.msg-internal { background: #fff8d6; border-color: #f1e2a3; }
.tag-internal { background: #ffe07a; color: #6b5400; padding: 1px 6px; border-radius: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: #fff; border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px; color: var(--text); cursor: pointer; font-family: inherit; }
.att-chip:hover { border-color: var(--accent); background: var(--accent-bg); }
.att-modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 9999; display: flex; flex-direction: column; padding: 14px; backdrop-filter: blur(4px); }
.att-modal-bar { display: flex; align-items: center; gap: 10px; color: #fff; margin-bottom: 10px; font-size: 13px; }
.att-modal-bar .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-modal-bar a, .att-modal-bar button { color: #fff; padding: 6px 10px; background: rgba(255,255,255,.15); border-radius: 6px; text-decoration: none; font-size: 12px; border: 0; cursor: pointer; }
.att-modal-body { flex: 1; overflow: auto; background: rgba(255,255,255,.05); border-radius: 10px; padding: 10px; display: flex; align-items: center; justify-content: center; }
.att-modal-body img { max-width: 100%; max-height: 100%; display: block; border-radius: 6px; }
.att-modal-body iframe { width: 100%; height: 100%; border: 0; border-radius: 6px; background: #fff; }

/* Reply */
.reply { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.reply textarea { width: 100%; min-height: 120px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); font: inherit; resize: vertical; }
.reply-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

/* Audit */
.audit { margin-top: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.audit summary { cursor: pointer; color: var(--dim); font-weight: 600; }

/* Login */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; padding: 30px; border-radius: var(--radius); border: 1px solid var(--border); width: 360px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.05); }
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card h1 span { color: var(--accent); }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); font-weight: 600; }
.login-card input { padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); font: inherit; }
.login-err { background: #fde2e1; color: #8a1f1c; padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* Admin */
.admin-block { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.admin-block h2 { margin: 0 0 10px; font-size: 16px; }
.admin-form { margin-top: 12px; padding: 10px; background: #fafbfc; border-radius: 8px; }
.admin-form summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 10px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); font-weight: 600; }
.form-grid input, .form-grid select { padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border); font: inherit; background: #fff; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.ok { color: #30a060; font-weight: 600; }
.muted { color: var(--dim); }
.flash { background: var(--accent-bg); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
.flash code { background: rgba(0,0,0,.05); padding: 2px 6px; border-radius: 4px; display: inline-block; }
