/* ==========================================================================
   ivpan chat — design system
   Netral hangat, tipografi rapat, garis tipis, satu aksen hijau tua.
   ========================================================================== */

@font-face {
  font-family: "Inter";
  src: url("/fonts/InterVariable.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #fbfbf9;
  --hover: #f1f1ec;
  --active: #eef1ec;
  --ink: #17180f;
  --ink-2: #5e6055;
  --ink-3: #8e9084;
  --line: #e5e5dd;
  --line-2: #d7d7cd;
  --green: #1c6b4b;
  --green-soft: #e7efe9;
  --green-ink: #0e4a32;
  --danger: #b42318;
  --radius: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: #d9e6dd; }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ------------------------------- komponen -------------------------------- */

.avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .01em;
  background: var(--green);
  user-select: none;
  overflow: hidden;
}
.avatar.big { width: 44px; height: 44px; border-radius: 12px; font-size: 14px; }
.avatar.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 10px; }

.avatar-wrap { position: relative; flex: 0 0 auto; display: flex; }
.presence {
  position: absolute; right: -2px; bottom: -2px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--line-2);
  border: 2px solid var(--surface-2);
}
.presence.on { background: #2e9e63; }

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px;
  color: var(--ink-3);
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 15px; height: 15px; display: block; }
.icon-btn.attached { color: var(--ink-2); }

