:root {
  --green: #00a884; --green-dark: #075E54; --bg: #f0f2f5; --panel: #fff; --line: #e9edef;
  --text: #111b21; --muted: #667781; --bubble-in: #fff; --bubble-out: #d9fdd3; --chat-bg: #efeae2;
  --hover: #f5f6f6; --active: #f0f2f5; --danger: #e53935;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar { width: 380px; min-width: 300px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.me { display: flex; flex-direction: column; }
.me small { color: var(--muted); font-size: 12px; }
.icon { background: none; border: 0; font-size: 18px; padding: 6px 8px; border-radius: 50%; color: var(--muted); }
.icon:hover { background: rgba(0,0,0,.06); }
.icon.on { color: var(--green); }
.btn { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 6px 12px; font-size: 13px; color: var(--text); }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--danger); }
.search { padding: 8px 12px; }
.search input { width: 100%; border: 0; background: var(--bg); border-radius: 8px; padding: 9px 12px; outline: none; }
.filters { display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto; }
.chip { white-space: nowrap; border: 0; background: var(--bg); color: var(--muted); border-radius: 16px; padding: 5px 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.chip.active { background: #d9fdd3; color: #008069; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

#chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.ci { display: flex; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.ci:hover { background: var(--hover); }
.ci.active { background: var(--active); }
.ci .bar { position: absolute; right: 0; top: 0; bottom: 0; width: 4px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: #dfe5e7; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; font-size: 17px; }
.ci .body { flex: 1; min-width: 0; }
.ci .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ci .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .time { font-size: 12px; color: var(--muted); flex: none; }
.ci.unread .time { color: var(--green); }
.ci .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .deal { font-size: 12px; color: #1e88e5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .meta { display: flex; gap: 4px; align-items: center; flex: none; }
.badge { background: var(--green); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; min-width: 20px; text-align: center; }
.pin-ic { font-size: 12px; }
.lbls { display: flex; gap: 3px; }

#chat { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }
.empty { margin: auto; color: var(--muted); font-size: 15px; }
#chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.who { flex: 1; min-width: 0; }
.who-name { font-weight: 600; }
.who-sub { font-size: 12px; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 6px; }
.dropdown { position: relative; }
.menu { position: absolute; left: 0; top: 110%; background: #fff; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.15); min-width: 260px; max-height: 420px; overflow-y: auto; z-index: 20; padding: 6px 0; }
.menu h4 { margin: 6px 14px 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.menu a, .menu button, .menu label { display: flex; align-items: center; gap: 8px; width: 100%; text-align: right; background: none; border: 0; padding: 8px 14px; color: var(--text); text-decoration: none; font-size: 14px; }
.menu a:hover, .menu button:hover, .menu label:hover { background: var(--hover); }
.menu .closed { text-decoration: line-through; color: var(--muted); }
.menu .sub { font-size: 12px; color: var(--muted); display: block; }
.chat-tags { display: flex; gap: 6px; padding: 6px 16px; flex-wrap: wrap; }
.chat-tags:empty { display: none; }
.tag { font-size: 12px; color: #fff; border-radius: 12px; padding: 2px 10px; }
.tag.ad { background: #1877f2; }

#messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: #fff; color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px .5px rgba(0,0,0,.1); }
.msg { max-width: 65%; padding: 6px 9px 4px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.45; }
.msg.in { align-self: flex-start; background: var(--bubble-in); }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .author { font-size: 12px; color: #008069; font-weight: 600; margin-bottom: 2px; }
.msg .foot { font-size: 11px; color: var(--muted); text-align: left; margin-top: 2px; }
.msg a { color: #027eb5; }
.msg img { max-width: 260px; border-radius: 6px; display: block; }

#composer { background: var(--bg); padding: 8px 16px; }
#send-form { display: flex; gap: 8px; align-items: flex-end; }
#text { flex: 1; resize: none; border: 0; border-radius: 8px; padding: 10px 12px; max-height: 140px; outline: none; }
.send { background: var(--green); color: #fff; border: 0; border-radius: 50%; width: 42px; height: 42px; font-size: 18px; transform: scaleX(-1); }
.note { font-size: 13px; color: #8a6d00; background: #fff8e1; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }

#admin { position: fixed; inset: 0; background: var(--bg); overflow-y: auto; z-index: 30; }
.admin-head { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 2; }
.admin-head h2 { margin: 0; font-size: 18px; }
#admin-tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#admin-tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 18px; color: var(--muted); }
#admin-tabs button.active { background: #d9fdd3; color: #008069; }
#admin-body { padding: 20px; max-width: 1200px; }
.card { background: #fff; border-radius: 10px; padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
select, input[type=text], input[type=password] { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.code { font-family: Consolas, monospace; font-size: 12px; background: var(--bg); padding: 6px 8px; border-radius: 6px; direction: ltr; display: inline-block; word-break: break-all; }
.multi { max-height: 140px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; min-width: 200px; }
.multi label { display: block; font-size: 13px; }
.auto { color: #008069; font-size: 12px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal-box { width: min(440px, calc(100% - 32px)); }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111b21; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; font-size: 14px; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  #sidebar { width: 100%; min-width: 0; border: 0; }
  #chat { display: none; }
  #app.open #sidebar { display: none; }
  #app.open #chat { display: flex; }
  .mobile-only { display: inline-block; }
  .msg { max-width: 85%; }
  #messages { padding: 12px; }
  .head-actions .btn { padding: 5px 8px; }
}
