:root {
  --bg: #f4f6f5; --surface: #fff; --text: #14201b; --muted: #66756e; --line: #e2e8e5;
  --brand: #0b8f6a; --brand-d: #077a59; --brand-l: #e3f5ee;
  --warn: #b7791f; --warn-l: #fdf3dc; --err: #c53030; --err-l: #fde8e8; --info: #2b6cb0; --info-l: #e6f0fb;
  --bubble-in: #fff; --bubble-out: #d9fdd3; --chat-bg: #efeae2;
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --surface: #162019; --text: #e8f0ec; --muted: #8fa399; --line: #25332b;
    --brand: #19b387; --brand-d: #14a07a; --brand-l: #12362c;
    --warn-l: #3a2f12; --err-l: #3d1a1a; --info-l: #14283d;
    --bubble-in: #1f2c27; --bubble-out: #144d3a; --chat-bg: #0b1210;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Cairo, system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--err); font-size: 13px; min-height: 18px; }
a { color: var(--brand); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }

.logo { font-weight: 700; font-size: 22px; letter-spacing: -.5px; padding: 4px 12px 18px; direction: ltr; text-align: right; }
.logo span { color: var(--brand); } .logo.big { font-size: 34px; text-align: center; padding: 0 0 4px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 28px; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
#nav { display: grid; gap: 2px; flex: 1; align-content: start; }
#nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
#nav a:hover { background: var(--bg); }
#nav a.on { background: var(--brand-l); color: var(--brand); }
#nav .badge { margin-inline-start: auto; background: var(--brand); color: #fff; border-radius: 99px; font-size: 12px; padding: 0 8px; }
main { padding: 24px 28px 48px; min-width: 0; }
.banner { background: var(--warn-l); color: var(--warn); border: 1px solid var(--warn); padding: 8px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.grid { display: grid; gap: 14px; } .g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } .g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi .n { font-size: 28px; font-weight: 700; line-height: 1.2; } .kpi .l { color: var(--muted); font-size: 13px; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 9px; cursor: pointer; transition: background .15s, transform .05s; }
.btn:hover { background: var(--bg); } .btn:active { transform: scale(.98); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--err); } .btn.ghost { background: transparent; } .btn.small { padding: 3px 10px; font-size: 13px; } .btn.block { width: 100%; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 4px; }
.field { margin-bottom: 12px; } .hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; } .tbl-wrap { overflow-x: auto; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--brand-l); color: var(--brand); } .pill.warn { background: var(--warn-l); color: var(--warn); }
.pill.bad { background: var(--err-l); color: var(--err); } .pill.info { background: var(--info-l); color: var(--info); }
.tag { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 7px; font-size: 12px; margin: 1px; }
.tag.sel { background: var(--brand); color: #fff; border-color: var(--brand); cursor: pointer; } .tag.pick { cursor: pointer; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; display: flex; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--brand); } .bar i.r { background: #2b6cb0; } .bar i.f { background: var(--err); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .b { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; background: var(--brand); min-height: 2px; } .chart .b.in { background: #8bb8ff; }
.chart small { color: var(--muted); font-size: 11px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; display: grid; gap: 8px; z-index: 99; }
.toast { background: #14201b; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); max-width: 380px; font-size: 14px; }
.toast.bad { background: var(--err); }

/* WhatsApp preview + chat */
.phone { background: var(--chat-bg); border-radius: 14px; padding: 14px; border: 1px solid var(--line); }
.bubble { background: var(--bubble-in); border-radius: 10px; padding: 8px 10px; max-width: 320px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.bubble .h { font-weight: 700; margin-bottom: 4px; } .bubble .f { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bubble .media { background: var(--line); height: 120px; border-radius: 6px; margin-bottom: 6px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.bubble .var { background: var(--warn-l); color: var(--warn); border-radius: 4px; padding: 0 3px; }
.pbtn { background: var(--bubble-in); color: #1a73e8; text-align: center; border-radius: 8px; margin-top: 4px; padding: 6px; max-width: 320px; font-weight: 600; font-size: 14px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); }
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; } @media (max-width: 800px) { .split { grid-template-columns: 1fr; } }

.inbox { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 170px); min-height: 420px; padding: 0; overflow: hidden; }
.convs-col { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.convs { overflow: auto; flex: 1; }
.conv { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 1px; }
.conv:hover { background: var(--bg); } .conv.on { background: var(--brand-l); }
.conv .top { display: flex; justify-content: space-between; gap: 6px; font-weight: 600; } .conv .snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { background: var(--brand); color: #fff; border-radius: 99px; font-size: 12px; padding: 0 7px; }
.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.msgs { flex: 1; overflow: auto; padding: 16px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 6px; }
.m { max-width: 70%; padding: 6px 10px; border-radius: 10px; background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0, 0, 0, .12); white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.m.out { align-self: flex-start; background: var(--bubble-out); } .m.in { align-self: flex-end; }
.m .meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; }
.m .tpl { font-size: 11px; color: var(--brand); font-weight: 700; } .m.failed { outline: 1px solid var(--err); }
.composer { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 120px; }
.closed-note { padding: 10px 14px; background: var(--warn-l); color: var(--warn); font-size: 13px; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; overflow-x: auto; align-items: center; }
  .logo { padding: 0 8px; } #nav { display: flex; } #nav a { white-space: nowrap; } main { padding: 16px; }
  .inbox { grid-template-columns: 1fr; height: auto; } .convs { max-height: 240px; }
}

/* team + assignment */
.userbox { border-top: 1px solid var(--line); padding: 12px 10px 6px; display: grid; gap: 4px; margin-top: 8px; }
.userbox .uname { font-weight: 700; } .avail { display: flex; gap: 6px; align-items: center; font-size: 12px; font-weight: 400; margin: 2px 0; }
.avail input { width: auto; } tr.dim td { opacity: .5; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; font: inherit; font-size: 13px; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 4px; cursor: pointer; color: var(--muted); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); } .tabs .cnt { background: var(--bg); border-radius: 99px; padding: 0 6px; font-size: 11px; }
.conv .who { font-size: 12px; color: var(--muted); }
.chat-head select { width: auto; padding: 4px 8px; font-size: 13px; }
.evt { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 2px 12px; }
.note-b { align-self: center; max-width: 80%; background: var(--warn-l); color: var(--text); border: 1px dashed var(--warn); border-radius: 10px; padding: 6px 12px; font-size: 13px; white-space: pre-wrap; }
.composer-wrap { border-top: 1px solid var(--line); } .composer-wrap.note { background: var(--warn-l); }
.composer-wrap .composer { border-top: 0; padding-top: 4px; }
.mode { display: flex; gap: 4px; padding: 6px 10px 0; } .mode button { font: inherit; font-size: 12px; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 2px 10px; border-radius: 99px; cursor: pointer; }
.mode button.on { background: var(--brand-l); color: var(--brand); } .composer-wrap.note .mode button.on { background: var(--warn); color: #fff; }
