/* ==========================================================================
   ChatDesk Agent Portal — frontend app shell
   ========================================================================== */

.cd-portal-shell {
    margin: 0;
    padding: 0;
    background: #f1f5f9;
    color: #1e293b;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

.cd-portal-shell * { box-sizing: border-box; }

/* ---- Buttons ----
   .button / .button-primary / .button-large / .button-small are WordPress's
   own wp-admin button classes — that CSS only ever loads in wp-admin, never
   on the frontend, so every button in the portal (reused from the same
   markup as the wp-admin ticket hub) was rendering as a plain unstyled
   native browser button. Defined here, scoped to the portal only, so
   wp-admin's own button styling is untouched. */

.cd-portal-shell .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    line-height: 1.4;
    cursor: pointer;
    text-decoration: none !important;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.cd-portal-shell .button:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: #1e293b;
}

.cd-portal-shell .button-primary {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #ffffff !important;
}
.cd-portal-shell .button-primary:hover {
    background: #4338ca;
    border-color: #4338ca;
    color: #ffffff !important;
}

.cd-portal-shell .button-large { padding: 11px 20px; font-size: 14px; }
.cd-portal-shell .button-small { padding: 4px 10px; font-size: 11px; }

.cd-portal-shell .button:disabled,
.cd-portal-shell .button[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ---- Top bar ---- */

.cd-portal-topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.cd-portal-brand {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.02em;
    color: #4f46e5;
    display: flex;
    align-items: center;
    text-decoration: none !important;
}

.cd-portal-brand-logo {
    height: 26px;
    width: auto;
    display: block;
}

.cd-portal-brand-divider {
    margin: 0 10px;
    color: #cbd5e1;
    font-weight: 400;
}

.cd-portal-brand-text {
    color: #1e293b;
}

.cd-portal-topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.cd-portal-user {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
}

.cd-portal-user-name { font-weight: 600; color: #334155; }

.cd-portal-user a {
    color: #64748b;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}
.cd-portal-user a:hover { background: #f8fafc; color: #1e293b; }

/* ---- Body: list column + detail column ---- */

.cd-portal-body {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 56px);
}

/* Filters sidebar: Active/Assigned/Closed + New Ticket, always its own
   narrow column — never merged with the ticket list itself. */
.cd-portal-filters-col {
    width: 220px;
    flex-shrink: 0;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
}

.cd-portal-nav {
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cd-portal-new-btn {
    background: #4f46e5;
    color: #ffffff !important;
    text-decoration: none !important;
    text-align: center;
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 10px;
}
.cd-portal-new-btn:hover { background: #4338ca; }

.cd-portal-nav a:not(.cd-portal-new-btn) {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
}
.cd-portal-nav a:not(.cd-portal-new-btn):hover { background: #f8fafc; color: #1e293b; }
.cd-portal-nav a.is-active { background: #eef2ff; color: #4f46e5; font-weight: 700; }

.cd-portal-saved-views {
    padding-top: 6px;
    border-top: 1px solid #e2e8f0;
}
.cd-portal-nav-heading {
    margin: 4px 10px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #94a3b8;
}
.cd-portal-saved-view-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 6px;
}
.cd-portal-saved-view-row:hover { background: #f8fafc; }
.cd-portal-saved-view-row a {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
}
.cd-portal-saved-view-row:hover a { color: #1e293b; }
.cd-delete-saved-view {
    background: none;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0 10px;
}
.cd-delete-saved-view:hover { color: #dc2626; }

/* Ticket list: the wide body column next to the filters sidebar. */
.cd-portal-list-body {
    flex: 1;
    min-width: 0;
    padding: 20px 28px;
}

.cd-portal-list-inner {
    width: 100%;
    overflow-x: auto;
}

.cd-portal-dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.cd-portal-dashboard-title {
    margin: 0;
    font-size: 18px;
    color: #1e293b;
}

.cd-portal-dashboard-header .cd-reports-daterange { margin: 0; }

/* ---- List toolbar (search + screen options) ---- */

.cd-portal-list-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.cd-portal-search-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 320px;
    max-width: 480px;
}

.cd-portal-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    margin-left: auto;
}

.cd-portal-search-input {
    flex: 1 1 auto;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    min-width: 0;
}

.cd-portal-search-clear {
    font-size: 12px;
    color: #64748b;
    text-decoration: none;
    white-space: nowrap;
}
.cd-portal-search-clear:hover { color: #334155; text-decoration: underline; }

/* ---- Me Mode ---- */

.cd-portal-me-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    height: 36px;
    padding: 0 14px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.cd-portal-me-mode-toggle:has(input:checked) {
    background: #eef2ff;
    border-color: #4f46e5;
    color: #4f46e5;
}

/* ---- Screen Options ---- */

.cd-portal-screen-options {
    position: relative;
    display: flex;
    justify-content: flex-end;
    flex: 0 0 auto;
}

.cd-screen-options-icon {
    display: inline-block;
    font-size: 20px;
    line-height: 1;
    vertical-align: -4px;
}

.cd-screen-options-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 20;
    min-width: 200px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    padding: 14px 16px;
}
.cd-screen-options-panel.is-open { display: block; }

.cd-screen-options-title {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #64748b;
}

.cd-screen-options-panel label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 13px;
    color: #1e293b;
    cursor: pointer;
}

/* Column visibility is applied directly as an inline style per cell
   (class-portal.php) and toggled live the same way by admin-script.js —
   not CSS classes here — since admin-defined custom field columns have
   keys that don't exist until runtime and can't be enumerated in a
   stylesheet ahead of time. */

/* ---- Filters popup ---- */

#cd-filters-btn { position: relative; }
.cd-filters-btn-active { border-color: #4f46e5; color: #4f46e5; }
.cd-filters-count {
    display: inline-block;
    min-width: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #4f46e5;
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.cd-filters-panel {
    min-width: 280px;
    max-width: 340px;
    max-height: 70vh;
    overflow-y: auto;
}

.cd-filters-row { margin-bottom: 12px; }
.cd-filters-row:last-of-type { margin-bottom: 0; }
.cd-filters-row > label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 5px;
}

.cd-filters-row select,
.cd-filters-row input[type="text"],
.cd-filters-row input[type="number"],
.cd-filters-row input[type="date"],
.cd-filters-row input[type="url"],
.cd-filters-row input[type="email"] {
    width: 100%;
    height: 34px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 0 10px;
    font-size: 13px;
    box-sizing: border-box;
}

.cd-filters-checkbox-list {
    max-height: 130px;
    overflow-y: auto;
    border: 1px solid #f1f5f9;
    border-radius: 6px;
    padding: 6px 10px;
}
.cd-filters-checkbox-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    color: #1e293b;
    cursor: pointer;
}

.cd-filters-date-range {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
}
.cd-filters-date-range input { flex: 1; min-width: 0; }

.cd-filters-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
}
.cd-filters-actions a { font-size: 12px; color: #64748b; text-decoration: none; }
.cd-filters-actions a:hover { color: #334155; text-decoration: underline; }

.cd-filters-save-row {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}
.cd-filters-save-row input {
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
}

.cd-portal-list-empty {
    padding: 60px 20px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

.cd-portal-ticket-table {
    width: 100%;
    min-width: 900px;
    border-collapse: separate;
    border-spacing: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.cd-portal-ticket-table thead th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #64748b;
    background: #f8fafc;
    padding: 10px 14px;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.cd-portal-ticket-table td {
    padding: 12px 14px;
    font-size: 13px;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    white-space: nowrap;
}
.cd-portal-ticket-table tbody tr:last-child td { border-bottom: none; }
.cd-portal-ticket-table tbody tr:hover { background: #f8fafc; }
.cd-portal-ticket-table tr.is-active { background: #eef2ff; }

.cd-portal-th-check, .cd-portal-td-check {
    width: 32px;
    white-space: nowrap;
}

.cd-portal-bulk-toolbar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 8px;
}
.cd-portal-bulk-toolbar.is-visible { display: flex; }

.cd-portal-bulk-count {
    font-size: 13px;
    font-weight: 600;
    color: #4f46e5;
    margin-right: 4px;
}

.cd-portal-bulk-toolbar select,
.cd-portal-bulk-toolbar input[type="text"] {
    height: 32px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
}
.cd-portal-ticket-table tr.is-unread { background: #eff6ff; }
.cd-portal-ticket-table tr.is-unread:hover { background: #dbeafe; }
.cd-portal-ticket-table tr.is-unread .cd-portal-td-ticket a { font-weight: 700; }

.cd-portal-td-ticket {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cd-portal-td-ticket a {
    color: #1e293b;
    text-decoration: none;
    font-weight: 600;
}
.cd-portal-td-ticket a:hover { color: #4f46e5; text-decoration: underline; }

/* Portal counterpart to wp-admin's .row-actions .cd-row-new-response —
   same wording/class, same blue-pulse treatment, just always inline here
   rather than needing a visibility override (the Portal's table has no
   hover-hidden row-actions mechanism to fight with). */
.cd-row-new-response {
    display: inline-block;
    margin-top: 2px;
    background: #2563eb;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    animation: cd-pulse 2s infinite;
}

/* Collision detection — same amber "presence" accent as the detail page's
   #cd-presence-banner, escalating to a pulsing red once someone's actually
   typing a reply (the real duplicate-reply risk), not just looking. */
.cd-portal-presence-badge {
    display: inline-block;
    font-size: 11px;
    color: #92400e;
    background: #fef3c7;
    border-radius: 4px;
    padding: 1px 4px;
    margin-right: 2px;
    vertical-align: middle;
}
.cd-portal-presence-badge.is-replying {
    color: #fff;
    background: #d63638;
    animation: cd-pulse 2s infinite;
}
@keyframes cd-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

.cd-portal-table-status {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.cd-portal-overdue-badge {
    background: #fee2e2;
    color: #b91c1c;
    display: block;
    width: fit-content;
}
.cd-portal-overdue-badge + .cd-portal-overdue-badge { margin-top: 4px; }

.cd-portal-td-customer {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cd-portal-td-customer strong { display: block; font-weight: 600; }
.cd-portal-td-customer span {
    display: block;
    color: #94a3b8;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ---- Detail column ---- */

.cd-portal-detail {
    flex: 1;
    min-width: 0;
    padding: 24px;
}

.cd-portal-detail .cd-wrap {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 100%;
}

/* 56px, not the wp-admin value inherited from admin-style.css .cd-aside
   (top: 40px) — that was tuned for wp-admin's own toolbar height and left
   this sidebar's top edge scrolling under the portal's 56px sticky topbar. */
.cd-portal-detail .cd-aside { top: 56px; }

/* Full-screen the conversation while a ticket (or the create form) is open,
   instead of squeezing it next to the list rail. */
.cd-portal-fullscreen-detail .cd-portal-filters-col,
.cd-portal-fullscreen-detail .cd-portal-list-body { display: none; }
.cd-portal-fullscreen-detail .cd-portal-detail { max-width: 1400px; margin: 0 auto; }

.cd-portal-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 600;
    color: #4f46e5;
    text-decoration: none;
}
.cd-portal-back-link:hover { text-decoration: underline; }

.cd-portal-placeholder {
    height: calc(100vh - 104px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 14px;
}
.cd-portal-create-card { padding: 24px 26px; }
.cd-portal-create-card h2 { margin-top: 0; }

/* ---- Login screen ---- */

.cd-portal-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.cd-portal-login-card {
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
    padding: 36px 34px;
    width: 100%;
    max-width: 380px;
}

.cd-portal-login-logo {
    display: flex;
    align-items: center;
    margin: 0 0 24px;
    font-size: 16px;
    font-weight: 700;
}
.cd-portal-login-logo img {
    height: 34px;
    width: auto;
    display: block;
}

.cd-portal-login-card h1 {
    margin: 0 0 6px;
    font-size: 20px;
    color: #1e293b;
}
.cd-portal-login-sub {
    margin: 0 0 20px;
    color: #94a3b8;
    font-size: 13px;
}

.cd-portal-login-card form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cd-portal-login-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
}

.cd-portal-login-card input[type="text"],
.cd-portal-login-card input[type="password"] {
    font-weight: 400;
    text-transform: none;
    height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 0 12px;
    font-size: 14px;
}

.cd-portal-remember {
    flex-direction: row !important;
    align-items: center;
    gap: 8px !important;
    text-transform: none !important;
    font-weight: 500 !important;
    color: #64748b !important;
}

.cd-portal-btn-primary {
    background: #4f46e5;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    display: inline-block;
}
.cd-portal-btn-primary:hover { background: #4338ca; color: #ffffff; }

@media (max-width: 900px) {
    .cd-portal-body { flex-direction: column; }
    .cd-portal-filters-col {
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }
    .cd-portal-nav { flex-direction: row; align-items: center; flex-wrap: wrap; }
    .cd-portal-new-btn { margin: 0 0 0 auto; }
    .cd-portal-list-body { padding: 16px; }
    .cd-portal-detail { padding: 16px; }
}
