/* WhatsApp-style team inbox. No external fonts or images: everything is local, the CSP allows nothing else. */
:root {
  --bg: #d1d7db; --panel: #ffffff; --header: #f0f2f5; --hover: #f5f6f6; --selected: #f0f2f5; --line: #e9edef;
  --text: #111b21; --muted: #667781; --accent: #00a884; --accent-dark: #008069; --accent-text: #ffffff;
  --bubble-out: #d9fdd3; --bubble-in: #ffffff; --wallpaper: #efeae2; --tick: #53bdeb; --danger: #ea0038; --warn: #fff3cd; --warn-text: #5c4400;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, .13); --input: #ffffff; --chip: #e9edef; --chip-on: #d9fdd3; --chip-on-text: #008069;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0b141a; --panel: #111b21; --header: #202c33; --hover: #202c33; --selected: #2a3942; --line: #222d34; --text: #e9edef; --muted: #8696a0; --accent: #00a884; --accent-dark: #00a884; --bubble-out: #005c4b; --bubble-in: #202c33; --wallpaper: #0b141a; --tick: #53bdeb; --warn: #3a3320; --warn-text: #f5d97a; --shadow: 0 1px 0.5px rgba(11, 20, 26, .5); --input: #2a3942; --chip: #202c33; --chip-on: #103529; --chip-on-text: #06cf9c; } }
:root[data-theme="dark"] { --bg: #0b141a; --panel: #111b21; --header: #202c33; --hover: #202c33; --selected: #2a3942; --line: #222d34; --text: #e9edef; --muted: #8696a0; --accent: #00a884; --accent-dark: #00a884; --bubble-out: #005c4b; --bubble-in: #202c33; --wallpaper: #0b141a; --tick: #53bdeb; --warn: #3a3320; --warn-text: #f5d97a; --shadow: 0 1px 0.5px rgba(11, 20, 26, .5); --input: #2a3942; --chip: #202c33; --chip-on: #103529; --chip-on-text: #06cf9c; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
[hidden] { display: none !important; }
svg.i { width: 24px; height: 24px; fill: currentColor; flex: none; }
svg.i.sm { width: 18px; height: 18px; } svg.i.xs { width: 15px; height: 15px; }

/* ---------- sign-in ---------- */
.login-body { display: grid; place-items: center; min-height: 100%; background: linear-gradient(180deg, var(--accent) 0 220px, var(--bg) 220px); padding: 16px; }
.login-card { background: var(--panel); width: 100%; max-width: 420px; padding: 34px 32px 28px; border-radius: 10px; box-shadow: 0 17px 50px rgba(11, 20, 26, .2); }
.login-logo { width: 62px; height: 62px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.login-card h1 { font-size: 22px; font-weight: 500; margin: 0 0 6px; text-align: center; }
.login-card .muted { text-align: center; margin: 0 0 18px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--input); outline: none; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0, 168, 132, .18); }
.login-card button { width: 100%; margin-top: 22px; padding: 12px; border: 0; border-radius: 24px; background: var(--accent); color: #fff; font-weight: 600; }
.login-card button:hover { background: var(--accent-dark); }
.login-error { background: #fdecef; color: #b00020; padding: 10px 12px; border-radius: 8px; margin: 0 0 6px; text-align: left !important; }
@media (prefers-color-scheme: dark) { .login-error { background: #3b1a21; color: #ff8a9b; } }

/* ---------- shell ---------- */
#app { height: 100%; display: flex; max-width: 1700px; margin: 0 auto; background: var(--panel); box-shadow: 0 6px 18px rgba(11, 20, 26, .05); }
@media (min-width: 1500px) { body { padding: 19px 0; } #app { height: calc(100% - 0px); } }
.rail { width: 64px; background: var(--header); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 4px; flex: none; }
.rail button { position: relative; width: 46px; height: 46px; border: 0; background: none; color: var(--muted); border-radius: 50%; display: grid; place-items: center; }
.rail button:hover { background: var(--selected); }
.rail button.on { background: var(--selected); color: var(--text); }
.rail .spacer { flex: 1; }
.rail .badge-dot { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 16px; flex: none; text-transform: uppercase; user-select: none; }
.avatar.lg { width: 84px; height: 84px; font-size: 32px; } .avatar.sm { width: 32px; height: 32px; font-size: 13px; }

.view { flex: 1; min-width: 0; display: flex; }
.col-list { width: 410px; max-width: 42%; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 300px; background: var(--panel); }
.col-head { height: 59px; background: var(--header); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; flex: none; }
.col-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.icon-btn { border: 0; background: none; color: var(--muted); width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:hover { background: var(--selected); color: var(--text); }
.search { padding: 8px 12px 6px; background: var(--panel); flex: none; }
.search label { display: flex; align-items: center; gap: 14px; background: var(--header); border-radius: 8px; padding: 0 12px; height: 35px; color: var(--muted); }
.search input { flex: 1; border: 0; outline: 0; background: none; font-size: 14px; min-width: 0; }
.chips { display: flex; gap: 6px; padding: 4px 12px 8px; overflow-x: auto; flex: none; scrollbar-width: none; }
.chip { border: 0; background: var(--chip); color: var(--muted); border-radius: 16px; padding: 5px 12px; white-space: nowrap; font-size: 13.5px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-text); font-weight: 600; }
.chip .n { margin-left: 5px; font-weight: 700; }
.list { flex: 1; overflow-y: auto; }
.row { display: flex; gap: 13px; padding: 0 15px; align-items: center; height: 72px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.row:hover { background: var(--hover); } .row.on { background: var(--selected); }
.row .mid { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.row:last-child .mid { border-bottom: 0; }
.row .top, .row .bot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row .name { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--muted); flex: none; } .row.unread .time { color: var(--accent); font-weight: 600; }
.row .prev { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; min-width: 0; }
.row .prev span { overflow: hidden; text-overflow: ellipsis; }
.row .tags { display: flex; gap: 6px; align-items: center; flex: none; }
.pill { background: var(--accent); color: #fff; border-radius: 12px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.pill.warn { background: #f59f00; } .pill.grey { background: var(--muted); }
.tick { color: var(--muted); display: inline-flex; } .tick.read { color: var(--tick); } .tick.failed { color: var(--danger); }
.empty { padding: 36px 24px; text-align: center; color: var(--muted); }
.more { padding: 14px; text-align: center; }
.more button { border: 0; background: none; color: var(--accent-dark); }

/* ---------- conversation ---------- */
.col-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--wallpaper); position: relative; border-bottom: 6px solid var(--accent); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; padding: 24px; }
.chat-empty h3 { font-weight: 300; font-size: 30px; color: var(--text); margin: 18px 0 10px; }
.chat-empty .logo { width: 88px; height: 88px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; margin: 0 auto; color: #fff; }
.chat-head { height: 59px; background: var(--header); display: flex; align-items: center; gap: 13px; padding: 0 12px 0 16px; flex: none; cursor: pointer; }
.chat-head .who { flex: 1; min-width: 0; } .chat-head .t { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 6% 8px; display: flex; flex-direction: column; gap: 2px; background-image: radial-gradient(circle at 20% 30%, rgba(0, 0, 0, .025) 0 2px, transparent 3px), radial-gradient(circle at 70% 70%, rgba(0, 0, 0, .025) 0 2px, transparent 3px); background-size: 46px 46px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow); margin: 10px 0; }
.sys { align-self: center; background: var(--warn); color: var(--warn-text); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; margin: 6px 0; max-width: 80%; text-align: center; }
.msg { display: flow-root; max-width: 65%; padding: 6px 7px 7px 9px; border-radius: 7.5px; box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere; margin-top: 2px; min-width: 70px; }
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.msg.first-in::before, .msg.first-out::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
.msg.first-in::before { left: -8px; background: var(--bubble-in); clip-path: polygon(100% 0, 0 0, 100% 100%); }
.msg.first-out::before { right: -8px; background: var(--bubble-out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg .by { font-size: 12.5px; font-weight: 600; color: var(--accent-dark); margin-bottom: 1px; }
.msg .by.auto { color: #7e57c2; } .msg .by.bot { color: #1976d2; }
.msg .txt { white-space: pre-wrap; font-size: 14.2px; line-height: 19px; }
.msg .meta { float: right; margin: 5px 0 -3px 12px; font-size: 11px; color: var(--muted); display: inline-flex; gap: 3px; align-items: center; line-height: 15px; }
.msg.err .meta { color: var(--danger); }
.msg .errline { color: var(--danger); font-size: 12px; margin-top: 3px; }
.msg img.pic { display: block; max-width: 320px; width: 100%; max-height: 340px; object-fit: cover; border-radius: 6px; margin-bottom: 4px; cursor: zoom-in; background: var(--line); min-height: 60px; }
.msg audio { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }
.file { display: flex; gap: 10px; align-items: center; padding: 10px; background: rgba(0, 0, 0, .05); border-radius: 6px; margin-bottom: 4px; color: inherit; text-decoration: none; }
.file .nm { font-size: 14px; word-break: break-all; } .file .sz { font-size: 12px; color: var(--muted); }
.tpl { font-style: italic; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.closed-bar { background: var(--header); padding: 14px 16px; display: flex; gap: 12px; align-items: center; flex: none; font-size: 13.5px; }
.closed-bar .grow { flex: 1; }
.composer { background: var(--header); padding: 8px 14px; display: flex; gap: 10px; align-items: flex-end; flex: none; }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; border-radius: 8px; background: var(--input); padding: 10px 12px; max-height: 140px; min-height: 42px; line-height: 20px; font-size: 15px; }
.send { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .45; cursor: default; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 20px; padding: 8px 18px; font-weight: 600; }
.btn:hover { background: var(--accent-dark); } .btn.ghost { background: var(--chip); color: var(--text); } .btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #111b21; color: #fff; padding: 11px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); z-index: 90; max-width: 90vw; }
.toast.bad { background: #b00020; }

/* ---------- side panel and menus ---------- */
.col-info { width: 360px; max-width: 100%; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; flex: none; overflow-y: auto; }
.col-info .col-head { justify-content: flex-start; gap: 14px; }
.card { background: var(--panel); padding: 14px 20px; border-bottom: 8px solid var(--header); }
.card h4 { margin: 0 0 8px; font-weight: 400; color: var(--muted); font-size: 14px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 26px 20px 18px; border-bottom: 8px solid var(--header); }
.hero .nm { font-size: 22px; text-align: center; } 
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; } .kv span:first-child { color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; font-size: 13px; } .history li { padding: 4px 0; color: var(--muted); }
.menu { position: fixed; background: var(--panel); border-radius: 8px; box-shadow: 0 2px 5px rgba(11, 20, 26, .26), 0 2px 10px rgba(11, 20, 26, .16); padding: 8px 0; z-index: 80; min-width: 190px; }
.menu button { display: flex; width: 100%; gap: 12px; align-items: center; padding: 10px 22px; border: 0; background: none; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.modal-back { position: fixed; inset: 0; background: rgba(11, 20, 26, .55); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; box-shadow: 0 17px 50px rgba(11, 20, 26, .3); }
.modal.wide { max-width: 760px; }
.modal h3 { margin: 0; padding: 18px 22px 6px; font-weight: 500; font-size: 19px; }
.modal .body { padding: 8px 22px 6px; } .modal .foot { padding: 14px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; }
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); z-index: 95; display: grid; place-items: center; }
.viewer img { max-width: 94vw; max-height: 92vh; }
.field { margin: 10px 0; } .field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--input); outline: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.check input { margin-top: 3px; }
.tplbox { background: var(--wallpaper); padding: 12px; border-radius: 8px; margin: 8px 0; }
.tplbox .msg { max-width: 100%; align-self: auto; }

/* ---------- manager screens ---------- */
.page { flex: 1; min-width: 0; overflow-y: auto; background: var(--header); }
.page-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 14px 24px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; }
.page-body { padding: 18px 24px 40px; max-width: 1100px; margin: 0 auto; }
.panel { background: var(--panel); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 4px; font-size: 16px; } .panel p.muted { margin: 0 0 10px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--panel); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 600; } .stat .l { color: var(--muted); font-size: 13px; }
.bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 8px 0; } .bar i { display: block; height: 100%; background: var(--accent); }
.bar.warn i { background: #f59f00; } .bar.bad i { background: var(--danger); }
table.t { width: 100%; border-collapse: collapse; } table.t th { text-align: left; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; } table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--hover); }
.tag { display: inline-block; background: var(--chip); border-radius: 10px; padding: 1px 9px; font-size: 12px; margin: 1px 3px 1px 0; }
.status { display: inline-block; border-radius: 10px; padding: 2px 10px; font-size: 12px; font-weight: 600; background: var(--chip); }
.status.running { background: var(--chip-on); color: var(--chip-on-text); } .status.paused { background: var(--warn); color: var(--warn-text); } .status.done { background: var(--chip); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--input); }
.days { display: grid; grid-template-columns: 70px 1fr 1fr 40px; gap: 8px; align-items: center; margin: 4px 0; }
.rule { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.chart { width: 100%; height: 170px; } .chart rect.in { fill: #8696a0; } .chart rect.out { fill: var(--accent); } .chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ---------- small screens: one pane at a time ---------- */
@media (max-width: 900px) {
  #app { flex-direction: column-reverse; }
  .rail { width: 100%; height: 56px; flex-direction: row; justify-content: space-around; padding: 0 6px; border-right: 0; border-top: 1px solid var(--line); }
  .rail .spacer { display: none; }
  .view { flex-direction: column; min-height: 0; }
  .col-list { width: 100%; max-width: 100%; border-right: 0; flex: 1; min-height: 0; }
  .col-chat { position: absolute; inset: 0 0 56px 0; z-index: 20; border-bottom: 0; }
  body.no-chat .col-chat { display: none; } body:not(.no-chat) .col-list { display: none; }
  .back { display: grid; }
  .col-info { position: absolute; inset: 0 0 56px 0; width: 100%; z-index: 30; border-left: 0; }
  .msgs { padding: 10px 10px 6px; } .msg { max-width: 86%; }
  .page-body { padding: 12px 12px 30px; }
  .days { grid-template-columns: 56px 1fr 1fr 34px; }
}

.page-head select, .page-head input { padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--input); }
.chat-head .t bdi, .row .name bdi { unicode-bidi: isolate; }
.closed-bar .why { color: var(--muted); }
