/* =====================================================================
   Primeavest — operations console
   Desktop ≥1200: full sidebar · Tablet/iPad 768–1199: icon rail · Phone <768: top bar + bottom tabs
   ===================================================================== */
body { min-height: 100vh; overflow-x: hidden; }
.muted { color: var(--muted); } .dim { color: var(--dim); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(700px 400px at 50% 15%, rgba(201,169,97,.12), transparent 60%); }
.login-card { width: min(420px, 100%); border: 1px solid var(--line-2); border-radius: 24px; padding: 40px; background: var(--bg-2); box-shadow: var(--shadow); }
.login-card h1 { font-size: 40px; margin: 18px 0 26px; }
.login-card .field { margin-bottom: 14px; }
@media (max-width: 767px) { .login-card { padding: 28px 22px; } .login-card h1 { font-size: 34px; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 24px 16px; background: var(--bg-2); display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { margin: 0 10px 26px; }
.side .brand-name { font-size: 17px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-size: 14px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; position: relative; }
.nav-item svg { flex: none; width: 19px; height: 19px; }
.nav-item:hover { color: var(--text); background: var(--panel); }
.nav-item.active { color: var(--text); background: var(--panel-2); box-shadow: inset 2px 0 0 var(--gold); }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--dim); }
.nav-item .count.hot { background: var(--gold); color: var(--on-gold); border-radius: 10px; padding: 1px 7px; font-weight: 600; }
.nav-group { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); padding: 18px 12px 6px; }
.side-user { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--gold-soft); border: 1px solid rgba(201,169,97,.4); color: var(--gold-2); display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }
.side-user b { display: block; font-size: 13.5px; font-weight: 500; }
.side-user small { color: var(--dim); font-size: 12px; text-transform: capitalize; }
main { padding: 34px 40px 80px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.top h1 { font-size: 44px; margin-top: 4px; }
.mobile-top, .tabbar { display: none; }

/* tablet: icon rail */
@media (max-width: 1199px) {
  .shell { grid-template-columns: 76px 1fr; }
  .side { padding: 20px 10px; align-items: center; }
  .side .brand { margin: 0 0 20px; }
  .side .brand-name, .nav-item .label, .nav-group, .side-user > div { display: none; }
  .nav-item { justify-content: center; padding: 12px; width: 52px; }
  .nav-item .count { position: absolute; top: 4px; right: 2px; margin: 0; }
  .nav-item .count:not(.hot) { display: none; }
  .side-user { padding: 14px 0 0; justify-content: center; }
  main { padding: 28px 32px 80px; }
  .top h1 { font-size: 38px; }
}
/* phone: top bar + bottom tabs */
@media (max-width: 767px) {
  .shell { display: block; }
  .side { display: none; }
  .mobile-top { display: flex; position: sticky; top: 0; z-index: 40; height: 58px; align-items: center; justify-content: space-between; padding: 0 16px; background: rgba(10,10,12,.92); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
  .mobile-top .brand-name { font-size: 16px; }
  .mobile-top .brand-mark { width: 30px; height: 30px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: rgba(16,16,19,.96); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tab { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--dim); background: none; border: 0; padding: 6px 0; cursor: pointer; position: relative; -webkit-tap-highlight-color: transparent; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--gold-2); }
  .tab .count { position: absolute; top: 0; left: 52%; background: var(--gold); color: var(--on-gold); border-radius: 9px; font-size: 10px; padding: 0 5px; font-weight: 600; min-width: 16px; text-align: center; }
  .tab .count:empty { display: none; }
  main { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  .top { margin-bottom: 18px; align-items: center; }
  .top h1 { font-size: 32px; }
  .top .eyebrow { display: none; }
}

/* ---------- cards / panels ---------- */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; font-weight: 500; color: var(--muted); }
.panel-body { padding: 8px 20px 16px; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; background: var(--bg-2); cursor: pointer; transition: border-color .2s; text-align: left; width: 100%; }
.kpi:hover { border-color: rgba(201,169,97,.45); }
.kpi small { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.kpi b { display: block; font-family: var(--serif); font-weight: 400; font-size: 40px; line-height: 1.1; font-variant-numeric: lining-nums; }
.kpi.warn b { color: var(--amber); }
.dash-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.dash-grid > .panel:last-child:nth-child(odd) { grid-column: 1 / -1; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover .lr-main b { color: var(--gold-2); }
.lr-main { flex: 1; min-width: 0; }
.lr-main b { font-weight: 500; display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-main small { color: var(--dim); font-size: 12.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-side { text-align: right; font-size: 12.5px; color: var(--muted); flex: none; }
.tag { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; border: 1px solid; white-space: nowrap; }
.tag.red { color: var(--red); border-color: rgba(224,122,106,.4); }
.tag.amber { color: var(--amber); border-color: rgba(224,178,90,.4); }
.tag.gold { color: var(--gold-2); border-color: rgba(201,169,97,.4); }
.tag.green { color: var(--green); border-color: rgba(111,191,142,.4); }
.tag.grey { color: var(--muted); border-color: var(--line-2); }
@media (max-width: 1199px) { .kpis { grid-template-columns: repeat(3, 1fr); } .dash-grid { grid-template-columns: 1fr; } }
@media (max-width: 767px) { .kpis { grid-template-columns: 1fr 1fr; gap: 10px; } .kpi { padding: 14px 16px; } .kpi b { font-size: 32px; } .kpis .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; } }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1; min-width: 220px; max-width: 380px; position: relative; }
.toolbar .search input { padding-left: 40px; }
.toolbar .search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--dim); }
.toolbar select.input { width: auto; min-width: 150px; }
.chips { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--gold-soft); border-color: rgba(201,169,97,.5); color: var(--gold-2); }
.chip b { font-weight: 600; margin-left: 4px; }
@media (max-width: 767px) {
  .toolbar .search { max-width: none; min-width: 0; flex-basis: 100%; }
  .toolbar select.input { flex: 1; min-width: 0; }
  .chips { margin-inline: -16px; padding-inline: 16px; }
}

