* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --line: #e3e8ee;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --sidebar: #111827;
}
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* ---------- login ---------- */
#login-screen {
  position: fixed; inset: 0; background: var(--sidebar);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-box {
  background: var(--card); padding: 36px; border-radius: 14px; width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-box p { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.login-box input { width: 100%; margin-bottom: 12px; }
/* :not(.pw-eye) — kalau tidak, butang mata yang disuntik turut jadi lebar 100%
   dan menutupi seluruh medan, jadi klik biasa mendedahkan kata laluan */
.login-box button:not(.pw-eye) { width: 100%; }
.login-err { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 16px; }

/* ---------- layout ---------- */
#app { display: none; }
#app.ready { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; background: var(--sidebar); color: #cbd5e1; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 18px 0;
  position: sticky; top: 0; height: 100vh;
}
.logo { padding: 0 20px 18px; font-weight: 700; font-size: 17px; color: #fff; }
.logo span { color: #4ade80; }
.nav button {
  display: block; width: 100%; text-align: left; padding: 11px 20px;
  background: none; border: none; color: #cbd5e1; font-size: 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav button.active { background: rgba(74,222,128,.12); color: #4ade80; border-left-color: #4ade80; }
.sidebar .foot { margin-top: auto; padding: 14px 20px; font-size: 12px; color: #64748b; }
.sidebar .foot a { color: #94a3b8; cursor: pointer; text-decoration: underline; }

.main { flex: 1; padding: 26px 30px; max-width: 1150px; }
.main h2 { font-size: 21px; margin-bottom: 4px; }
.main .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }

/* ---------- components ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

.stat { text-align: left; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.grey { background: #eef1f5; color: var(--muted); }

button, .btn {
  background: var(--blue); color: #fff; border: none; padding: 8px 14px;
  border-radius: 8px; font-size: 13.5px; cursor: pointer; font-family: inherit;
}
button:hover { filter: brightness(1.08); }
button.sm { padding: 5px 10px; font-size: 12.5px; }
button.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: var(--red); }
button.green { background: var(--green); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
textarea { width: 100%; min-height: 110px; resize: vertical; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1; min-width: 140px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* toggle papar/sembunyi kata laluan */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 40px; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; padding: 5px 7px; cursor: pointer;
  color: var(--muted); display: flex; align-items: center; border-radius: 6px;
}
.pw-eye:hover { background: #eef1f5; color: var(--ink); filter: none; }
.pw-eye:focus-visible { outline: 2px solid var(--blue); }
.login-box .pw-wrap { margin-bottom: 12px; }
.login-box .pw-wrap input { margin-bottom: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 2px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: #fafbfd; }
.msg-preview { max-width: 300px; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; color: var(--muted); }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ---------- chats ---------- */
.chat-layout { display: grid; grid-template-columns: 330px 1fr; gap: 14px; align-items: start; }
.chat-list { max-height: 68vh; overflow-y: auto; }
.chat-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--line); padding: 10px 8px; cursor: pointer; color: var(--ink);
}
.chat-item:hover { background: #f6f8fb; filter: none; }
.chat-item.active { background: var(--blue-soft); }
.chat-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item .who { font-weight: 600; font-size: 13.5px; }
.chat-item .when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chat-item .prev { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

.thread { max-height: 68vh; overflow-y: auto; padding: 4px 2px; }
.bubble { max-width: 74%; padding: 8px 11px; border-radius: 12px; margin-bottom: 8px;
  font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.bubble .meta { font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.bubble.inb { background: #eef1f5; border-top-left-radius: 3px; }
.bubble.out { background: var(--green-soft); margin-left: auto; border-top-right-radius: 3px; }
.bubble.media { font-style: italic; color: var(--muted); }
.thread-head { display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.day-sep { text-align: center; font-size: 11px; color: var(--muted); margin: 12px 0 8px; }

.composer { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line);
  padding-top: 12px; margin-top: 12px; }
.composer textarea { min-height: 44px; max-height: 140px; flex: 1; margin: 0; }
.composer button { white-space: nowrap; }
.composer-off { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }

.branch-picker { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 4px; }
.branch-picker label { display: inline-flex; align-items: center; gap: 6px; margin: 0;
  font-size: 13px; color: var(--ink); font-weight: 500; cursor: pointer; }
.branch-picker input { margin: 0; }

@media (max-width: 860px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { max-height: 40vh; }
}

/* branch card */
.branch-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.branch-card .head b { font-size: 15px; }
.branch-card .line { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.branch-card .line .k { color: var(--muted); }
.branch-card .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 60;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: #fff; border-radius: 14px; padding: 26px; width: 380px; max-width: 92vw;
  text-align: center;
}
.modal h3 { margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.modal img { width: 260px; height: 260px; }
.modal .close-row { margin-top: 14px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 80;
  background: var(--sidebar); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 340px;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--red); }

.tabs2 { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs2 button { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.tabs2 button.active { background: var(--blue); color: #fff; border-color: var(--blue); }

@media (max-width: 760px) {
  #app.ready { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; padding: 0; }
  .logo { padding: 14px; }
  .nav { display: flex; }
  .nav button { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .nav button.active { border-bottom-color: #4ade80; }
  .sidebar .foot { display: none; }
  .main { padding: 16px; }
}
