/* DR Connect - shared styles for admin and user panels. Mobile first. */
:root {
  --ink: #0d1b2a;
  --ink-2: #1b2b3d;
  --text: #1f2933;
  --muted: #64748b;
  --line: #e3e8ee;
  --bg: #f4f6f8;
  --card: #ffffff;
  --brand: #0b7a5c;
  --brand-dark: #086148;
  --brand-soft: #e3f4ee;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --info: #2563a8;
  --info-soft: #e5effa;
  --radius: 10px;
  --sidebar-w: 236px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; color: var(--ink); line-height: 1.25; }
h1 { font-size: 21px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.hidden { display: none !important; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 54px; background: var(--ink); color: #fff;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
}
.topbar .brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; color: #fff; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand small { font-weight: 400; opacity: .65; margin-left: 6px; font-size: 12px; }
.menu-btn { background: none; border: 0; color: #fff; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.menu-btn:hover { background: rgba(255,255,255,.1); }
.menu-btn span, .menu-btn span::before, .menu-btn span::after { display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px; position: relative; content: ""; }
.menu-btn span::before { position: absolute; top: -6px; } .menu-btn span::after { position: absolute; top: 6px; }
.sidebar {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: var(--sidebar-w); background: var(--ink); color: #cbd5e1;
  transform: translateX(-100%); transition: transform .2s ease; display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar.open { transform: none; }
.sidebar .logo { padding: 16px 18px 12px; color: #fff; font-weight: 700; font-size: 18px; }
.sidebar .logo small { display: block; font-weight: 400; font-size: 12px; opacity: .6; margin-top: 2px; }
.sidebar nav { padding: 6px 10px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 2px; border-radius: 8px;
  color: #cbd5e1; font-size: 14.5px; min-height: 42px;
}
.sidebar nav a:hover { background: var(--ink-2); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar nav a .count { margin-left: auto; background: #fff; color: var(--brand-dark); font-size: 11.5px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }
.sidebar .who { padding: 12px 18px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar .who strong { display: block; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .who a { color: #9fd9c6; }
.sidebar .who .ver { display: block; margin-top: 6px; font-size: 11.5px; color: #64748b; }
.backdrop { position: fixed; inset: 0; background: rgba(13,27,42,.5); z-index: 35; display: none; }
.backdrop.show { display: block; }
.main { padding: 16px 12px 40px; max-width: 1200px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-head h1 { flex: 1; min-width: 160px; }
.page-head .sub { flex-basis: 100%; color: var(--muted); font-size: 13.5px; margin-top: -4px; }

@media (min-width: 960px) {
  .topbar { display: none; }
  .sidebar { transform: none; }
  .backdrop { display: none !important; }
  .main { margin-left: var(--sidebar-w); max-width: none; padding: 24px 28px 48px; }
}

/* ---------- Cards / stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { flex: 1; min-width: 120px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }
.cols { display: grid; gap: 14px; }
@media (min-width: 900px) { .cols.two { grid-template-columns: 1fr 1fr; } .cols.side { grid-template-columns: 2fr 1fr; } }
.cols > .card { margin-bottom: 0; }
.cols { margin-bottom: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f0c9c4; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], input[type=search],
input[type=number], input[type=datetime-local], input[type=date], input[type=file], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cfd6de; border-radius: 8px; background: #fff;
  font: inherit; font-size: 16px; color: var(--text);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
@media (min-width: 700px) { input, select, textarea { font-size: 14.5px !important; } }
.field { margin-bottom: 12px; min-width: 0; }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.grid { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.g2 { grid-template-columns: 1fr 1fr; } .grid.g3 { grid-template-columns: 1fr 1fr 1fr; } .grid .full { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; min-height: 36px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters > * { flex: 1 1 140px; min-width: 0; }
.filters .btn { flex: 0 0 auto; }

/* ---------- Tables (become stacked cards on phones) ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
@media (max-width: 719px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: #fff; }
  .table td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; text-align: left; flex: 0 0 38%; }
  .table td[data-label=""]::before, .table td:not([data-label])::before { display: none; }
  .table td.primary-cell { font-weight: 600; text-align: left; display: block; padding-bottom: 5px; }
  .table td.primary-cell::before { display: none; }
  .table .actions { text-align: left; justify-content: flex-start; flex-wrap: wrap; padding-top: 6px; white-space: normal; }
  .table td.empty { display: block; text-align: center; }
}

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f4; color: #475569; white-space: nowrap; }
.badge.green { background: var(--brand-soft); color: var(--brand-dark); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--info-soft); color: var(--info); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 12px; font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; min-height: 44px; }
.tabs button.active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.tab-pane { display: none; } .tab-pane.active { display: block; }

/* ---------- Modal / toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(13,27,42,.55); display: none; align-items: flex-end; justify-content: center; }
.modal.show { display: flex; }
.modal .box { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 18px 16px 20px; }
.modal .box.wide { max-width: 760px; }
.modal .box-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.modal .box-head h2 { flex: 1; }
.modal .x { background: none; border: 0; font-size: 26px; line-height: 1; width: 40px; height: 40px; cursor: pointer; color: var(--muted); border-radius: 8px; }
.modal .x:hover { background: #f1f5f9; }
@media (min-width: 640px) { .modal { align-items: center; padding: 20px; } .modal .box { border-radius: 14px; padding: 22px; } }
#toasts { position: fixed; z-index: 80; left: 12px; right: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; max-width: 480px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; background: var(--info-soft); color: #1e4b80; }
.alert.warn { background: var(--warn-soft); color: #7a5312; }
.alert.error { background: var(--danger-soft); color: #8c271c; }
.alert.ok { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------- Auth pages (login, MFA, password, setup) ---------- */
.auth-body { background: #fff; }
.auth2 { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.auth2-brand {
  position: relative; overflow: hidden; color: #e2e8f0; padding: 22px 20px;
  background: radial-gradient(circle at 85% 10%, rgba(37, 211, 140, .28), transparent 45%),
              radial-gradient(circle at 10% 90%, rgba(56, 189, 248, .18), transparent 40%),
              linear-gradient(160deg, #0d1b2a 0%, #0f2f3a 60%, #0b4a3c 100%);
}
.auth2-logo { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 19px; letter-spacing: .2px; }
.auth2-logo:hover { text-decoration: none; }
.mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #25d38c, #0b7a5c); position: relative; flex: 0 0 auto; box-shadow: 0 6px 16px rgba(11,122,92,.45); }
.mark::after { content: ""; position: absolute; left: 8px; top: 9px; width: 14px; height: 10px; border-radius: 4px 4px 4px 1px; background: #fff; }
.auth2-pitch { display: none; }
.auth2-pitch .eyebrow { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #6ee7b7; background: rgba(110,231,183,.12); padding: 4px 10px; border-radius: 999px; }
.auth2-pitch h2 { color: #fff; font-size: 30px; line-height: 1.2; margin: 16px 0 18px; max-width: 420px; }
.auth2-pitch ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth2-pitch li { position: relative; padding-left: 30px; color: #cbd5e1; }
.auth2-pitch li::before { content: ""; position: absolute; left: 0; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: rgba(37,211,140,.2); }
.auth2-pitch li::after { content: ""; position: absolute; left: 6px; top: 7px; width: 5px; height: 8px; border: solid #34d399; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.auth2-foot { display: none; font-size: 12.5px; color: #94a3b8; margin: 0; }
.auth2-main { display: flex; align-items: flex-start; justify-content: center; padding: 28px 18px 40px; background: #f7f9fb; }
.auth2-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 26px 22px; box-shadow: 0 18px 40px -24px rgba(13,27,42,.35); }
.auth2-card h1 { font-size: 23px; margin-bottom: 4px; }
.auth2-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.btn.block { width: 100%; min-height: 46px; font-size: 15px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.label-row a { font-size: 13px; font-weight: 600; }
.code-input { font-size: 22px !important; letter-spacing: 6px; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; }
@media (min-width: 900px) {
  .auth2 { grid-template-columns: minmax(380px, 46%) 1fr; }
  .auth2-brand { padding: 40px 48px; display: flex; flex-direction: column; justify-content: space-between; }
  .auth2-pitch { display: block; }
  .auth2-foot { display: block; }
  .auth2-main { align-items: center; padding: 40px; }
  .auth2-card { padding: 34px 32px; }
}

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: 1fr; gap: 8px 16px; font-size: 14px; }
@media (min-width: 640px) { .kv { grid-template-columns: 1fr 1fr; } }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div { min-width: 0; overflow-wrap: anywhere; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 6px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.bars .bar i { display: block; width: 100%; max-width: 34px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar b { font-size: 11px; font-weight: 600; color: var(--ink); }
.bars .bar span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.progress { height: 8px; background: #e7ecf0; border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px !important; background: #f8fafc; }
.chan { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.chan:last-child { border-bottom: 0; }
.chan .info { flex: 1; min-width: 0; }
.wa-preview { background: #e9f5e1; border-radius: 10px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 360px; }
.wa-preview .hd { font-weight: 700; margin-bottom: 4px; }
.wa-preview .ft { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.wa-preview .bt { border-top: 1px solid #cfe3c3; margin-top: 8px; padding-top: 6px; color: var(--info); text-align: center; font-weight: 600; font-size: 13.5px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 1fr; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: calc(100vh - 150px); height: calc(100dvh - 150px); min-height: 380px; }
.inbox .list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.inbox .list .search { padding: 10px; border-bottom: 1px solid var(--line); }
.inbox .list .items { overflow-y: auto; flex: 1; }
.conv { display: block; width: 100%; text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; cursor: pointer; font: inherit; min-height: 58px; }
.conv:hover, .conv.active { background: #f1f7f5; }
.conv .top { display: flex; gap: 8px; align-items: baseline; }
.conv .top strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.conv .top time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.conv .bot { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.conv .bot span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.conv .bot em { font-style: normal; background: var(--brand); color: #fff; border-radius: 10px; font-size: 11.5px; font-weight: 700; padding: 0 7px; }
.inbox .thread { display: none; flex-direction: column; min-height: 0; background: #efeae2; }
.inbox.chat-open .list { display: none; }
.inbox.chat-open .thread { display: flex; }
.thread .th-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #fff; border-bottom: 1px solid var(--line); }
.thread .th-head .who { flex: 1; min-width: 0; }
.thread .th-head .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .th-head .who span { font-size: 12.5px; color: var(--muted); }
.thread .msgs { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 84%; padding: 7px 10px 5px; border-radius: 10px; background: #fff; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.out { align-self: flex-end; background: #d9fdd3; }
.bubble.failed { background: var(--danger-soft); }
.bubble .meta { display: block; font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; white-space: normal; }
.bubble .tag { display: block; font-size: 11px; font-weight: 700; color: var(--brand-dark); text-transform: uppercase; letter-spacing: .3px; }
.bubble img { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.bubble .err { display: block; color: var(--danger); font-size: 12px; white-space: normal; }
.thread .composer { background: #fff; border-top: 1px solid var(--line); padding: 8px; }
.thread .composer .row { display: flex; gap: 6px; align-items: flex-end; }
.thread .composer textarea { min-height: 42px; max-height: 120px; flex: 1; }
.thread .composer .note { font-size: 12.5px; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; }
.thread .placeholder { margin: auto; color: var(--muted); text-align: center; padding: 20px; }
.back-btn { display: inline-flex; }
@media (min-width: 860px) {
  .inbox { grid-template-columns: 320px 1fr; height: calc(100vh - 120px); }
  .inbox .list, .inbox.chat-open .list { display: flex; }
  .inbox .thread { display: flex; }
  .back-btn { display: none; }
}

/* ---------- Admin working inside a company panel ---------- */
.admin-view-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; background: #e8f0fe; border: 1px solid #b9cdf5; color: #1e3a6e; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }

/* ---------- Read-only (portal validity ended) ---------- */
.expired-bar { background: #fff4e5; border: 1px solid #f5d29a; color: #7a4a06; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.expired-bar strong { color: #5c3604; }
body.readonly [data-readonly-hide] { display: none !important; }

/* ---------- MFA / account ---------- */
.qr-box { display: inline-block; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; line-height: 0; }
.qr-box img, .qr-box svg { width: 190px; height: 190px; image-rendering: pixelated; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 12px 14px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.steps-list { margin: 0 0 12px; padding-left: 20px; font-size: 14px; }
.steps-list li { margin-bottom: 6px; }
.sub-card { display: grid; gap: 4px; }
.days-left { font-size: 28px; font-weight: 800; color: var(--ink); line-height: 1.1; }