/* ---------- table (desktop/tablet) · cards (phone) ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-2); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); font-weight: 500; padding: 13px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 15px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover { background: var(--panel); }
td .ref { font-family: var(--serif); font-size: 18px; letter-spacing: .02em; font-variant-numeric: lining-nums; }
td small { color: var(--dim); display: block; font-size: 12px; }
.col-tablet-hide { }
@media (max-width: 1199px) { .col-tablet-hide { display: none; } td, th { padding-inline: 12px; } }
.cards { display: none; }
@media (max-width: 767px) {
  .table-wrap { display: none; }
  .cards { display: grid; gap: 10px; }
  .s-card { border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); padding: 16px; cursor: pointer; }
  .s-card:active { background: var(--panel); }
  .s-card header { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
  .s-card .ref { font-family: var(--serif); font-size: 19px; font-variant-numeric: lining-nums; }
  .s-card .route-line { font-size: 14px; }
  .s-card .meta { display: flex; justify-content: space-between; gap: 10px; color: var(--dim); font-size: 12.5px; margin-top: 8px; flex-wrap: wrap; }
}

/* ---------- drawer (editor) ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80; opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(800px, 100%); background: var(--bg-2); border-left: 1px solid var(--line-2); z-index: 90;
  transform: translateX(100%); transition: transform .32s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column; visibility: hidden; }
.drawer.open { transform: none; visibility: visible; }
.drawer-head { padding: 20px 26px 0; border-bottom: 1px solid var(--line); }
.drawer-head .row { justify-content: space-between; align-items: flex-start; flex-wrap: nowrap; }
.drawer-head .ref { font-family: var(--serif); font-size: 30px; line-height: 1.15; margin: 2px 0 4px; font-variant-numeric: lining-nums; word-break: break-all; }
.dtabs { display: flex; gap: 4px; margin-top: 14px; overflow-x: auto; scrollbar-width: none; }
.dtabs::-webkit-scrollbar { display: none; }
.dtab { padding: 10px 14px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.dtab.on { color: var(--text); border-color: var(--gold); }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 26px 30px; overscroll-behavior: contain; }
.drawer-foot { padding: 14px 26px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; background: var(--bg-2); }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: transparent; cursor: pointer; color: var(--muted); display: grid; place-items: center; flex: none; }
.icon-btn:hover { color: var(--text); border-color: var(--gold); }
.icon-btn.danger:hover { color: var(--red); border-color: rgba(224,122,106,.5); }
.sec { margin-bottom: 26px; }
.sec h4 { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); font-weight: 500; margin-bottom: 12px; }
.sec h4 span { color: var(--dim); letter-spacing: 0; text-transform: none; }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.g3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.g2 .full, .g3 .full { grid-column: 1 / -1; }
.field textarea { min-height: 80px; }
.btn-danger { border-color: rgba(224,122,106,.4); color: var(--red); background: transparent; }
.btn-danger:hover { background: rgba(224,122,106,.08); }
@media (max-width: 1199px) { .drawer { width: min(720px, 100%); } }
@media (max-width: 767px) {
  .drawer { width: 100%; border-left: 0; }
  .drawer-head { padding: 14px 16px 0; }
  .drawer-head .ref { font-size: 24px; }
  .drawer-body { padding: 18px 16px 24px; }
  .drawer-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .drawer-foot .btn { flex: 1; }
  .g2, .g3 { grid-template-columns: 1fr; }
}
@media (min-width: 768px) and (max-width: 1199px) { .g3 { grid-template-columns: 1fr 1fr; } }

/* timeline editor */
.ev { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; background: var(--panel); }
.ev-row { display: grid; grid-template-columns: 1.15fr 1fr 1.1fr auto; gap: 8px; align-items: center; }
.ev textarea { margin-top: 8px; min-height: 52px !important; resize: vertical; }
.ev .input { padding: 9px 11px; font-size: 13.5px; min-height: 42px; }
.ev.new { border-style: dashed; border-color: rgba(201,169,97,.45); background: rgba(201,169,97,.04); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 10px; cursor: pointer; }
.check input { accent-color: var(--gold); width: 16px; height: 16px; }
@media (max-width: 767px) { .ev-row { grid-template-columns: 1fr 1fr; } .ev-row .loc { grid-column: 1 / -1; } .ev .input { font-size: 16px; } }

