:root {
  --navy: #1d4f9c; --sky: #2a9fd8; --ink: #14233a; --muted: #66758c; --line: #dfe5ee;
  --bg: #f3f6fa; --card: #fff; --ok: #1b8a5a; --warn: #c27c0e; --bad: #c0392b;
  --r: 10px; --shadow: 0 1px 2px rgba(20,35,58,.06), 0 4px 16px rgba(20,35,58,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--navy); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); font-weight: 400; }
small { color: var(--muted); font-weight: 400; }

/* layout */
body.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #fff; border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.brand img { width: 100%; max-width: 190px; display: block; }
.tag { color: var(--muted); font-size: 12px; margin: 4px 2px 22px; letter-spacing: .02em; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side nav a span { width: 18px; text-align: center; color: var(--muted); }
.side nav a:hover { background: var(--bg); }
.side nav a.on { background: #e8f0fb; color: var(--navy); }
.side nav a.on span { color: var(--navy); }
.logout { margin-top: auto; }
.logout button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 8px 12px; font: inherit; }
.main { padding: 28px 32px 60px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.sub { margin: 4px 0 0; color: var(--muted); }
.back { font-size: 13px; text-decoration: none; display: inline-block; margin-bottom: 6px; }
.actions { display: flex; gap: 8px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #c4cfdd; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: #17427f; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd3f3; border-color: var(--navy); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ok { color: var(--ok); font-weight: 600; margin: 0 0 8px; }
.banner { background: #e7f6ee; padding: 10px 14px; border-radius: 8px; }
.err { color: var(--bad); }

/* list */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.hl { border-color: #b9d1f2; background: #f2f7fe; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input { max-width: 340px; }
.filters select { width: auto; }
.table-wrap { padding: 0; overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid #eef1f6; vertical-align: top; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: #f7faff; }
.tbl td small { display: block; }
.tbl a { text-decoration: none; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px !important; cursor: default; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; background: #eef1f6; color: var(--muted); }
.pill.sim { background: #fff3dc; color: var(--warn); text-transform: none; font-size: 11px; }
.s-new { background: #e3eefc; color: var(--navy); }
.s-contacted { background: #efe8fb; color: #6a3fb5; }
.s-scheduled { background: #fff3dc; color: var(--warn); }
.s-installed { background: #e3f5ec; color: var(--ok); }
.s-cancelled { background: #fbe9e7; color: var(--bad); }

/* detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.panel { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 20px; }
.panel textarea { margin-bottom: 10px; resize: vertical; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.seg input { display: none; }
.seg span { display: inline-block; padding: 5px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; cursor: pointer; opacity: .55; border: 1px solid transparent; }
.seg input:checked + span { opacity: 1; border-color: currentColor; }
.transcript { max-height: 460px; overflow: auto; display: flex; flex-direction: column; gap: 6px; background: #efeae2; padding: 10px; border-radius: 8px; }
.msg { max-width: 88%; padding: 6px 9px; border-radius: 8px; font-size: 12.5px; box-shadow: 0 1px 0 rgba(0,0,0,.06); unicode-bidi: plaintext; }
.msg.out { background: #fff; align-self: flex-start; }
.msg.in { background: #d9fdd3; align-self: flex-end; }
.msg time { display: block; font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }

/* form sheet (replica of the paper form) */
.sheet-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 28px; overflow: auto; }
.sheet { width: 100%; max-width: 820px; margin: 0 auto; font-size: 12px; color: #111; }
.sheet-logo { width: 62%; display: block; margin: 0 0 10px; }
.bar { background: var(--navy); color: #fff; padding: 3px 8px; font-weight: 600; letter-spacing: .02em; margin-top: 8px; }
.bar.center { text-align: center; font-size: 14px; position: relative; }
.bar .ref { position: absolute; right: 8px; font-family: ui-monospace, monospace; font-weight: 500; font-size: 11px; top: 5px; opacity: .85; }
.bar.split { display: flex; justify-content: space-between; }
.bar.sm { margin: 0 0 4px; font-weight: 500; }
.sec-title { font-weight: 700; padding: 6px 0 2px; }
.grid2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 6px 22px; padding: 2px 0 6px; }
.ff { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 6px; margin: 4px 0; }
.ff label { font-weight: 500; }
.fv { border: 1px solid #9aa6b8; min-height: 22px; padding: 2px 6px; background: #fbfcfe; font-weight: 600; color: #0b2a5c; overflow-wrap: anywhere; }
.grid-plan { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border: 1px solid var(--navy); }
.plans { border-collapse: collapse; width: 100%; }
.plans th { background: var(--navy); color: #fff; padding: 2px 4px; font-weight: 600; }
.plans td { border: 1px solid #b8c3d4; padding: 2px 6px; text-align: center; }
.plans td:first-child { text-align: left; white-space: nowrap; }
.opts > div:not(.bar) { padding: 2px 6px; }
.cb { display: inline-flex; width: 13px; height: 13px; border: 1px solid #333; vertical-align: -2px; margin-right: 6px; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; line-height: 1; }
.cb.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.row-note { display: flex; justify-content: space-between; padding: 3px 2px; }
ol.ar { margin: 4px 0; padding-right: 22px; font-size: 12.5px; }
ol.ar li { margin: 2px 0; }
.pay { display: flex; gap: 40px; padding: 4px 4px; flex-wrap: wrap; }
ol.info { margin: 4px 0; padding-left: 22px; font-weight: 600; }
ol.info li { margin: 1px 0; }
.deleg { font-size: 12.5px; line-height: 1.9; margin: 6px 0; }
.deleg u { text-decoration: none; border-bottom: 1px dotted #333; padding: 0 6px; font-weight: 700; color: #0b2a5c; }
.sig { display: grid; grid-template-columns: 1.6fr 1fr; border: 1px solid var(--navy); margin-top: 8px; }
.sig-l { padding: 6px 8px; border-right: 1px solid var(--navy); display: flex; flex-direction: column; }
.sig-l p { margin: 0 0 6px; }
.accepted { color: var(--ok); font-weight: 600; font-size: 11px; }
.sig-lines { display: flex; justify-content: space-between; margin-top: auto; padding-top: 20px; font-weight: 600; }
.sig-r { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.sig-r > div { display: flex; gap: 14px; }
.sig-r span { font-weight: 700; min-width: 80px; }
.mss { margin-top: 8px; align-items: center; justify-content: space-between; border-top: 1px solid var(--navy); padding-top: 6px; }
.mss img { width: 58px; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.tbl.edit td { padding: 6px 8px; cursor: default; }
.tbl.edit tbody tr:hover td { background: none; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid3 label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
.span2 { grid-column: span 2; }

/* login */
body.bare { display: grid; place-items: center; min-height: 100vh; }
.login { background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 30px; width: min(380px, 92vw); display: flex; flex-direction: column; gap: 14px; }
.login img { width: 85%; align-self: center; }
.login h1 { font-size: 16px; text-align: center; color: var(--muted); font-weight: 500; margin: 0 0 6px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
.login .btn { justify-content: center; padding: 10px; }

/* simulator */
.sim { display: grid; grid-template-columns: 400px 1fr; gap: 24px; align-items: start; }
.phone { position: relative; height: min(760px, calc(100vh - 150px)); min-height: 520px; border-radius: 22px; overflow: hidden; display: flex; flex-direction: column; border: 8px solid #1b1f24; box-shadow: 0 10px 40px rgba(20,35,58,.18); background: #efeae2; }
.phone-top { background: #075e54; color: #fff; display: flex; gap: 10px; align-items: center; padding: 10px 12px; }
.phone-top img { width: 36px; height: 36px; border-radius: 50%; background: #fff; object-fit: contain; padding: 3px; }
.phone-top small { display: block; color: #cfe9e4; font-size: 11px; }
.chat { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 84%; background: #fff; padding: 7px 9px 5px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 1px 0 rgba(0,0,0,.08); unicode-bidi: plaintext; white-space: normal; }
.bubble.me { align-self: flex-end; background: #d9fdd3; }
.bubble.bot { align-self: flex-start; }
.bubble .qbtns { display: flex; flex-direction: column; margin: 6px -9px -5px; border-top: 1px solid #eee; }
.bubble .qbtns button { background: none; border: 0; border-top: 1px solid #f0f0f0; color: #0a7cff; font: inherit; font-weight: 500; padding: 8px; cursor: pointer; }
.bubble .qbtns button:first-child { border-top: 0; }
.bubble .qbtns button:disabled { color: #9aa; cursor: default; }
.sheet-pop { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18); padding: 10px 0 14px; max-height: 70%; overflow: auto; z-index: 2; }
.sheet-pop h4 { margin: 4px 16px 8px; font-size: 14px; }
.sheet-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid #f1f1f1; padding: 10px 16px; font: inherit; cursor: pointer; }
.sheet-pop button:hover { background: #f5f8fb; }
.sheet-pop button small { display: block; }
.composer { display: flex; gap: 6px; padding: 8px; background: #f0f2f5; }
.composer input { border-radius: 20px; border: 0; padding: 9px 14px; }
.composer button { border: 0; background: none; font-size: 18px; cursor: pointer; padding: 0 6px; }
.composer .send { background: #00a884; color: #fff; border-radius: 50%; width: 38px; height: 38px; flex: none; font-size: 15px; }
.sim-help ul { padding-left: 18px; }
.sim-help li { margin: 4px 0; }
.typing { align-self: flex-start; color: var(--muted); font-size: 12px; padding: 2px 6px; }

/* nav badge */
.badge { margin-left: auto; background: var(--navy); color: #fff; font-size: 11px; border-radius: 99px; padding: 1px 7px; font-weight: 700; }
.badge.alert { background: var(--bad); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.check input { width: auto; }
.span3 { grid-column: 1 / -1; }
.pad { padding: 16px; margin: 0; }
.bubble .who, .cv-msg .who { display: block; font-size: 11.5px; font-weight: 700; color: #0b7a5f; margin-bottom: 2px; }

/* live chat inbox */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; height: calc(100vh - 56px); min-height: 520px; }
.inbox .card { padding: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.ib-tools { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.ib-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ib-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.ib-tabs button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.ib-tabs b { color: inherit; }
.ib-items { overflow-y: auto; flex: 1; }
.ib-item { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eef1f6; background: #fff; padding: 11px 12px; cursor: pointer; font: inherit; color: inherit; }
.ib-item:hover { background: #f7faff; }
.ib-item.on { background: #e8f0fb; }
.ib-item.waiting { box-shadow: inset 3px 0 0 var(--bad); }
.av { flex: none; width: 38px; height: 38px; border-radius: 50%; background: #dbe6f5; color: var(--navy); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.ib-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ib-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ib-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-row time { color: var(--muted); font-size: 11.5px; flex: none; }
.ib-last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.unread { background: #25d366; color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; flex: none; }
.ib-tags { display: flex; gap: 4px; margin-top: 2px; }
.t { font-style: normal; font-size: 11px; font-weight: 600; border-radius: 99px; padding: 1px 8px; background: #eef1f6; color: var(--muted); }
.t.wait { background: #fbe9e7; color: var(--bad); }
.t.agent { background: #e3f5ec; color: var(--ok); }
.t.bot { background: #e3eefc; color: var(--navy); }
.t.ref { font-family: ui-monospace, monospace; }
.ib-empty { margin: auto; text-align: center; color: var(--muted); max-width: 380px; padding: 30px; }
.ib-empty b { color: var(--ink); font-size: 16px; }
.cv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cv-back { display: none; padding: 6px 10px; }
.cv-who { display: flex; flex-direction: column; min-width: 0; }
.cv-who small { font-family: ui-monospace, monospace; }
.cv-state { margin-left: 8px; }
.cv-state .t { font-size: 12px; padding: 3px 10px; }
.cv-actions { margin-left: auto; display: flex; gap: 8px; }
.cv-msgs { flex: 1; overflow-y: auto; background: #efeae2; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.cv-msg { max-width: 72%; padding: 6px 10px 4px; border-radius: 8px; box-shadow: 0 1px 0 rgba(0,0,0,.07); unicode-bidi: plaintext; font-size: 13.5px; }
.cv-msg time { display: block; text-align: right; font-size: 10.5px; color: var(--muted); }
.cv-msg.in { align-self: flex-start; background: #fff; }
.cv-msg.bot { align-self: flex-end; background: #f4f6f9; color: #3c4a5e; }
.cv-msg.bot .who { color: var(--navy); }
.cv-msg.agent { align-self: flex-end; background: #d9fdd3; }
.cv-sys { align-self: center; background: #fff8d6; color: #6b5a12; font-size: 12px; border-radius: 6px; padding: 3px 10px; }
.cv-warn { background: #fff3dc; color: #7a4d06; padding: 8px 14px; font-size: 13px; border-top: 1px solid #f1dfb6; }
.quick { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; }
.quick button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted); unicode-bidi: plaintext; }
.quick button:hover { border-color: var(--navy); color: var(--navy); }
.cv-compose { display: flex; gap: 8px; padding: 10px 12px 12px; align-items: flex-end; }
.cv-compose textarea { resize: none; min-height: 40px; max-height: 160px; unicode-bidi: plaintext; }
.cv-compose .btn { height: 40px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 900px) {
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 120px); }
  .inbox .ib-conv { display: none; }
  .inbox.has-conv .ib-list { display: none; }
  .inbox.has-conv .ib-conv { display: flex; }
  .cv-back { display: inline-flex; }
  .cv-msg { max-width: 88%; }
}

@media (max-width: 1100px) {
  .detail, .sim { grid-template-columns: 1fr; }
  .panel { position: static; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  body.app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .brand img { max-width: 150px; } .tag { display: none; }
  .side nav { flex-direction: row; } .logout { margin: 0 0 0 auto; }
  .main { padding: 18px 16px 40px; }
  .filters { flex-wrap: wrap; } .grid3 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sheet-wrap { padding: 12px; } .grid2, .grid-plan, .sig { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body.app { display: block; background: #fff; }
  .no-print { display: none !important; }
  .main { padding: 0; }
  .detail { display: block; }
  .sheet-wrap { border: 0; box-shadow: none; padding: 0; }
  .sheet { max-width: none; font-size: 10.5px; }
  .bar, .plans th, .cb.on { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
