/* Kalem Inbox — colours and sizes live in these variables; change them here to restyle the app. */
:root {
  --navy: #0b1f3a;
  --navy-2: #13294b;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --amber: #f5b301;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --bubble-in: #ffffff;
  --bubble-out: #dcf3ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --font: 'IBM Plex Sans', 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 4px 0; }
.row { display: flex; align-items: center; justify-content: space-between; }
.row.gap { gap: 8px; justify-content: flex-start; }
.row.end { justify-content: flex-end; }
[dir="auto"] { unicode-bidi: plaintext; }

/* buttons & inputs */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #c7d0dd; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4fd8; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; width: 36px; height: 36px; border-radius: 8px; display: inline-grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--bg); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
select { cursor: pointer; }

/* brand */
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--amber); color: var(--navy); display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; margin: 0 auto 12px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; background: var(--navy); padding: 16px; }
.login-card { background: #fff; width: 100%; max-width: 360px; border-radius: 16px; padding: 32px 28px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: grid; gap: 4px; text-align: left; font-weight: 500; font-size: 13px; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.rail { width: 72px; background: var(--navy); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 0; flex: none; }
.rail .brand-mark { margin-bottom: 14px; }
.rail-btn { width: 60px; border: 0; background: transparent; color: #9fb0c8; cursor: pointer; border-radius: 10px; padding: 8px 0; display: grid; justify-items: center; gap: 2px; font-size: 11px; }
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { color: #fff; background: var(--navy-2); }
.rail-btn.active { color: #fff; background: var(--navy-2); box-shadow: inset 3px 0 0 var(--amber); }
.rail-spacer { flex: 1; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; margin-bottom: 8px; }
.conn-dot.on { background: #22c55e; }
.view { flex: 1; min-width: 0; }

/* inbox columns */
.inbox { display: flex; height: 100%; }
.list-pane { width: 360px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; border-bottom: 1px solid var(--line); }
.list-head > * { min-width: 0; }
#search { width: 100%; }
.list-head h2 { margin: 0; font-size: 18px; }
.list-head select { flex: 1; min-width: 0; padding: 6px 8px; font-size: 13px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.number-strip { display: flex; gap: 6px; padding: 6px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.number-strip:empty { display: none; }
.num-pill { font-size: 11.5px; border-radius: 999px; padding: 2px 8px; background: var(--bg); display: inline-flex; align-items: center; gap: 5px; }
.num-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.num-pill.open i { background: var(--ok); }
.num-pill.bad i { background: var(--danger); }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f1f4f8; position: relative; }
.chat-item:hover { background: #f8fafc; }
.chat-item.active { background: var(--blue-soft); }
.chat-item .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.chat-main { flex: 1; min-width: 0; }
.chat-top, .chat-bottom { display: flex; align-items: center; gap: 6px; }
.chat-name, .chat-preview, .convo-title .name { text-align: left; }
.chat-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { font-size: 11.5px; color: var(--muted); flex: none; }
.chat-item.unread .chat-time { color: var(--blue); font-weight: 600; }
.chat-preview { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-item.unread .chat-preview { color: var(--text); }
.badge { background: var(--blue); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; flex: none; }
.chat-meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 11px; border-radius: 4px; padding: 1px 6px; color: #fff; line-height: 16px; white-space: nowrap; }
.tag.num { background: var(--bg); color: var(--muted); }
.tag.who { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #cbd5e1; color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; font-size: 15px; }
.avatar.small { width: 32px; height: 32px; font-size: 13px; background: var(--amber); color: var(--navy); }
.empty { color: var(--muted); text-align: center; padding: 30px; }
.empty.big { margin: auto; }

/* conversation */
.convo-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #eef2f7; }
.convo { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.convo-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.convo-title { flex: 1; min-width: 0; }
.convo-title .name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-title .sub { font-size: 12px; color: var(--muted); }
.convo-head select { max-width: 170px; font-size: 13px; padding: 6px 8px; }
.back-btn { display: none; font-size: 28px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; background: #dfe6ef; color: #475569; font-size: 11.5px; padding: 3px 10px; border-radius: 999px; margin: 10px 0 6px; }
.load-older { align-self: center; margin-bottom: 6px; }
.msg { max-width: min(560px, 78%); align-self: flex-start; background: var(--bubble-in); border-radius: 10px; padding: 6px 9px 4px; box-shadow: 0 1px 1px rgba(15, 23, 42, .06); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .text { white-space: pre-wrap; }
.msg .meta { display: flex; justify-content: flex-end; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .by { color: #0369a1; font-weight: 500; }
.msg .ticks.read { color: #0ea5e9; }
.msg .ticks.err { color: var(--danger); }
.msg.deleted .text { font-style: italic; color: var(--muted); }
.msg .quote { border-left: 3px solid var(--blue); background: rgba(15, 23, 42, .05); border-radius: 6px; padding: 4px 8px; font-size: 12.5px; color: #334155; margin-bottom: 4px; max-height: 60px; overflow: hidden; }
.msg .reaction { position: absolute; bottom: -12px; right: 8px; background: #fff; border-radius: 999px; padding: 0 5px; font-size: 13px; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.msg.has-reaction { margin-bottom: 12px; }
.msg img.media { display: block; max-width: 100%; max-height: 340px; border-radius: 6px; cursor: zoom-in; background: #e2e8f0; min-width: 120px; min-height: 80px; }
.msg img.sticker { max-width: 150px; background: transparent; cursor: default; }
.msg video.media { max-width: 100%; max-height: 340px; border-radius: 6px; background: #000; }
.msg audio { width: 260px; max-width: 100%; height: 40px; display: block; }
.msg .doc { display: flex; align-items: center; gap: 10px; padding: 8px; background: rgba(15, 23, 42, .05); border-radius: 8px; text-decoration: none; color: inherit; }
.msg .doc .ic { font-size: 22px; }
.msg .doc .dn { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.msg .media-missing { font-size: 12.5px; color: var(--muted); padding: 6px 0; }
.msg .actions { position: absolute; top: 2px; right: -30px; display: none; }
.msg.out .actions { right: auto; left: -30px; }
.msg:hover .actions { display: block; }
.msg .actions button { border: 0; background: #fff; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); font-size: 12px; }
.msg.flash { animation: flash 1.2s; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--amber); } }
a { color: var(--blue); }
.reply-bar, .file-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 14px; background: #fff; border-top: 1px solid var(--line); font-size: 13px; }
.reply-bar span { color: var(--muted); }
.doc-toggle { display: flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: 40px; line-height: 1.4; }
.recording { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: #fff7e6; border-top: 1px solid var(--line); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.recording .muted { flex: 1; }
.offline-bar { background: #fef2f2; color: #991b1b; padding: 8px 14px; font-size: 13px; border-top: 1px solid #fecaca; }

/* details pane */
.info-pane { width: 320px; flex: none; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.info-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.info-head h3 { margin: 0; font-size: 15px; }
.info-body { padding: 14px; overflow-y: auto; display: grid; gap: 10px; align-content: start; }
.info-body h4 { margin: 8px 0 0; font-size: 13px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.label-list { display: flex; flex-wrap: wrap; gap: 6px; }
.label-list .tag { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; padding: 3px 8px; }
.label-list .tag button { border: 0; background: transparent; color: #fff; cursor: pointer; padding: 0; font-size: 12px; opacity: .8; }
.notes { display: grid; gap: 8px; }
.note { background: #fffbea; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.note .nb { white-space: pre-wrap; }
.note .nm { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; }
.note .nm button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.note-form { display: grid; gap: 6px; }
.note-form textarea { resize: vertical; }
.info-actions { display: flex; gap: 8px; margin-top: 8px; }

/* admin pages */
.page { padding: 24px 32px; overflow-y: auto; height: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.page-head h2 { margin: 0; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.card .top { display: flex; align-items: center; gap: 10px; }
.card .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.card h3 { margin: 0; font-size: 16px; flex: 1; }
.status { font-size: 12px; border-radius: 999px; padding: 2px 10px; background: var(--bg); color: var(--muted); }
.status.open { background: #dcfce7; color: #166534; }
.status.qr, .status.connecting, .status.reconnecting { background: #fef9c3; color: #854d0e; }
.status.logged_out, .status.qr_expired, .status.new { background: #fee2e2; color: #991b1b; }
.conn-log { background: #0f172a; color: #e2e8f0; padding: 8px; border-radius: 6px; font-size: 11px; white-space: pre-wrap; max-height: 220px; overflow: auto; margin: 6px 0 0; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; align-items: center; }
.inline-form.vertical { flex-direction: column; align-items: stretch; max-width: 360px; }
.inline-form input[type="color"] { width: 44px; padding: 2px; height: 38px; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; }
.table td:last-child { text-align: right; white-space: nowrap; }
.table input { padding: 5px 8px; }
.export-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; max-width: 900px; align-items: end; }
.export-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; }
.export-help { max-width: 760px; }

/* dialogs & toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(420px, 92vw); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(11, 31, 58, .45); }
.dialog-form { padding: 20px; display: grid; gap: 12px; }
.dialog-form h3 { margin: 0; }
.dialog-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; }
.qr-box ol { margin: 0; padding-left: 18px; }
.qr-image { display: grid; place-items: center; min-height: 300px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.qr-image img { width: 280px; height: 280px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.err { background: var(--danger); }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; }

/* mobile: one column at a time */
@media (max-width: 820px) {
  .rail { position: fixed; bottom: 0; left: 0; right: 0; width: auto; height: 58px; flex-direction: row; padding: 0 6px; z-index: 10; justify-content: space-around; }
  .rail .brand-mark, .rail-spacer, .conn-dot { display: none; }
  .rail-btn { width: auto; flex: 1; }
  .rail-btn.active { box-shadow: inset 0 3px 0 var(--amber); }
  .app { padding-bottom: 58px; }
  .list-pane { width: 100%; border-right: 0; }
  .inbox.chat-open .list-pane { display: none; }
  .inbox:not(.chat-open) .convo-pane { display: none; }
  .back-btn { display: inline-grid; }
  .info-pane { position: fixed; inset: 0 0 58px 0; width: auto; z-index: 20; }
  .messages { padding: 12px; }
  .msg { max-width: 88%; }
  .msg .actions { display: block; position: absolute; top: auto; bottom: 2px; right: auto; left: 6px; }
  .msg.out .actions { left: 6px; }
  .msg .actions button { width: 20px; height: 20px; font-size: 10px; box-shadow: none; background: transparent; opacity: .6; }
  .convo-head select { max-width: 110px; }
  .page { padding: 16px; }
}
