:root {
  --blue: #0866ff; --blue-50: #e8f0ff; --green: #0f9d63; --green-50: #e4f7ee; --amber: #b26a00; --amber-50: #fff3d6;
  --red: #c62828; --red-50: #fde7e7; --gray-50: #f6f7fb; --gray-100: #eceef3; --gray-200: #dfe2ea; --gray-500: #6b7280;
  --text: #111827; --radius: 12px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--text); background: var(--gray-50); font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.hidden { display: none !important; }

/* Layout */
.shell { display: flex; height: 100vh; height: 100dvh; }
.side { width: 230px; background: #fff; border-right: 1px solid var(--gray-200); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 8px 16px; }
.brand img { width: 34px; height: 34px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: #374151; font-weight: 500; }
.nav a.active { background: var(--blue-50); color: var(--blue); font-weight: 700; }
.nav a .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 7px; }
.side .me { margin-top: auto; font-size: 13px; color: var(--gray-500); padding: 8px 12px; }
.main { flex: 1; min-width: 0; overflow: auto; }
.page { padding: 24px 28px; max-width: 1100px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.sub { color: var(--gray-500); margin: 0 0 20px; }

/* Mobile */
.bottomnav { display: none; }
@media (max-width: 800px) {
  .side { display: none; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--gray-200); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; text-align: center; padding: 10px 4px; font-size: 12px; text-decoration: none; color: #4b5563; position: relative; }
  .bottomnav a.active { color: var(--blue); font-weight: 700; }
  .bottomnav .count { position: absolute; top: 4px; right: 18%; background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; }
  .main { padding-bottom: 64px; }
  .page { padding: 16px; }
}

/* Controls */
a.btn { text-decoration: none; display: inline-block; }
.btn { border: 1px solid var(--gray-200); background: #fff; padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--gray-50); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { filter: brightness(.95); }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.amber { background: #ffb300; border-color: #ffb300; color: #1f2937; }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--gray-200); border-radius: 10px; padding: 9px 12px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
label.f { display: block; font-size: 13px; font-weight: 600; color: #4b5563; margin: 14px 0 6px; }
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card .hint { color: var(--gray-500); font-size: 13px; margin: 0 0 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--gray-500); font-size: 13px; }
.notice { background: var(--amber-50); border: 1px solid #f5d48a; color: #7a4a00; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.notice.ok { background: var(--green-50); border-color: #a7e3c6; color: #0b6b44; }
code.copy { background: var(--gray-100); padding: 3px 8px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* Toggle */
.toggle { position: relative; width: 46px; height: 26px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; background: #cfd4de; border-radius: 99px; cursor: pointer; transition: .15s; }
.toggle span::after { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.toggle input:checked + span { background: var(--green); }
.toggle input:checked + span::after { transform: translateX(20px); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-kumpleto, .b-may_contact { background: var(--green-50); color: var(--green); }
.b-interesado { background: var(--amber-50); color: var(--amber); }
.b-nagtatanong { background: var(--gray-100); color: var(--gray-500); }
.b-hindi_pasok { background: var(--red-50); color: var(--red); }
.b-takeover { background: #ffe9c2; color: #8a5300; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0c1226, #14204a); }
.login .box { background: #fff; width: 100%; max-width: 380px; padding: 28px; border-radius: 18px; }
.login img { width: 56px; height: 56px; }
.login h1 { margin-top: 10px; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 360px 1fr 300px; height: 100vh; height: 100dvh; }
.inbox .list { border-right: 1px solid var(--gray-200); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.inbox .list .head { padding: 14px 14px 8px; border-bottom: 1px solid var(--gray-100); }
.inbox .list .head input[type=search] { min-width: 0; }
.tabs { display: flex; gap: 4px; margin: 10px 0 4px; }
.tabs button { border: 0; background: none; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--gray-500); font-size: 14px; }
.tabs button.active { background: var(--blue-50); color: var(--blue); }
.tabs button .n { font-size: 12px; opacity: .8; margin-left: 3px; }
.items { overflow: auto; flex: 1; }
.item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--gray-100); cursor: pointer; position: relative; }
.item:hover { background: var(--gray-50); }
.item.active { background: var(--blue-50); }
.item.lead { box-shadow: inset 4px 0 0 var(--green); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #c9d2e3; flex: none; object-fit: cover; display: grid; place-items: center; color: #fff; font-weight: 700; }
.item .t { flex: 1; min-width: 0; }
.item .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .prev { color: var(--gray-500); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .meta { font-size: 11px; color: var(--gray-500); margin-top: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item .unread { position: absolute; right: 12px; top: 14px; background: var(--blue); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; }
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--gray-50); }
.chat .top { background: #fff; border-bottom: 1px solid var(--gray-200); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.chat .msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 75%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.msg.in { background: #fff; border: 1px solid var(--gray-200); align-self: flex-start; }
.msg.out { background: var(--blue); color: #fff; align-self: flex-end; }
.msg.out.staff, .msg.out.page { background: var(--green); }
.msg-meta { font-size: 11px; color: var(--gray-500); margin: 0 6px 6px; }
.msg-meta.r { align-self: flex-end; }
.banner { background: var(--amber-50); color: #7a4a00; padding: 10px 16px; font-size: 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #f5d48a; }
.composer { background: #fff; border-top: 1px solid var(--gray-200); padding: 10px; display: flex; gap: 8px; }
.composer textarea { min-height: 44px; height: 44px; max-height: 160px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--gray-500); text-align: center; padding: 30px; }
.detail { background: #fff; border-left: 1px solid var(--gray-200); overflow: auto; padding: 16px; }
.detail h3 { margin: 0 0 4px; font-size: 16px; }
.detail .fld { margin-top: 10px; }
.detail .fld label { font-size: 12px; font-weight: 600; color: var(--gray-500); display: block; margin-bottom: 4px; }
.detail input.filled { background: #f0fbf5; border-color: #b8e6cf; }
.back { display: none; }
@media (max-width: 1150px) { .inbox { grid-template-columns: 320px 1fr; } .detail { display: none; } .detail.show { display: block; position: fixed; inset: 0 0 0 auto; width: min(360px, 100%); z-index: 30; box-shadow: -10px 0 30px rgba(0,0,0,.15); } }
@media (max-width: 800px) {
  .inbox { grid-template-columns: 1fr; height: calc(100dvh - 58px); }
  .inbox.open .list { display: none; }
  .inbox:not(.open) .chat { display: none; }
  .back { display: inline-flex; }
  .msg { max-width: 85%; }
}

/* Tables / lists */
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.pg { background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.pg .t { flex: 1; min-width: 0; }
.pg .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pg .err { color: var(--red); font-size: 12px; margin-top: 3px; }
.faq { border: 1px solid var(--gray-200); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.faq .q { font-weight: 700; }
.faq .a { color: #374151; margin-top: 3px; white-space: pre-wrap; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl td, .tbl th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
.tbl th { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .03em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--gray-200); border-radius: 99px; padding: 4px 10px; font-size: 13px; cursor: pointer; background: #fff; }
.chip input { margin: 0; }
.testchat { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px; min-height: 160px; max-height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 6px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 12px; max-width: 340px; box-shadow: 0 8px 30px rgba(0,0,0,.2); cursor: pointer; font-size: 14px; }
.toast.good { border-left: 5px solid var(--green); }
.toast.bad { border-left: 5px solid var(--red); }
