/* ============ Konek - ala WhatsApp Web ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --accent: #00a884;
  --accent-dark: #008069;
  --panel: #ffffff;
  --panel-header: #f0f2f5;
  --chat-bg: #efeae2;
  --sent: #d9fdd3;
  --received: #ffffff;
  --text: #111b21;
  --text-sec: #667781;
  --border: #e9edef;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --badge: #25d366;
  --tick: #53bdeb;
  --overlay: rgba(11, 20, 26, 0.5);
  --input-bg: #ffffff;
  --danger: #ea0038;
}
body.dark {
  --accent: #00a884;
  --accent-dark: #005c4b;
  --panel: #111b21;
  --panel-header: #202c33;
  --chat-bg: #0b141a;
  --sent: #005c4b;
  --received: #202c33;
  --text: #e9edef;
  --text-sec: #8696a0;
  --border: #2a3942;
  --hover: #202c33;
  --active: #2a3942;
  --badge: #00a884;
  --tick: #53bdeb;
  --overlay: rgba(0, 0, 0, 0.6);
  --input-bg: #2a3942;
}
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--panel-header);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.35); border-radius: 3px; }

/* ============ Halaman Auth ============ */
.auth-page, .link-page {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; overflow: auto; background: var(--panel-header); gap: 18px; padding: 24px;
}
.auth-header { text-align: center; }
.logo-big {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 34px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px;
}
.auth-header h1 { font-size: 28px; letter-spacing: -0.5px; }
.auth-header p { color: var(--text-sec); margin-top: 4px; font-size: 14px; }
.auth-card, .link-card {
  background: var(--panel); border-radius: 12px; padding: 24px; width: 100%; max-width: 380px;
  box-shadow: 0 4px 24px rgba(11, 20, 26, 0.08);
}
.tabs { display: flex; gap: 8px; margin-bottom: 18px; background: var(--panel-header); border-radius: 8px; padding: 4px; }
.tabs button { flex: 1; padding: 8px; border-radius: 6px; font-size: 14px; color: var(--text-sec); }
.tabs button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.tabs.small button { padding: 6px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-sec); margin-bottom: 5px; font-weight: 600; }
.field input, .modal input {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--text); font-size: 14px; outline: none;
}
.field input:focus, .modal input:focus { border-color: var(--accent); }
.phone-wrap { display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 8px; background: var(--input-bg); }
.phone-wrap span { padding: 11px 6px 11px 12px; color: var(--text-sec); font-size: 14px; }
.phone-wrap input { border: none !important; flex: 1; background: transparent; }
.btn-primary {
  width: 100%; padding: 12px; background: var(--accent); color: #fff; border-radius: 8px;
  font-size: 15px; font-weight: 600; transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-sec {
  width: 100%; padding: 10px; background: var(--panel-header); color: var(--text);
  border-radius: 8px; font-size: 14px; font-weight: 600;
}
.btn-sec:hover { background: var(--hover); }
.wide { width: 100%; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; text-align: center; }
.auth-foot { color: var(--text-sec); font-size: 13px; text-align: center; }
.auth-foot a { color: var(--accent-dark); text-decoration: none; font-weight: 600; }

/* ============ Halaman Link (QR pairing) ============ */
.link-card { text-align: center; }
#qr-holder {
  width: 236px; height: 236px; margin: 0 auto 14px; background: #fff; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; padding: 8px;
}
#qr-holder img, #qr-holder canvas { image-rendering: pixelated; }
.code-display {
  font-size: 30px; font-weight: 700; letter-spacing: 4px; color: var(--accent-dark);
  background: var(--panel-header); border-radius: 10px; padding: 10px; margin: 12px 0;
  font-family: 'Courier New', monospace;
}
.hint { color: var(--text-sec); font-size: 13px; line-height: 1.5; }
.countdown { font-size: 13px; color: var(--text-sec); font-weight: 600; }
.link-status { margin-top: 10px; font-size: 14px; color: var(--text-sec); }
.link-status.ok { color: var(--accent-dark); font-weight: 600; }

/* ============ Layout Chat ============ */
#app { display: flex; height: 100vh; }
#sidebar {
  width: 30%; min-width: 340px; max-width: 440px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sb-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--panel-header); min-height: 60px; position: relative;
}
.sb-title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-icons, .ch-icons { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: var(--text-sec); position: relative;
}
.icon-btn:hover { background: rgba(134, 150, 160, 0.15); }
.icon-btn svg { width: 22px; height: 22px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 600;
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0;
}
.avatar.big { width: 72px; height: 72px; font-size: 28px; margin: 0 auto 14px; }
.sb-search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.sb-search input {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: none; outline: none;
  background: var(--panel-header); color: var(--text); font-size: 14px;
}
#chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; gap: 12px; padding: 12px 14px; cursor: pointer; align-items: center;
  border-bottom: 1px solid var(--border);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.ci-main { flex: 1; min-width: 0; }
