[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8; --card: #fff; --text: #1f2328; --muted: #6b7280; --border: #e5e7eb;
  --primary: #2563eb; --danger: #dc2626; --warn: #d97706; --ok: #059669; --note: #fef9c3;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
.muted { color: var(--muted); font-size: 13px; }
.req { color: var(--danger); }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: #fff; padding: 8px 14px; }
button.primary, form button[type=submit] { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
button:disabled { opacity: .6; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
textarea { resize: vertical; }
label { display: block; margin: 0 0 14px; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 5px; font-weight: 400; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 14px; }
label.check input { width: auto; margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.error { color: var(--danger); min-height: 1.2em; }

/* Form */
.form-page .card { max-width: 620px; margin: 32px auto; background: var(--card); padding: 28px; border-radius: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.form-page h1 { margin: 0 0 4px; font-size: 22px; }
.form-page form { margin-top: 18px; }
.form-page form button[type=submit] { width: 100%; padding: 12px; }
body.embed { background: #fff; }
body.embed .card { margin: 0; box-shadow: none; padding: 22px 20px; }
#captcha { margin: 8px 0; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } .form-page .card { margin: 0; border-radius: 0; padding: 20px 16px; } }

/* Admin */
.admin header { display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: #111827; color: #fff; }
.admin header h1 { font-size: 17px; margin: 0; flex: 1; }
.admin header button { background: transparent; color: #fff; border-color: #374151; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: #1f2937; padding: 3px 10px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.stat.hot { background: var(--danger); }
.layout { display: grid; grid-template-columns: 420px 1fr; height: calc(100vh - 52px); }
.list { border-right: 1px solid var(--border); overflow: auto; background: #fff; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 1; }
.filters input { grid-column: 1 / -1; }
.filters select, .filters input { padding: 6px 8px; font-size: 13px; }
.item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:hover, .item.active { background: #eef2ff; }
.item .top { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.item .subj { font-weight: 600; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.overdue { border-left: 4px solid var(--danger); }
.item.awaiting { border-left: 4px solid var(--warn); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge.new { background: #dbeafe; color: #1e40af; } .badge.open { background: #fef3c7; color: #92400e; }
.badge.waiting { background: #e0e7ff; color: #3730a3; } .badge.closed { background: #d1fae5; color: #065f46; }
.badge.app { background: #f3f4f6; } .badge.cat-affiliate { background: #fce7f3; color: #9d174d; }
.detail { overflow: auto; padding: 18px 24px; }
.detail h2 { margin: 0 0 6px; font-size: 19px; }
.meta { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.msg { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; white-space: pre-wrap; word-wrap: break-word; }
.msg.agent { background: #eff6ff; border-color: #bfdbfe; margin-left: 40px; }
.msg.note { background: var(--note); border-color: #fde68a; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; white-space: normal; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; white-space: normal; }
.atts a img { max-width: 160px; max-height: 120px; border-radius: 6px; border: 1px solid var(--border); }
.composer { position: sticky; bottom: 0; background: var(--bg); padding-top: 10px; }
.ai { border-color: #c7d2fe; background: #eef2ff; color: #3730a3; font-weight: 600; }
.tablewrap { margin-bottom: 20px; }
.creditbar { background: #fef2f2; color: #991b1b; border-bottom: 1px solid #fecaca; padding: 10px 16px; font-size: 14px; }
.creditbar a { color: #991b1b; font-weight: 600; }
.creditform { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 12px; align-items: end; max-width: 720px; margin-top: 10px; }
.appform { display: grid; grid-template-columns: 2fr 2fr 1fr auto; gap: 12px; align-items: end; }
.composer .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.composer .actions .spacer { flex: 1; }
.empty { color: var(--muted); padding: 40px; text-align: center; }
.login { max-width: 360px; margin: 15vh auto; background: #fff; padding: 28px; border-radius: 14px; }
.back { display: none; }
@media (max-width: 860px) {
  html, body.admin { overflow-x: hidden; }
  body.admin { background: var(--bg); }
  /* 16px input mengelak iPhone zoom automatik */
  .admin input, .admin select, .admin textarea, .filters select, .filters input { font-size: 16px; }
  .admin header { gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
  .admin header h1 { flex: 1; font-size: 18px; }
  .hbtn .lbl { display: none; }
  .hbtn { width: 40px; height: 40px; padding: 0; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; }
  .hbtn.on { border-color: var(--ok); }
  .stats { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .stats::-webkit-scrollbar { display: none; }
  .stat { white-space: nowrap; padding: 5px 12px; font-size: 13px; }
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; min-height: calc(100vh - 110px); }
  .layout.show-detail .list { display: none; }
  .layout:not(.show-detail) .detail { display: none; }
  .list, .detail { overflow: visible; min-width: 0; border: 0; }
  .filters { position: static; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 10px 12px; }
  .filters select, .filters input { padding: 9px 10px; }
  .item { padding: 12px 14px; overflow: hidden; }
  .item .subj { font-size: 15px; }
  .detail { padding: 12px 12px 0; }
  .detail h2 { font-size: 18px; overflow-wrap: anywhere; }
  .meta { overflow-wrap: anywhere; }
  .msg { padding: 11px 12px; overflow-wrap: anywhere; }
  .msg.agent { margin-left: 16px; }
  .atts a img { max-width: 120px; max-height: 100px; }
  .back { display: inline-block; margin-bottom: 10px; padding: 8px 14px; }
  .composer { margin: 0 -12px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: #fff; box-shadow: 0 -4px 12px rgba(0,0,0,.05); }
  .composer textarea { min-height: 110px; }
  .composer .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .composer .actions button { min-height: 44px; padding: 8px 10px; }
  .composer .actions .ai, .composer .actions select { grid-column: 1 / -1; }
  .composer .actions .spacer { display: none; }
  .composer .actions select { width: 100% !important; min-height: 44px; }
  .tablewrap { overflow-x: auto; }
  .appform, .creditform { grid-template-columns: 1fr !important; }
  .login { margin: 10vh 16px; }
  .login input { font-size: 16px; }
  .login button { width: 100%; min-height: 44px; }
}
