/* Customer + staff portal chrome */
.portal-body {
    min-height: 100vh;
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(240, 128, 32, .16), transparent 55%),
        linear-gradient(180deg, #eef2f6 0%, #e6ebf2 100%);
    color: var(--ink);
}
.portal-top {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(7, 17, 31, .94);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.portal-top-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 68px;
    flex-wrap: wrap;
}
.portal-top .brand span { color: #fff; }
.portal-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1rem;
    margin-right: auto;
}
.portal-nav a {
    color: rgba(255, 255, 255, .78);
    font-weight: 600;
    font-size: .92rem;
    text-decoration: none;
}
.portal-nav a:hover,
.portal-nav a.is-active { color: var(--orange); }
.portal-nav-support {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    position: relative;
}
.nav-chat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 .35rem;
    border-radius: 999px;
    background: #f08020;
    color: #07111f;
    font-size: .68rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 0 0 2px rgba(7, 17, 31, .35);
}
.nav-chat-badge[hidden] {
    display: none !important;
}
.portal-nav-support.has-pending-chat {
    color: #ffd7a8;
}
.portal-nav-support.is-chat-alert .nav-chat-badge {
    animation: portal-chat-badge-pulse 1s ease-in-out 3;
}
@keyframes portal-chat-badge-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 2px rgba(7, 17, 31, .35); }
    50% { transform: scale(1.18); box-shadow: 0 0 0 4px rgba(240, 128, 32, .45); }
}
.portal-user {
    display: flex;
    align-items: center;
    gap: .75rem;
}
.portal-user strong { display: block; font-size: .92rem; }
.portal-user small { color: rgba(255, 255, 255, .65); }
.portal-user .btn-outline {
    border-color: rgba(255, 255, 255, .28);
    color: #fff;
}
.portal-main { padding: 2rem 0 3rem; }
.portal-foot {
    padding: 1.25rem 0 2rem;
    color: var(--muted);
    font-size: .9rem;
}
.portal-foot .wrap {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.portal-hero {
    display: grid;
    gap: .45rem;
    margin-bottom: 1.4rem;
}
.portal-hero h1 {
    font-family: Syne, sans-serif;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    margin: 0;
}
.portal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}
.portal-stat,
.portal-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    box-shadow: 0 10px 28px rgba(7, 17, 31, .05);
}
.portal-stat.is-reorderable {
    cursor: grab;
    user-select: none;
    touch-action: none;
    position: relative;
}
.portal-stat.is-reorderable::after {
    content: '⋮⋮';
    position: absolute;
    top: .55rem;
    right: .7rem;
    color: var(--muted);
    font-size: .7rem;
    letter-spacing: -.08em;
    opacity: .55;
}
.portal-stat.is-dragging {
    opacity: .55;
    cursor: grabbing;
    box-shadow: 0 14px 34px rgba(7, 17, 31, .14);
}
.portal-stat.is-drop-target {
    outline: 2px dashed rgba(240, 128, 32, .55);
    outline-offset: 2px;
}
.portal-stat--due-admin {
    background:
        linear-gradient(165deg, rgba(240, 128, 32, .16) 0%, rgba(240, 128, 32, .07) 48%, #fff7ef 100%);
    border-color: rgba(240, 128, 32, .35);
    box-shadow: 0 10px 28px rgba(240, 128, 32, .1);
}
.portal-stat--due-admin span {
    color: #a85a12;
}
.portal-stat--due-admin strong {
    color: #8a4508;
}
.portal-stat--post-payout {
    background:
        linear-gradient(165deg, rgba(12, 52, 120, .12) 0%, rgba(12, 52, 120, .05) 50%, #f3f6fb 100%);
    border-color: rgba(12, 52, 120, .22);
}
.portal-stat--post-payout span { color: #0c3478; }
.portal-stat--post-payout strong { color: #0a2a61; }
.portal-stat--pending-payout {
    background:
        linear-gradient(165deg, rgba(180, 120, 20, .14) 0%, rgba(180, 120, 20, .05) 50%, #fffaf0 100%);
    border-color: rgba(160, 100, 10, .28);
}
.portal-stat--pending-payout span { color: #8a5a08; }
.portal-stat--pending-payout strong { color: #6e4705; }
.portal-stat--collected {
    background:
        linear-gradient(165deg, rgba(34, 140, 80, .14) 0%, rgba(34, 140, 80, .05) 50%, #f2faf5 100%);
    border-color: rgba(34, 140, 80, .28);
}
.portal-stat--collected span { color: #176b3a; }
.portal-stat--collected strong { color: #125a30; }
.portal-agent-report-note {
    margin: .35rem 0 0;
    font-size: .88rem;
}
.portal-stat span {
    display: block;
    color: var(--muted);
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.portal-stat strong {
    display: block;
    margin-top: .35rem;
    font-size: 1.45rem;
    font-family: Syne, sans-serif;
}
.portal-panel { margin-top: 1rem; }
.portal-panel h2 {
    margin: 0 0 .9rem;
    font-size: 1.15rem;
    font-family: Syne, sans-serif;
}
.portal-panel-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .75rem 1rem;
    align-items: end;
}
.portal-panel-head h2 { margin-bottom: .25rem; }
.portal-panel-head .lead { margin: 0; }
.portal-month-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    align-items: center;
}
.portal-month-nav input[type="month"],
.portal-month-nav select {
    min-height: 40px;
    padding: .45rem .65rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    font: inherit;
    background: var(--paper);
    color: var(--ink);
}
.portal-month-nav .btn[aria-disabled="true"] {
    opacity: .45;
    pointer-events: none;
}
.portal-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .9rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
}
.portal-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f6 100%);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    text-align: left;
    vertical-align: middle;
    padding: .75rem .7rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.portal-table tbody td {
    padding: .78rem .7rem;
    border-bottom: 1px solid rgba(7, 17, 31, .08);
    text-align: left;
    vertical-align: top;
    color: var(--ink);
    background: #fff;
    transition: background .15s ease;
}
.portal-table tbody tr:nth-child(even) td {
    background: rgba(7, 17, 31, .018);
}
.portal-table tbody tr:hover td {
    background: rgba(240, 128, 32, .07);
}
.portal-table tbody tr:last-child td {
    border-bottom: 0;
}
.portal-table th:first-child,
.portal-table td:first-child {
    padding-left: .95rem;
}
.portal-table th:last-child,
.portal-table td:last-child {
    padding-right: .95rem;
}
.portal-table td strong {
    font-weight: 750;
    color: var(--ink);
}
.portal-table td small {
    display: inline-block;
    margin-top: .15rem;
    color: var(--muted);
    font-size: .8rem;
    font-weight: 500;
    line-height: 1.35;
}
.portal-table td .portal-form {
    min-width: 11rem;
    gap: .45rem;
}
.portal-table td .portal-form label {
    font-size: .75rem;
}
.portal-table td .portal-form input {
    min-height: 38px;
    padding: .4rem .6rem;
    font-size: .86rem;
}
.portal-table td .btn {
    min-height: 36px;
    padding: .35rem .8rem;
    font-size: .82rem;
}
.portal-table .portal-badge {
    white-space: nowrap;
}
.portal-panel > .portal-table,
.portal-chart-card > .portal-table,
.portal-panel-head + .portal-table,
.portal-grid + .portal-table,
.lead + .portal-table {
    margin-top: .15rem;
}
/* Horizontal scroll on narrow viewports without breaking column alignment */
.portal-panel:has(> .portal-table),
.portal-chart-card:has(> .portal-table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.portal-panel:has(> .portal-table) > .portal-table,
.portal-chart-card:has(> .portal-table) > .portal-table {
    min-width: 560px;
}
.portal-badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 999px;
    background: rgba(240, 128, 32, .14);
    color: var(--ink);
    font-size: .78rem;
    font-weight: 700;
}
.portal-badge.is-muted { background: rgba(7, 17, 31, .08); }
.portal-login {
    max-width: 440px;
    margin: 2rem auto;
}
.portal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .55rem;
    margin-top: 1rem;
}
.portal-form {
    display: grid;
    gap: .75rem;
}
.portal-form label {
    display: grid;
    gap: .35rem;
    font-size: .85rem;
    font-weight: 700;
    color: var(--muted);
}
.portal-form label small {
    font-weight: 500;
    color: var(--muted);
}
.portal-form .portal-check {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
    color: var(--ink);
}
.portal-form .portal-check input {
    width: auto;
    min-height: auto;
    margin: 0;
}

.chat-staff-layout {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    gap: 1rem;
    align-items: stretch;
    min-height: 640px;
}
.chat-staff-list,
.chat-staff-thread {
    display: flex;
    flex-direction: column;
    min-height: 640px;
}
.chat-staff-convs {
    display: grid;
    gap: .55rem;
    overflow: auto;
    max-height: none;
    flex: 1;
    padding: .15rem;
}
.chat-staff-item {
    text-align: left;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 14px;
    padding: .8rem .9rem;
    cursor: pointer;
    display: grid;
    gap: .35rem;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.chat-staff-item:hover {
    border-color: rgba(240, 128, 32, .35);
    box-shadow: 0 8px 20px rgba(7, 17, 31, .06);
}
.chat-staff-item strong { font-size: .95rem; color: var(--ink); }
.chat-staff-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}
.chat-staff-item-meta,
.chat-staff-item small {
    color: var(--muted);
    font-size: .8rem;
}
.chat-staff-item.is-active {
    border-color: rgba(240, 128, 32, .55);
    background: linear-gradient(180deg, #fff9f2, #fff4ea);
    box-shadow: 0 10px 24px rgba(240, 128, 32, .12);
}
.chat-status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .15rem .55rem;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    white-space: nowrap;
}
.chat-status--bot { background: #e8eef6; color: #334155; }
.chat-status--queued { background: #fff1d6; color: #9a6700; }
.chat-status--active { background: #e5f6ec; color: #1f7a4c; }
.chat-status--closed { background: #eceff3; color: #5b6b7c; }
.chat-status--escalated { background: #fde8e8; color: #a12622; }
.chat-project-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .12rem .5rem;
    font-size: .68rem;
    font-weight: 700;
    background: #07111f;
    color: #fff;
}
.chat-staff-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    align-items: center;
}
.chat-staff-actions select {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .35rem .55rem;
    font: inherit;
}
.chat-staff-log {
    flex: 1;
    min-height: 380px;
    max-height: none;
    margin: .75rem 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: .9rem;
    display: grid;
    gap: .7rem;
    align-content: start;
    overflow: auto;
    background:
        radial-gradient(120% 80% at 0% 0%, rgba(240, 128, 32, .07), transparent 50%),
        linear-gradient(180deg, #eef3f9, #f7f9fc);
}
.chat-staff-log .chat-bubble {
    max-width: 78%;
    padding: .7rem .85rem;
    border-radius: 16px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 6px 16px rgba(7, 17, 31, .05);
}
.chat-staff-log .chat-bubble--visitor {
    justify-self: start;
    background: linear-gradient(180deg, #fff7ef, #ffefdf);
    border-color: rgba(240, 128, 32, .4);
    border-bottom-left-radius: 6px;
}
.chat-staff-log .chat-bubble--staff {
    justify-self: end;
    background: #fff;
    border-color: #c9d6e6;
    border-bottom-right-radius: 6px;
}
.chat-staff-log .chat-bubble--bot {
    justify-self: start;
    background: linear-gradient(180deg, #0d1a2e, #07111f);
    color: #f4f7fb;
    border-color: transparent;
    border-bottom-left-radius: 6px;
}
.chat-staff-log .chat-bubble--bot .chat-bubble-who,
.chat-staff-log .chat-bubble--bot .chat-bubble-time {
    color: rgba(244, 247, 251, .72);
}
.chat-staff-log .chat-bubble--system {
    justify-self: center;
    max-width: 94%;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: .25rem .5rem;
    font-size: .84rem;
    color: var(--muted);
    text-align: center;
}
.chat-staff-log .chat-bubble-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .3rem;
}
.chat-staff-log .chat-bubble-who {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.chat-staff-log .chat-bubble-time {
    font-size: .7rem;
    color: var(--muted);
    white-space: nowrap;
}
.chat-staff-log .chat-bubble p {
    margin: 0;
    line-height: 1.45;
    font-size: .94rem;
    word-break: break-word;
}
.chat-staff-thread .chat-compose {
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .45rem;
    align-items: center;
    padding: .7rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.chat-staff-thread .chat-compose input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .55rem .7rem;
    font: inherit;
    width: 100%;
}
.chat-staff-empty {
    margin: auto;
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem;
}
@media (max-width: 900px) {
    .chat-staff-layout { grid-template-columns: 1fr; }
    .chat-staff-list,
    .chat-staff-thread { min-height: 0; }
    .chat-staff-convs { max-height: 280px; }
}

.bot-flow-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    gap: 1rem;
    align-items: start;
}
.bot-flow-board { padding: .85rem; }
.bot-flow-scroll {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background:
        linear-gradient(90deg, rgba(7,17,31,.04) 1px, transparent 1px) 0 0 / 24px 24px,
        linear-gradient(rgba(7,17,31,.04) 1px, transparent 1px) 0 0 / 24px 24px,
        #f7f9fc;
    max-height: 72vh;
}
.bot-flow-canvas {
    position: relative;
    min-width: 900px;
    min-height: 560px;
}
.bot-flow-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}
.bot-flow-link {
    fill: none;
    stroke: #f08020;
    stroke-width: 2.5;
    pointer-events: stroke;
}
.bot-flow-link.is-draft {
    stroke-dasharray: 6 4;
    opacity: .7;
}
.bot-flow-unlink {
    fill: #f08020;
    stroke: #fff;
    stroke-width: 2;
    pointer-events: all;
    cursor: pointer;
}
.bot-flow-card {
    position: absolute;
    width: 220px;
    padding: .75rem .8rem 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(7, 17, 31, .08);
    cursor: grab;
    touch-action: none;
    user-select: none;
    z-index: 2;
}
.bot-flow-card.is-dragging { cursor: grabbing; z-index: 5; opacity: .95; }
.bot-flow-card.is-selected {
    border-color: rgba(240, 128, 32, .7);
    box-shadow: 0 0 0 2px rgba(240, 128, 32, .25);
}
.bot-flow-card.is-inactive { opacity: .55; }
.bot-flow-card header {
    display: grid;
    gap: .15rem;
    margin-bottom: .45rem;
    padding-right: .6rem;
}
.bot-flow-card strong { font-size: .92rem; }
.bot-flow-card small { color: var(--muted); font-size: .75rem; }
.bot-flow-card p {
    margin: 0;
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.35;
}
.bot-flow-port {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #f08020;
    box-shadow: 0 0 0 1px rgba(240, 128, 32, .5);
    cursor: crosshair;
    z-index: 3;
}
.bot-flow-port--in { left: -7px; top: 50%; transform: translateY(-50%); }
.bot-flow-port--out { right: -7px; top: 50%; transform: translateY(-50%); }
.bot-flow-hint { margin: .75rem 0 0; }
.bot-flow-editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}
@media (max-width: 980px) {
    .bot-flow-layout { grid-template-columns: 1fr; }
}
.portal-form input,
.portal-form select,
.portal-form textarea {
    min-height: 44px;
    padding: .65rem .75rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    font: inherit;
    background: var(--paper);
    color: var(--ink);
}
.portal-alert {
    padding: .75rem .9rem;
    border-radius: 12px;
    font-weight: 600;
    margin-bottom: 1rem;
}
.portal-alert.is-error {
    background: rgba(180, 40, 40, .1);
    color: #8f1f1f;
}
.portal-alert.is-ok {
    background: rgba(34, 140, 80, .12);
    color: #176b3a;
}
.portal-alert.is-info {
    background: rgba(12, 52, 120, .1);
    color: #0c3478;
}
.customer-list {
    display: grid;
    gap: .45rem;
}
.customer-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
}
.customer-item > summary {
    list-style: none;
    display: grid;
    grid-template-columns: 3.2rem minmax(0, 1.6fr) auto minmax(0, .9fr) auto auto auto;
    gap: .45rem .75rem;
    align-items: center;
    padding: .7rem .9rem;
    cursor: pointer;
}
.customer-edit-btn {
    justify-self: end;
    min-height: 34px;
    padding: .35rem .7rem;
    font-size: .82rem;
}
.portal-modal {
    border: none;
    padding: 0;
    background: transparent;
    max-width: min(520px, calc(100vw - 2rem));
    width: 100%;
}
.portal-modal::backdrop {
    background: rgba(7, 17, 31, .55);
}
.portal-modal-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.15rem 1.2rem 1.25rem;
    box-shadow: 0 24px 48px rgba(7, 17, 31, .22);
}
.portal-modal-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
    margin-bottom: .35rem;
}
.portal-modal-head h2 {
    margin: .15rem 0 0;
    font-size: 1.2rem;
    font-family: Syne, sans-serif;
}
.portal-modal-head .lead {
    margin: .25rem 0 0;
    font-size: .88rem;
}
.customer-item > summary::-webkit-details-marker { display: none; }
.customer-item > summary::marker { content: ''; }
.customer-item[open] > summary {
    border-bottom: 1px solid var(--line);
}
.customer-item-id {
    font-weight: 800;
    color: var(--muted);
}
.customer-item-who {
    display: grid;
    min-width: 0;
}
.customer-item-who small {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
}
.customer-item-meta {
    font-size: .85rem;
    color: var(--ink);
}
.customer-item-body {
    padding: 1rem .9rem 1.1rem;
    display: grid;
    gap: 1rem;
}
.portal-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-top: .85rem;
}
.portal-chart-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .85rem .9rem 1rem;
    background: var(--paper);
}
.portal-chart-card h3 {
    margin: 0 0 .55rem;
    font-size: .95rem;
    font-family: Syne, sans-serif;
}
.portal-chart-card canvas {
    display: block;
    width: 100%;
    height: 260px;
}
@media (max-width: 900px) {
    .portal-grid { grid-template-columns: 1fr; }
    .portal-nav { order: 3; width: 100%; }
    .customer-item > summary {
        grid-template-columns: 3.2rem minmax(0, 1fr) auto auto;
    }
    .customer-item-meta { display: none; }
    .portal-chart-grid { grid-template-columns: 1fr; }
    .portal-table {
        font-size: .84rem;
    }
    .portal-table thead th,
    .portal-table tbody td {
        padding: .62rem .5rem;
    }
    .portal-table th:first-child,
    .portal-table td:first-child {
        padding-left: .7rem;
    }
    .portal-table th:last-child,
    .portal-table td:last-child {
        padding-right: .7rem;
    }
}