.ci-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ci-title { font-size: 15px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--text-sec); flex-shrink: 0; }
.ci-last { font-size: 13px; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ci-badge {
  background: var(--badge); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 20px; padding: 2px 7px; flex-shrink: 0;
}

#chat-main { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-sec); gap: 8px; border-bottom: 6px solid var(--accent);
}
.empty-state .doodle {
  width: 200px; height: 200px; border-radius: 50%; background: var(--panel-header);
  display: flex; align-items: center; justify-content: center; font-size: 90px; color: var(--accent); margin-bottom: 20px;
}
.empty-state h2 { color: var(--text-sec); font-weight: 400; }
.empty-state p { font-size: 14px; }

#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ch-header {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: var(--panel-header); min-height: 60px;
}
.ch-info { flex: 1; min-width: 0; }
#ch-title { font-size: 16px; font-weight: 600; }
#ch-sub { font-size: 13px; color: var(--text-sec); }
.messages { flex: 1; overflow-y: auto; padding: 20px 6% 12px; }
.date-divider { text-align: center; margin: 14px 0; }
.date-divider span {
  background: var(--panel-header); color: var(--text-sec); font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 8px;
}
.msg-row { display: flex; margin-bottom: 3px; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }
.bubble {
  max-width: min(65%, 520px); padding: 7px 10px 20px 10px; border-radius: 10px;
  font-size: 14.2px; line-height: 1.45; position: relative; word-wrap: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}
.msg-row.mine .bubble { background: var(--sent); border-top-right-radius: 2px; }
.msg-row.theirs .bubble { background: var(--received); border-top-left-radius: 2px; }
.bubble .meta {
  position: absolute; right: 8px; bottom: 4px; font-size: 11px; color: var(--text-sec);
  display: flex; align-items: center; gap: 3px; float: right; margin: 0 -4px -6px 8px;
}
.bubble .meta .ticks { color: var(--tick); }
.bubble.typing { color: var(--text-sec); font-style: italic; }
.ch-input {
  display: flex; gap: 10px; padding: 10px 16px; background: var(--panel-header); align-items: center;
}
.ch-input input {
  flex: 1; padding: 13px 16px; border-radius: 10px; border: none; outline: none;
  background: var(--panel); color: var(--text); font-size: 15px;
}
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn svg { width: 22px; height: 22px; }

/* ============ Dropdown & Modal ============ */
.dropdown {
  position: absolute; top: 56px; right: 12px; background: var(--panel); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(11, 20, 26, 0.18); z-index: 60; overflow: hidden; min-width: 210px;
}
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 13px 20px; font-size: 14px; color: var(--text);
}
.dropdown button:hover { background: var(--hover); }
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--panel); border-radius: 14px; padding: 22px; width: 100%;
  max-width: 400px; max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal label { display: block; font-size: 12px; color: var(--text-sec); margin: 10px 0 5px; font-weight: 600; }
.modal .or { text-align: center; color: var(--text-sec); font-size: 13px; margin: 12px 0; }
.modal-close { margin-top: 14px; width: 100%; padding: 10px; border-radius: 8px; background: var(--panel-header); color: var(--text); font-weight: 600; font-size: 14px; }
.device-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border);
}
.device-row .dr-main { flex: 1; min-width: 0; }
.device-row .dr-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.device-row .dr-name .tag {
  font-size: 10px; background: var(--accent); color: #fff; padding: 2px 7px; border-radius: 10px; font-weight: 600;
}
.device-row .dr-sub { font-size: 12px; color: var(--text-sec); margin-top: 2px; }
.device-remove { color: var(--danger); font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 6px; }
.device-remove:hover { background: rgba(234, 0, 56, 0.08); }
#devices-list { margin: 8px 0 16px; }
#scan-video { width: 100%; border-radius: 10px; background: #000; margin-bottom: 10px; }
#link-panel { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
#pane-code input { text-align: center; font-size: 20px; letter-spacing: 3px; font-weight: 700; }
.link-ok { color: var(--accent-dark) !important; font-weight: 600; }

/* ============ Mobile ============ */
.only-mobile { display: none !important; }
@media (max-width: 768px) {
  #sidebar { width: 100%; max-width: none; min-width: 0; }
  #chat-main { position: fixed; inset: 0; z-index: 50; transform: translateX(100%); transition: transform 0.2s; }
  body.chat-open #chat-main { transform: translateX(0); }
  .only-mobile { display: flex !important; }
  .bubble { max-width: 82%; }
}