/* ---------- chat ---------- */
.chat-admin { display: grid; grid-template-columns: 320px 1fr; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); height: calc(100vh - 170px); min-height: 480px; overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; }
.chat-item { padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-item:hover { background: var(--panel); }
.chat-item.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--gold); }
.chat-item header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-item b { font-weight: 500; }
.chat-item p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item small { color: var(--dim); font-size: 11.5px; }
.chat-item .unread { background: var(--gold); color: var(--on-gold); border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.chat-item.closed { opacity: .55; }
.chat-convo { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-convo-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.chat-convo-head small { color: var(--muted); display: block; font-size: 12px; }
.chat-convo .chat-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.back-btn { display: none; }
@media (max-width: 1199px) { .chat-admin { grid-template-columns: 270px 1fr; } }
@media (max-width: 767px) {
  .chat-admin { display: block; height: auto; min-height: 0; border: 0; background: none; overflow: visible; }
  .chat-list { border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); }
  .chat-admin.convo-open .chat-list { display: none; }
  .chat-admin:not(.convo-open) .chat-convo { display: none; }
  .chat-admin.convo-open .chat-convo { position: fixed; inset: 0; z-index: 70; background: var(--bg-2); }
  .back-btn { display: grid; }
  .chat-convo-head { padding: 10px 12px; flex-wrap: nowrap; }
  .chat-convo-head .acts .btn { padding: 0 12px; }
  .chat-convo .chat-input { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .chat-convo .chat-input textarea { font-size: 16px; }
}

/* ---------- enquiries / activity / users ---------- */
.inq { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px; background: var(--bg-2); }
.inq header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; align-items: flex-start; }
.inq p.msg-text { color: var(--text); white-space: pre-wrap; font-size: 14.5px; }
.inq .inq-foot { display: grid; grid-template-columns: 180px 1fr auto; gap: 10px; margin-top: 14px; align-items: center; }
@media (max-width: 767px) { .inq .inq-foot { grid-template-columns: 1fr; } .inq { padding: 16px; } }
.act-row { display: grid; grid-template-columns: 170px 160px 1fr; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.act-row:last-child { border-bottom: 0; }
.act-row .when { color: var(--dim); }
.act-row .who { color: var(--gold-2); }
@media (max-width: 767px) { .act-row { grid-template-columns: 1fr; gap: 2px; padding: 12px 16px; } }
.user-row { display: flex; gap: 14px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row:last-child { border-bottom: 0; }
.user-row .lr-main { min-width: 160px; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.65); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.open { display: flex; }
.modal { width: min(480px, 100%); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 20px; padding: 26px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal h3 { font-family: var(--serif); font-weight: 400; font-size: 28px; margin-bottom: 16px; }
.modal .field { margin-bottom: 12px; }
.modal .row { justify-content: flex-end; margin-top: 18px; }
@media (max-width: 767px) { .modal-bg { align-items: flex-end; padding: 0; } .modal { border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); } }

/* "More" sheet on phones */
.more-sheet .nav-item { padding: 14px 8px; font-size: 15px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1199px) { .settings-grid { grid-template-columns: 1fr; } }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 14px; }
.switch input { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line-2); position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.switch input:checked { background: var(--gold); }
.switch input:checked::after { transform: translateX(18px); background: var(--on-gold); }

/* layout hardening */
.dash-grid > *, .kpis > *, .settings-grid > *, main > * { min-width: 0; }
td .ref, td.nowrap { white-space: nowrap; }
@media (max-width: 767px) {
  .s-card header { flex-wrap: wrap; }
  .s-card .ref { white-space: nowrap; }
  .panel-head { padding: 14px 16px; }
  .panel-body { padding: 4px 16px 12px; }
}
@media (max-width: 767px) {
  .chat-convo-head .acts { flex-wrap: nowrap; gap: 6px; }
  .chat-convo-head .acts .btn { height: 34px; padding: 0 10px; font-size: 10px; letter-spacing: .08em; }
  .chat-convo-head .acts .icon-btn { width: 34px; height: 34px; }
}