.btn-primary {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .005em;
  transition: background .12s ease, transform .08s ease;
}
.btn-primary:hover { background: #000; }
.btn-primary:active { transform: translateY(.5px); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-primary.small { width: auto; height: 34px; padding: 0 14px; font-size: 12px; }

.btn-danger {
  width: 100%;
  height: 38px;
  border-radius: 8px;
  border: 1px solid #eccfca;
  background: #fff;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 550;
}
.btn-danger:hover { background: #fdf4f2; }

.form-error {
  margin: 0 0 12px;
  padding: 9px 11px;
  border-radius: 7px;
  background: #fdf2f0;
  border: 1px solid #f0d3cd;
  color: var(--danger);
  font-size: 12px;
}

/* --------------------------------- login --------------------------------- */

.auth-body { background: var(--paper); }
.auth {
  display: grid;
  grid-template-columns: minmax(360px, 43%) minmax(0, 1fr);
  min-height: 100dvh;
}

.auth-side {
  background: #12140f;
  color: #f2f2ea;
  padding: 40px 44px 34px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-side::after {
  content: "";
  position: absolute;
  left: 44px; right: 44px; bottom: 92px;
  height: 1px;
  background: rgba(255, 255, 255, .08);
  pointer-events: none;
}
.side-brand { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.side-brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  display: grid; place-items: center;
  background: #f2f2ea; color: #12140f;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
}
.side-brand em { font-style: normal; color: #7e8275; font-weight: 500; }

.side-copy { max-width: 400px; position: relative; z-index: 1; }
.eyebrow {
  margin: 0 0 18px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #71766a;
}
.side-copy h2 {
  margin: 0 0 18px;
  font-size: clamp(30px, 3.1vw, 42px);
  line-height: 1.06;
  letter-spacing: -.035em;
  font-weight: 560;
  color: #f5f5ee;
}
.side-copy .lede {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: #9a9e91;
  max-width: 330px;
}
.side-foot {
  display: flex; align-items: center; gap: 8px;
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: #6d7165;
}
.dot-live { width: 5px; height: 5px; border-radius: 50%; background: #4ea87a; box-shadow: 0 0 0 3px rgba(78,168,122,.15); }

.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 340px; }
.auth-box h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 620;
  letter-spacing: -.03em;
}
.auth-sub { margin: 0 0 26px; font-size: 12.5px; color: var(--ink-2); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  font-size: 13px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input::placeholder { color: #b0b2a7; }
.field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(28, 107, 75, .12); }

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 54px; }
.ghost-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  height: 30px; padding: 0 8px;
  font-size: 11px; font-weight: 600; color: var(--green);
  border-radius: 6px;
}
.ghost-eye:hover { background: var(--green-soft); }

.auth-box .btn-primary { margin-top: 6px; }
.auth-foot { margin: 20px 0 0; font-size: 11.5px; color: var(--ink-3); }
.mobile-brand { display: none; }

/* ---------------------------------- app ---------------------------------- */

.app {
  display: grid;
  grid-template-columns: 308px minmax(0, 1fr);
  height: 100dvh;
  background: var(--paper);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
}
.side-top { padding: 14px 14px 8px; }
.brand-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  font-size: 9.5px; font-weight: 700; letter-spacing: .03em;
}
.brand-text { font-size: 13px; font-weight: 600; letter-spacing: -.015em; }
.brand-text em { font-style: normal; color: var(--ink-3); font-weight: 500; }

.search {
  display: flex; align-items: center; gap: 7px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.search:focus-within { border-color: var(--line-2); box-shadow: 0 0 0 3px rgba(23, 24, 15, .04); }
.search svg { width: 13px; height: 13px; color: var(--ink-3); flex: 0 0 auto; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: none; background: none;
  font-size: 12.5px;
}
.search input::placeholder { color: #a9aa9f; }
.search input::-webkit-search-cancel-button { appearance: none; }

.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.list-head span:last-child { font-variant-numeric: tabular-nums; letter-spacing: .02em; }

.contact-list {
  list-style: none; margin: 0; padding: 0 8px 12px;
  overflow-y: auto; flex: 1; min-height: 0;
}
.contact {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s ease;
}
.contact + .contact { margin-top: 1px; }
.contact:hover { background: #f3f3ee; }
.contact.active { background: var(--active); }
.contact-body { flex: 1; min-width: 0; }
.contact-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.contact-top strong {
  font-size: 12.5px; font-weight: 600; letter-spacing: -.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-top time { flex: 0 0 auto; font-size: 10px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.contact-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 1px; }
.contact-preview {
  font-size: 11.5px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  flex: 0 0 auto;
  min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 999px;
  background: var(--green); color: #fff;
  font-size: 9.5px; font-weight: 650;
  display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}
.list-empty { margin: 0; padding: 22px 18px; font-size: 12px; color: var(--ink-3); }

.side-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.me-text strong { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text span { font-size: 10.5px; color: var(--ink-3); }

/* --------------------------------- chat ---------------------------------- */

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }

.empty-state {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 32px;
  color: var(--ink-3);
}
.empty-mark {
  width: 52px; height: 52px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  display: grid; place-items: center;
  color: var(--ink-3);
  background: var(--surface-2);
  margin-bottom: 16px;
}
.empty-mark svg { width: 22px; height: 22px; }
.empty-state h2 { margin: 0 0 5px; font-size: 14px; font-weight: 600; letter-spacing: -.01em; color: var(--ink); }
.empty-state p { margin: 0; font-size: 12px; max-width: 260px; }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex: 0 0 auto;
}
.chat-head-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; flex: 1; }
.chat-head-text strong { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.chat-head-text span { font-size: 11px; color: var(--ink-3); }
.chat-head-text span.online { color: var(--green); }
.back { display: none; }
.ws-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); margin-left: auto; }
.ws-dot.on { background: #2e9e63; }
.ws-dot.off { background: #d97757; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 22px 6px;
  background: var(--paper);
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar, .contact-list::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb, .contact-list::-webkit-scrollbar-thumb {
  background: #d8d8ce; border: 3px solid transparent; background-clip: content-box; border-radius: 99px;
}

.day-sep { align-self: center; margin: 14px 0 10px; }
.day-sep span {
  font-size: 9.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3);
  background: var(--paper);
  padding: 0 8px;
}

.chat-hint { margin: auto; color: var(--ink-3); font-size: 12px; text-align: center; padding: 24px; }

.bubble {
  max-width: min(66%, 540px);
  padding: 7px 11px 6px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  align-self: flex-start;
  overflow-wrap: anywhere;
  animation: rise .12s ease-out;
}
.bubble.grouped { margin-top: 1px; }
.bubble.mine {
  align-self: flex-end;
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
@keyframes rise { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.bubble-text { font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.bubble-text a { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }

.bubble-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  margin-top: 2px;
  font-size: 9.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.bubble.mine .bubble-meta { color: rgba(255, 255, 255, .62); }
.ticks { display: inline-flex; align-items: center; color: rgba(255, 255, 255, .6); }
.ticks svg { width: 13px; height: 13px; display: block; }
.ticks.read { color: #b6e3c8; }

.bubble-img {
  display: block;
  max-width: 280px;
  max-height: 300px;
  border-radius: 8px;
  margin: 2px 0 4px;
  cursor: zoom-in;
  object-fit: cover;
  background: var(--hover);
}
.bubble-file {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px;
  margin: 2px 0 4px;
  border-radius: 7px;
  background: var(--paper);
  text-decoration: none;
}
.bubble.mine .bubble-file { background: rgba(255, 255, 255, .12); color: #fff; }
.file-ico { display: flex; color: var(--ink-2); }
.bubble.mine .file-ico { color: rgba(255, 255, 255, .85); }
.file-ico svg { width: 18px; height: 18px; }
.file-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.file-meta strong {
  font-size: 12px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px;
}
.file-meta span { font-size: 10.5px; opacity: .62; }

.typing-row {
  display: flex; align-items: center; gap: 6px;
  padding: 0 24px 6px;
  font-size: 11.5px;
  color: var(--ink-3);
  background: var(--paper);
}
.typing-row b { font-weight: 550; color: var(--ink-2); }
.typing-dots {
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--green);
  box-shadow: 6px 0 0 rgba(28,107,75,.45), 12px 0 0 rgba(28,107,75,.2);
  margin-right: 12px;
  animation: blink 1.1s infinite ease-in-out;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex: 0 0 auto;
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 132px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  outline: none;
  font-size: 13px;
  line-height: 1.45;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.composer textarea::placeholder { color: #a9aa9f; }
.composer textarea:focus { border-color: var(--line-2); box-shadow: 0 0 0 3px rgba(23, 24, 15, .05); }
.send-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--green);
  color: #fff;
  transition: background .12s ease, opacity .12s ease;
}
.send-btn:hover { background: var(--green-ink); }
.send-btn:disabled { opacity: .45; }
.send-btn svg { width: 16px; height: 16px; }

.attach-preview {
  display: flex; align-items: center; gap: 8px;
  margin: 0 16px 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--ink-2);
}
.attach-preview > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------- modal --------------------------------- */

.modal {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(18, 20, 15, .38);
  backdrop-filter: blur(2px);
}
.modal-box {
  width: 100%; max-width: 372px;
  max-height: 88dvh; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(18, 20, 15, .16), 0 2px 8px rgba(18,20,15,.06);
}
.modal-box.wide { max-width: 600px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 14px; font-weight: 620; letter-spacing: -.015em; }

.stack { display: flex; flex-direction: column; }
.account-info { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.account-info strong { display: block; font-size: 13px; font-weight: 600; }
.account-info span { font-size: 11.5px; color: var(--ink-3); }

.admin-create { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 14px; }
.admin-create input, .admin-create select {
  height: 34px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-2); outline: none; font-size: 12px;
}
.admin-create input:focus, .admin-create select:focus { border-color: var(--green); background: #fff; }

.admin-table-wrap { overflow-x: auto; margin: 0 -4px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th {
  padding: 6px 5px;
  text-align: left;
  font-size: 9px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
}
.admin-table td { padding: 8px 5px; border-bottom: 1px solid #f0f0ea; vertical-align: middle; }
.admin-table .u-cell { display: flex; align-items: center; gap: 8px; }
.admin-table .u-cell strong { display: block; font-size: 12px; font-weight: 600; }
.admin-table .u-cell small { font-size: 10.5px; color: var(--ink-3); }
.pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--hover);
  color: var(--ink-2);
  font-size: 9px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
}
.pill.admin { background: var(--green-soft); color: var(--green-ink); }
.pill.off { background: #fbeeeb; color: var(--danger); }
.row-actions { display: flex; gap: 3px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions button {
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  font-size: 10.5px;
  color: var(--ink-2);
}
.row-actions button:hover { background: var(--hover); border-color: var(--line-2); }

.lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 24px;
  background: rgba(12, 13, 10, .9);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 90;
  padding: 9px 14px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

/* ------------------------------- responsive ------------------------------ */

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-main { padding: 28px 20px; align-items: center; }
  .mobile-brand {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 34px;
    font-size: 12.5px; font-weight: 600;
  }
  .mobile-brand .mark {
    width: 25px; height: 25px; border-radius: 6px;
    display: grid; place-items: center;
    background: var(--ink); color: #fff;
    font-size: 9.5px; font-weight: 700;
  }
  .mobile-brand em { font-style: normal; color: var(--ink-3); font-weight: 500; }

  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .chat {
    position: fixed; inset: 0; z-index: 20;
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  .app.chat-open .chat { transform: none; }
  .back { display: grid; }
  .bubble { max-width: 82%; }
  .messages { padding: 14px 14px 4px; }
  .chat { padding-top: env(safe-area-inset-top); }
  .composer { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .chat-head { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
