:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #1c1f26;
  --muted: #6b7280;
  --primary: #0754a5;
  --primary-soft: #e6eef8;
  --danger: #c0362c;
  --radius: 10px;
  --open: #0754a5;
  --in_progress: #b7791f;
  --resolved: #2f855a;
  --closed: #6b7280;
  --urgent: #c0362c;
  --high: #dd6b20;
  --medium: #0754a5;
  --low: #6b7280;
  --pending: #dd6b20;
  --confirmed: #2f855a;
  --declined: #6b7280;
  --cancelled: #6b7280;
  --attended: #0754a5;
  --no_show: #c0362c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
body > main { flex: 1; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; }
.site-footer { padding: 16px; text-align: center; font-size: 12px; color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { flex: none; border-radius: 50%; }
.brand-name { font-weight: 700; font-size: 18px; line-height: 1.2; white-space: nowrap; }
.brand-name > span { color: var(--primary); }
.brand-name > .brand-sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.brand-by { font-size: 12px; color: var(--muted); }
.topbar nav { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.badge-mode { white-space: nowrap; font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: #c4c8d0; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; text-align: center; }
.login-card h2 { margin: 0 0 4px; }
.login-card label { text-align: left; }
.login-logo { display: block; margin: 0 auto 14px; border-radius: 50%; border: 3px solid var(--primary); }
.login-error { min-height: 1.2em; margin: 10px 0; color: var(--danger); }
.login-card .btn-primary { width: 100%; padding: 10px 14px; }

/* ---------- Percakapan ---------- */
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

/* ---------- Dashboard ---------- */
.dash { width: 100%; padding: 16px 20px; max-width: 1400px; margin: 0 auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tab { padding: 8px 14px; border-radius: 8px; cursor: pointer; border: none; background: transparent; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { padding: 10px 12px; text-align: left; font: inherit; color: inherit; width: 100%; }
.stat .label { font-size: 12px; color: var(--muted); line-height: 1.3; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: #b9c3e0; }
.stat.alert { border-left-width: 3px; }
.stat.alert .label { color: var(--text); font-weight: 600; }
.stat.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); background: var(--primary-soft); }
.toolbar { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 8px; }
.toolbar .btn { white-space: nowrap; }
.quick-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 5px 12px; border-radius: 99px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: #b9c3e0; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-bottom: 8px; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 28px; margin-bottom: 10px; font-size: 13px; }
.result-count { color: var(--muted); margin-right: 4px; }
.result-count strong { color: var(--text); }
.filter-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--primary-soft); color: var(--primary); border-radius: 99px; padding: 3px 4px 3px 10px; }
.filter-chip button { border: none; background: transparent; color: inherit; cursor: pointer; padding: 0 6px; font-size: 12px; line-height: 1.6; border-radius: 99px; }
.filter-chip button:hover { background: rgba(7, 84, 165, .15); }
.link-btn { border: none; background: none; color: var(--primary); cursor: pointer; text-decoration: underline; font-size: 13px; padding: 2px 4px; }
.group-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 2px 0; }
.group-label:first-child { margin-top: 0; }
.back-btn { display: none; }
.btn-danger { color: var(--danger); border-color: #f0c4c0; }
.btn-danger:hover { border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.archived-banner { background: #fff7e6; border: 1px solid #f3d9a4; color: #8a5a00; padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; }
.danger-zone { border: 1px solid #f0c4c0; border-radius: 8px; padding: 12px; }
.danger-zone .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm-box { margin-top: 10px; background: #fdf0ef; border-radius: 8px; padding: 12px; }
.confirm-box label { display: flex; gap: 8px; align-items: center; color: var(--text); margin: 8px 0; }
.confirm-box input[type=checkbox] { width: auto; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px; align-items: start; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { cursor: pointer; padding: 12px 14px; }
.item:hover { border-color: #b9c3e0; }
.item.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.item .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.item .title { font-weight: 600; margin: 4px 0; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; margin-right: 4px; }
.detail h2 { margin: 0 0 4px; font-size: 18px; }
.detail .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.detail section { margin-top: 18px; }
.detail h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.desc { white-space: pre-wrap; background: var(--bg); padding: 10px 12px; border-radius: 8px; }
.note { border-left: 3px solid var(--primary); padding: 6px 10px; margin-bottom: 8px; background: var(--bg); border-radius: 0 8px 8px 0; }
.note .meta { font-size: 12px; color: var(--muted); }
.transcript { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; background: var(--bg); padding: 10px; border-radius: 8px; }
.transcript .msg { max-width: 90%; font-size: 14px; }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; }

@media (max-width: 900px) {
  .dash { padding: 12px; overflow-x: clip; }
  .split { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  /* Statistik jadi satu baris yang bisa digeser, supaya tiket langsung terlihat di layar pertama. */
  .stats { display: flex; overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: 12px; margin: 0 -12px 10px; padding: 0 12px 4px; }
  .stat { flex: 0 0 auto; width: auto; min-width: 112px; max-width: 150px; scroll-snap-align: start; }
  .stat .n { font-size: 20px; }
  .quick-filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 8px; padding: 0 12px 2px; }
  .toolbar { grid-template-columns: 1fr auto; }
  .toolbar #export-tickets { display: none; }
  /* Detail tampil penuh menggantikan list; panel kosong disembunyikan. */
  .split > .detail { display: none; }
  .show-detail .split > .detail { display: block; }
  .show-detail .split > .list, .show-detail .stats, .show-detail .toolbar, .show-detail .quick-filters,
  .show-detail .filters, .show-detail .active-filters { display: none; }
  .back-btn { display: inline-block; margin-bottom: 12px; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
}

@media (max-width: 600px) {
  .topbar { padding: 10px 12px; }
  .brand-sub, #telegram-link { display: none; }
  .brand { gap: 8px; }
  .brand-logo { width: 30px; height: 30px; }
  .brand-name { font-size: 16px; }
  .brand-by { font-size: 11px; }
  .topbar nav { gap: 6px; min-width: 0; }
  #logout { padding: 6px 10px; }
  #agent-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail .grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  #agent-name { display: none; }
}

/* ---------- Reservasi, keluhan, SLA, balasan agent ---------- */
.item.overdue { border-left: 3px solid var(--urgent); }
.item .visit { margin: 2px 0 6px; color: var(--text); }
.age { color: var(--muted); }
.age.late { color: var(--urgent); font-weight: 600; }
.badge-new { font-size: 12px; font-weight: 600; color: #fff; background: var(--primary); padding: 1px 7px; border-radius: 99px; }
.overdue-banner { background: #fdf0ef; border: 1px solid #f0c4c0; color: var(--danger); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; }
.form-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
label.inline { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--text); }
label.inline input { width: auto; }
.note.reply { border-left-color: #229ed9; }
.note.system { border-left-color: var(--closed); color: var(--muted); font-size: 13px; }
.msg.agent { background: #e7f5fc; border-color: #b3dff3; }
.msg .sender { font-size: 11px; font-weight: 600; color: #1b7fb0; margin-bottom: 2px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }

/* ---------- Service desk: reservasi, handoff, laporan, template ---------- */
.rsv-panel { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--bg); }
.rsv-panel h3 { display: flex; gap: 8px; align-items: center; }
.rsv-panel .actions, #rsv-form .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
#rsv-form { margin-top: 6px; }
.handoff-banner, .handoff-hint { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; }
.handoff-banner { background: #e7f5fc; border: 1px solid #b3dff3; color: #155e80; font-size: 14px; }
.handoff-hint { background: var(--bg); }
.badge-handoff { font-size: 12px; font-weight: 600; color: #155e80; background: #e7f5fc; padding: 1px 7px; border-radius: 99px; }
#reply-template { margin-bottom: 8px; }
.msg .time { font-size: 10px; opacity: .6; text-align: right; margin-top: 2px; }
.history { line-height: 1.9; }
.report-actions { display: flex; gap: 8px; align-items: center; }

.report-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.report-head h2 { margin: 0; font-size: 18px; }
.report-head select { width: auto; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 12px; }
.report-card { margin-bottom: 12px; }
.report-grid .report-card { margin-bottom: 0; }
.report-card h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 12px; }
.bar-list { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 140px) 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; }
.bar { display: block; height: 100%; min-width: 2px; background: var(--primary); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.col-chart { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--border); }
.col-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.col-slot:hover .col { filter: brightness(1.2); }
.col { display: block; width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; }
.col-axis { display: flex; justify-content: space-between; margin-top: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.table td { font-variant-numeric: tabular-nums; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--text); color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
#template-list > .btn { align-self: flex-start; }

/* ---------- Inbox customer ---------- */
.toolbar-single { grid-template-columns: 1fr; }
.tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 99px; background: var(--urgent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.inbox-item .top .title { margin: 0; color: var(--text); font-size: 15px; }
.inbox-item .preview { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 6px; }
.inbox-item.unread { border-left: 3px solid var(--primary); }
.inbox-item.unread .preview { color: var(--text); font-weight: 500; }
.inbox-item .meta { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.conv-sep { align-self: center; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 2px 10px; margin: 6px 0; }
.msg.auto { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 13px; }
.history-row { margin-bottom: 4px; }
.manual-ticket { margin-top: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.template-hint { margin: -4px 0 8px; }
#c-reply-template { margin-bottom: 8px; }
