/* ---------- Client portal ---------- */
body.portal { background: var(--bg-soft); display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: #C9D1DE; display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; gap: 18px; }
.sidebar-logo { color: #fff; padding: 0 8px; }
.sidebar-logo small { color: #7E8AA0; }
.org { background: rgba(255,255,255,.06); border-radius: 12px; padding: 12px 14px; }
.org b { display: block; color: #fff; font-size: 14px; }
.org-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7E8AA0; font-weight: 600; }
.new-ticket { justify-content: center; height: 42px; }
.side-nav { display: grid; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; color: #C9D1DE; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.on { background: rgba(30,94,255,.18); color: #fff; }
.side-nav a.on svg { color: #6E95FF; }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 16px; }
.side-foot .me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; border-radius: 10px; }
.side-foot .me:hover, .side-foot .me.on { background: rgba(255,255,255,.06); }
.side-foot .me b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .me small { color: #7E8AA0; font-size: 12px; }
.side-foot .avatar { width: 34px; height: 34px; flex: none; background: rgba(255,255,255,.1); color: #fff; font-size: 13px; }
.side-help { font-size: 12px; color: #7E8AA0; padding: 0 8px; }
.side-help a { color: #fff; font-weight: 600; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 0; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; }
.sidebar .icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.pmain { min-width: 0; display: flex; flex-direction: column; }
.ptop { display: flex; align-items: flex-end; gap: 16px; padding: 32px 40px 24px; }
.ptop h1 { font-size: 28px; letter-spacing: -.025em; line-height: 1.2; }
.ptop-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.ptop-actions form { display: contents; }
.pcrumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.pcrumbs a { color: var(--ink-2); font-weight: 500; }
.menu-p { display: none; border: 1px solid var(--line); background: #fff; }
.pcontent { padding: 0 40px 56px; }
.alert-error { background: #FEF3F2; color: #B42318; border-color: #FECDCA; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.panel-head h2 { font-size: 16px; letter-spacing: -.01em; }
.panel-head a { font-size: 13px; font-weight: 600; color: var(--accent); display: inline-flex; gap: 4px; align-items: center; }
.stack { display: grid; gap: 20px; align-content: start; min-width: 0; }
.pgrid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; margin-top: 20px; }
.pgrid:first-child { margin-top: 0; }
.pgrid-form { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; margin-top: 0; }
.pgrid-detail { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; margin-top: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 16px 0; text-align: center; }
.empty svg { color: #B0B8C6; margin-bottom: 8px; }
.empty a { color: var(--accent); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.small-link { font-size: 13px; font-weight: 600; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; font-family: inherit; display: inline-flex; align-items: center; gap: 4px; }
.small-link.danger { color: #D92D20; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; transition: .15s; }
.kpi:hover { border-color: #C9D3E6; }
.kpi span { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi strong { display: block; font-size: 34px; letter-spacing: -.03em; margin-top: 4px; line-height: 1.1; }
.kpi-alert { border-color: #FEC84B; background: #FFFCF5; }
.kpi-alert strong { color: #B54708; }

/* Ticket rows */
.trow { display: flex; align-items: center; gap: 16px; padding: 12px 10px; margin: 0 -10px; border-radius: 10px; }
.trow + .trow { border-top: 1px solid var(--line); border-radius: 0; }
.trow:hover { background: var(--bg-soft); border-radius: 10px; }
.trow-main { flex: 1; min-width: 0; }
.trow-main b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow-main small { color: var(--muted); font-size: 12px; }
.trow-meta { display: flex; gap: 6px; flex: none; }
.ref { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); margin-right: 8px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-blue { background: #EAF0FF; color: #1849D6; }
.badge-green { background: #E7F8EF; color: #067647; }
.badge-amber { background: #FEF0C7; color: #B54708; }
.badge-red { background: #FEE4E2; color: #B42318; }
.badge-grey { background: #F2F4F7; color: #475467; }
.sla { font-size: 12px; font-weight: 600; }
.sla-ok { color: #067647; } .sla-bad { color: #B42318; } .sla-due { color: #B54708; }

/* Visits / docs */
.visit-row { display: flex; gap: 14px; align-items: center; padding: 10px 0; }
.visit-row + .visit-row { border-top: 1px solid var(--line); }
.visit-row .date { width: 48px; height: 52px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; align-content: center; flex: none; line-height: 1.1; }
.visit-row .date b { font-size: 18px; } .visit-row .date span { font-size: 11px; text-transform: uppercase; font-weight: 600; }
.visit-row div:last-child b { display: block; font-size: 14px; } .visit-row div:last-child span { font-size: 13px; color: var(--muted); }
.mini-stat, .doc-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; font-size: 14px; color: var(--ink-2); }
.mini-stat + .mini-stat, .doc-row + .doc-row { border-top: 1px solid var(--line); }
.mini-stat svg, .doc-row svg { color: var(--muted); flex: none; }
.doc-row b { display: block; font-size: 14px; } .doc-row small { color: var(--muted); font-size: 12px; }
.doc-title { display: inline-flex; gap: 8px; align-items: center; }
.doc-title svg { color: var(--muted); }
.prio-bars { display: grid; gap: 8px; }
.prio-row { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: var(--bg-soft); font-size: 14px; }

/* Tables & filters */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); }
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filterbar select, .filterbar .search { height: 42px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-size: 14px; padding: 0 12px; color: var(--ink); }
.filterbar .search { display: flex; align-items: center; gap: 8px; color: var(--muted); flex: 1; min-width: 220px; }
.filterbar .search input { border: 0; outline: 0; font: inherit; font-size: 14px; flex: 1; min-width: 0; background: none; color: var(--ink); }
.filterbar .btn { height: 42px; }
.table-wrap { overflow-x: auto; }
.ptable { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
.table-wrap:has(> .ptable:not(.ptable-plain)) { border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.ptable th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ptable tbody tr:last-child td { border-bottom: 0; }
.ptable:not(.ptable-plain) tbody tr { cursor: pointer; }
.ptable:not(.ptable-plain) tbody tr:hover { background: #FAFBFC; }
.ptable-plain th, .ptable-plain td { padding-left: 0; }
.tlink { font-weight: 600; }
.row-off td { opacity: .55; }
.row-actions { display: flex; gap: 14px; }
.w-expired { color: #B42318; font-weight: 600; } .w-expiring { color: #B54708; font-weight: 600; }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 20px; font-size: 14px; color: var(--muted); }

/* Sites */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.site-card { transition: .15s; display: block; }
.site-card:hover { border-color: #C9D3E6; transform: translateY(-2px); }
.site-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.site-card .icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.site-card h3 { font-size: 17px; margin-bottom: 4px; }
.site-card p { font-size: 13px; }
.site-stats { display: flex; gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.site-stats b { color: var(--ink); }
.site-stats .has-open b { color: #B54708; }

/* Details list */
.details h3 { font-size: 16px; margin-bottom: 12px; }
.details dl { display: grid; gap: 12px; font-size: 14px; }
.details dt { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.details dd { margin: 2px 0 0; }
.details dd a { color: var(--accent); font-weight: 500; }

/* Ticket conversation */
.msg header { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.msg header b { font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg header small { color: var(--muted); font-size: 12px; }
.msg .avatar { width: 36px; height: 36px; font-size: 14px; }
.msg-body { font-size: 15px; color: var(--ink-2); }
.msg-body p + p { margin-top: 10px; }
.msg-staff { border-left: 3px solid var(--accent); }
.msg-staff .avatar { background: var(--ink); color: #fff; }
.msg-internal { background: #FFFCF5; border-color: #FEDF89; }
.tag-aci { font-size: 10px; background: var(--ink); color: #fff; padding: 2px 6px; border-radius: 4px; letter-spacing: .05em; }
.tag-internal { font-size: 11px; background: #FEF0C7; color: #B54708; padding: 2px 8px; border-radius: 4px; display: inline-flex; gap: 4px; align-items: center; }
.files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.files a { font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }
.files a:hover { border-color: var(--accent); color: var(--accent); }
.event { font-size: 13px; color: var(--muted); text-align: center; padding: 2px 0; }
.reply .field { margin-bottom: 12px; }
.reply-foot { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.reply-foot .btn { margin-left: auto; width: auto !important; height: 46px !important; }

/* Forms in portal */
.pform select { width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: 0 40px 0 14px; font: inherit; font-size: 15px; color: var(--ink); background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235B6678' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 14px center/16px no-repeat; appearance: none; }
.pform { border-radius: 16px; box-shadow: none; padding: 26px; }
.pform button.btn { width: auto; padding: 0 22px; }
.flabel { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.help { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.checklist-box { display: grid; gap: 10px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.prio-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.prio-pick label { border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; display: block; position: relative; }
.prio-pick input { position: absolute; opacity: 0; }
.prio-pick b { display: block; font-size: 14px; }
.prio-pick small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 4px; }
.prio-pick label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.prio-pick label.p1:has(input:checked) { border-color: #D92D20; background: #FEF3F2; box-shadow: 0 0 0 1px #D92D20; }
.prio-pick label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone { display: flex; gap: 10px; align-items: center; border: 1.5px dashed #C5CBD5; border-radius: 12px; padding: 16px; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 14px; }
.dropzone:hover { border-color: var(--accent); color: var(--accent); }
.dropzone input { font-size: 13px; font-weight: 400; color: var(--muted); max-width: 100%; }
.dropzone-sm { padding: 8px 12px; font-size: 13px; }
.callout-urgent { display: flex; gap: 14px; background: #FEF3F2; border-color: #FECDCA; color: #912018; }
.callout-urgent p { font-size: 14px; margin-top: 4px; }
.callout-urgent a { font-weight: 700; color: inherit; }

/* Auth pages */
body.auth { background: #fff; }
.auth-wrap { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.auth-side { background: var(--ink); color: #C9D1DE; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side::after { content: ""; position: absolute; right: -160px; bottom: -160px; width: 480px; height: 480px; border-radius: 50%; background: radial-gradient(circle, rgba(30,94,255,.45), transparent 70%); }
.auth-side .logo { color: #fff; } .auth-side .logo small { color: #7E8AA0; }
.auth-side h2 { color: #fff; font-size: 40px; letter-spacing: -.03em; margin-bottom: 24px; }
.auth-points { list-style: none; display: grid; gap: 16px; font-size: 16px; }
.auth-points li { display: flex; gap: 12px; align-items: center; }
.auth-points svg { color: #6E95FF; }
.auth-help { font-size: 14px; color: #7E8AA0; position: relative; z-index: 1; }
.auth-main { display: grid; place-items: center; padding: 48px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 30px; letter-spacing: -.03em; margin-bottom: 6px; }
.auth-card > p.muted { margin-bottom: 28px; }
.auth-card input[type=text], .auth-card input[type=password], .auth-card input[type=email] { width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; font: inherit; font-size: 15px; }
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.wide { width: 100%; justify-content: center; height: 50px; margin-top: 6px; cursor: pointer; font: inherit; font-weight: 600; }
.auth-links { margin-top: 20px; font-size: 14px; text-align: center; }
.auth-links a { color: var(--accent); font-weight: 600; }
.auth-card .helptext, .auth-card ul:not(.errorlist) { font-size: 12px; color: var(--muted); margin-top: 6px; padding-left: 16px; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .pgrid, .pgrid-form, .pgrid-detail { grid-template-columns: 1fr; }
  .prio-pick { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  body.portal { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim:not([hidden]) { position: fixed; inset: 0; background: rgba(11,18,32,.5); z-index: 30; }
  .menu-p { display: grid; align-self: center; }
  .ptop { padding: 20px; align-items: center; flex-wrap: wrap; }
  .ptop > div:nth-child(2) { flex: 1; min-width: 0; }
  .ptop h1 { font-size: 22px; }
  .ptop-actions { width: 100%; margin: 0; }
  .ptop-actions .btn { flex: 1; justify-content: center; }
  .pcontent { padding: 0 16px 40px; }
  .kpi strong { font-size: 28px; }
  .trow { flex-wrap: wrap; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .filterbar select { flex: 1; }
}

/* Fixes: shrinkable grid columns, hidden native file input, full-height sidebar colour */
.dropzone { position: relative; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (min-width: 861px) { body.portal { background: linear-gradient(to right, var(--ink) 264px, var(--bg-soft) 264px); } }
@media (max-width: 1100px) {
  .pgrid, .pgrid-form, .pgrid-detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  body.portal { grid-template-columns: minmax(0, 1fr); }
  .reply-foot .btn { margin-left: 0; width: 100% !important; justify-content: center; }
  .kpis { gap: 10px; }
  .kpi { padding: 16px; }
}

/* Sidebar counter (open enquiries) */
.nav-count { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
