/* HostPawa Bot Admin */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #00A4A6;
    --primary-dark: #008688;
    --primary-light: rgba(0, 164, 166, 0.12);
    --sidebar: #1a1a2e;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --dark: #111111;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #e4e7eb;
    --border-strong: #d1d5db;
    --text: #1f2937;
    --muted: #6b7280;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --sidebar-width: 248px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 0.9375rem;
}

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-dark); }

/* ---- Shell ---- */
.admin-shell {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 200;
    border-right: 1px solid var(--sidebar-border);
}

.admin-sidebar .brand {
    padding: 1.25rem 1.25rem 1rem;
    font-size: 1.0625rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.admin-sidebar .brand-logo {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.15rem;
}

.admin-sidebar .brand-text span {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.15rem;
    letter-spacing: 0;
}

.sidebar-section {
    padding: 1rem 0.75rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.4);
}

.admin-sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.5rem 0.75rem 1rem;
    overflow-y: auto;
    flex: 1;
}

.admin-sidebar a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: rgba(255, 255, 255, 0.78);
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.admin-sidebar a:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.admin-sidebar a.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.nav-unread {
    margin-left: auto;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0;
    text-transform: none;
    line-height: 1;
}

.nav-unread[hidden] {
    display: none !important;
}

.admin-sidebar a.active .nav-unread {
    background: #fff;
    color: var(--primary);
}

.admin-notify-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 80;
    width: min(22rem, calc(100vw - 2rem));
    background: #111827;
    color: #fff;
    border-radius: 12px;
    padding: 0.85rem 1rem;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.28);
    display: none;
}

.admin-notify-toast.is-visible {
    display: block;
    animation: admin-toast-in 0.2s ease;
}

.admin-notify-toast strong {
    display: block;
    font-size: 0.875rem;
}

.admin-notify-toast p {
    margin: 0.3rem 0 0.65rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.4;
}

.admin-notify-toast a {
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 700;
}

@keyframes admin-toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.admin-sidebar .sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--sidebar-border);
}

.admin-sidebar .sidebar-footer a {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.8125rem;
}

.admin-main-wrap {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.admin-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.875rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.admin-topbar-title {
    font-size: 0.8125rem;
    color: var(--muted);
    font-weight: 500;
}

.admin-topbar-title strong {
    display: block;
    font-size: 1rem;
    color: var(--dark);
    font-weight: 700;
    margin-top: 0.1rem;
}

.admin-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.admin-main {
    padding: 1.75rem;
    flex: 1;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.65rem;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
}

/* ---- Typography ---- */
.page-header { margin-bottom: 1.5rem; }

.page-header h1,
.admin-main > h1:first-child {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--dark);
    margin: 0 0 0.35rem;
    letter-spacing: -0.02em;
}

.page-header .lead,
.lead {
    color: var(--muted);
    margin: 0;
    font-size: 0.9375rem;
}

h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--dark);
    margin: 1.75rem 0 0.875rem;
}

.section-title {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 0 0 0.75rem;
}

.section-title-flush { margin-top: 0; }

.topbar-start {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ---- Stats ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 0 0 1.75rem;
}

.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.375rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card-sm .stat-num { font-size: 1.5rem; }

.stat-num {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.stat-label {
    display: block;
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-top: 0.35rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.375rem;
    box-shadow: var(--shadow-sm);
}

.panel h2 {
    margin: 0 0 0.875rem;
    font-size: 0.9375rem;
}

.panel p { margin: 0.5rem 0 0; }

.meta-list, .health-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.meta-list li, .health-list li { color: var(--muted); }
.meta-list strong, .health-list strong { color: var(--text); }

.health-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.4rem;
    background: #d1d5db;
}

.health-dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.health-dot.warn { background: #f97316; box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2); }

/* ---- Tables ---- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}

.admin-table th,
.admin-table td {
    padding: 0.875rem 1.125rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    vertical-align: middle;
}

.admin-table th {
    background: #fafbfc;
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.admin-table tbody tr:hover { background: #fafbfc; }
.admin-table tbody tr:last-child td { border-bottom: none; }

.admin-table input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
    cursor: pointer;
}

.admin-table code {
    font-size: 0.8125rem;
    background: #f3f4f6;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.mono-cell {
    font-family: ui-monospace, 'Cascadia Code', monospace;
    font-size: 0.8125rem;
    color: var(--muted);
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-human { background: #fff3e0; color: #c2410c; }
.badge-bot { background: var(--primary-light); color: var(--primary-dark); }
.badge-closed { background: #f3f4f6; color: #6b7280; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-paid { background: #dcfce7; color: #15803d; }
.badge-pending { background: #fef9c3; color: #a16207; }
.badge-channel { background: #eef2ff; color: #4338ca; text-transform: lowercase; }
.badge-tag { background: #f3f4f6; color: #4b5563; text-transform: none; letter-spacing: 0; font-weight: 600; }
.badge-priority-low { background: #f3f4f6; color: #6b7280; }
.badge-priority-normal { background: var(--primary-light); color: var(--primary-dark); }
.badge-priority-high { background: #fff3e0; color: #c2410c; }
.badge-priority-urgent { background: #fee2e2; color: #b91c1c; }

/* ---- Filters ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    align-items: center;
}

.filter-bar a {
    padding: 0.4rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s;
}

.filter-bar a:hover { border-color: var(--primary); color: var(--primary); }
.filter-bar a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.inbox-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.inbox-search-form {
    flex: 1 1 320px;
    margin-bottom: 0;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.filter-form input,
.filter-form select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font: inherit;
    background: #fff;
    min-width: 140px;
}

.filter-form input:focus,
.filter-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ---- Forms ---- */
.settings-form,
.admin-form {
    max-width: 720px;
}

/* Used as a non-form wrapper (e.g. brand logo uploads) — shares field/input styles */
div.settings-form {
    display: block;
}

.settings-form-wide {
    max-width: 880px;
}

.widget-settings-fieldset {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.widget-settings-fieldset label:not(.checkbox-row) {
    width: 100%;
    max-width: 100%;
}

.settings-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.settings-section-last,
.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 0 0 0.875rem;
}

.settings-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1.25rem;
    margin-bottom: 0.25rem;
}

.settings-field-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-field-grid label,
.settings-field-grid-3 label {
    min-width: 0;
}

.field-span-full {
    display: grid;
    gap: 0.4rem;
    width: 100%;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text);
}

.field-span-full:last-child {
    margin-bottom: 0;
}

.settings-checkbox-group {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.settings-checkbox-group .checkbox-row {
    margin-bottom: 0;
}

.hint-top {
    margin-top: 0;
    margin-bottom: 1rem;
}

.brand-logo-row {
    align-items: flex-start;
}

.brand-logo-preview {
    width: 88px;
    height: 88px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: grid;
    place-items: center;
    overflow: hidden;
    flex-shrink: 0;
}

.brand-logo-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.5rem;
    display: block;
}

.brand-logo-remove {
    margin-top: 0.75rem;
}

.settings-form fieldset,
.admin-form fieldset {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.375rem 1.5rem;
    margin: 0 0 1.25rem;
    box-shadow: var(--shadow-sm);
}

.settings-form legend,
.admin-form legend {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--dark);
    padding: 0 0.25rem;
    margin-bottom: 0.25rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
}

.form-group,
.settings-form label,
.admin-form label {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text);
}

.form-group:last-child,
.settings-form label:last-child,
.admin-form label:last-child { margin-bottom: 0; }

.settings-form label.checkbox-row,
.admin-form label.checkbox-row,
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 0.75rem;
}

.checkbox-row input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
    cursor: pointer;
}

.settings-form input,
.settings-form textarea,
.settings-form select,
.admin-form input,
.admin-form textarea,
.admin-form select,
.auth-card input {
    font: inherit;
    font-weight: 400;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.settings-form input:focus,
.settings-form textarea:focus,
.settings-form select:focus,
.admin-form input:focus,
.admin-form textarea:focus,
.admin-form select:focus,
.auth-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.settings-form textarea,
.admin-form textarea { resize: vertical; min-height: 88px; }

.settings-form input[type="color"] {
    padding: 0.25rem;
    height: 2.75rem;
    cursor: pointer;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
    align-items: center;
    margin-top: 0.5rem;
}

.settings-save-bar {
    margin-top: 0.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.settings-form fieldset .form-actions {
    margin-top: 0.75rem;
    padding-top: 0;
    border-top: none;
}

.hint, .field-hint {
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.45;
    margin: -0.35rem 0 0.75rem;
}

.hint code, code.inline {
    font-size: 0.8125rem;
    background: #f3f4f6;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    color: #374151;
}

.code-block {
    display: block;
    padding: 1rem 1.125rem;
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-family: ui-monospace, monospace;
    overflow-x: auto;
    margin: 0.75rem 0;
}

/* ---- Settings tabs ---- */
.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 1.5rem;
    padding: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.settings-tabs a {
    padding: 0.45rem 0.875rem;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 600;
    transition: all 0.15s;
}

.settings-tabs a:hover { background: #f3f4f6; color: var(--text); }
.settings-tabs a.active { background: var(--dark); color: #fff; }

/* ---- Chat / Inbox ---- */
.conversation-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.375rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.conv-header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.conv-header-title h1 {
    font-size: 1.375rem;
    margin: 0.25rem 0 0;
}

.conv-back {
    display: inline-block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.15rem;
}

.conv-back:hover { color: var(--primary); }

.conv-header-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.conv-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem 1.25rem;
    padding: 1rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.conv-meta-item {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
}

.conv-meta-item-wide { grid-column: 1 / -1; }

.conv-meta-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.conv-meta-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.conv-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.conv-summary {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.conv-summary strong {
    display: block;
    font-size: 0.8125rem;
    margin-bottom: 0.35rem;
}

.conv-summary p {
    margin: 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

.conv-session-panel {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.conv-session-panel > strong {
    display: block;
    font-size: 0.8125rem;
    margin-bottom: 0.65rem;
}

.conv-session-grid {
    margin-top: 0;
}

.conv-user-agent {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
}

.conv-user-agent summary {
    cursor: pointer;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.conv-user-agent code {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.75rem;
    color: var(--text);
}

.visitor-layout {
    display: grid;
    gap: 1.25rem;
}

.visitor-panel h2 {
    margin: 0 0 0.875rem;
    font-size: 1rem;
}

.visitor-subheading {
    margin: 1.25rem 0 0.65rem;
    font-size: 0.875rem;
    color: var(--text);
}

.visitor-edit-form {
    display: grid;
    gap: 0.75rem;
}

.visitor-edit-form label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.visitor-edit-form input,
.visitor-edit-form textarea {
    font-weight: 400;
}

.visitor-notes {
    margin: 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

.visitor-whmcs-form {
    margin-top: 0.5rem;
}

.visitor-whmcs-preview {
    margin-top: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
}

.visitor-whmcs-preview p {
    margin: 0 0 0.35rem;
}

.visitor-whmcs-actions,
.conv-link-whmcs-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-end;
}

.visitor-delete-form {
    margin-top: 1rem;
}

.conv-link-whmcs {
    margin: 1rem 0 0;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.conv-link-whmcs-fields label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.conv-link-whmcs-fields input {
    min-width: 12rem;
}

.table-sub {
    font-size: 0.75rem;
    margin-top: 0.15rem;
}

.admin-table-compact td,
.admin-table-compact th {
    font-size: 0.8125rem;
}

.conv-join-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.conv-join-banner-active {
    background: #f0fdfa;
    border-color: #99f6e4;
}

.conv-join-status {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.conv-join-status strong {
    font-size: 0.875rem;
    color: var(--text);
}

.conv-join-status span {
    font-size: 0.8125rem;
    color: var(--muted);
}

.conv-join-form {
    margin: 0;
    flex-shrink: 0;
}

.inbox-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.inbox-join-form {
    display: inline;
    margin: 0;
}

.inbox-join-form .btn {
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
}

.admin-table .muted {
    color: var(--muted);
}

.conv-toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.conv-control {
    display: grid;
    gap: 0.4rem;
    min-width: 0;
}

.conv-control-wide {
    grid-column: span 2;
}

.conv-control label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.conv-control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.conv-control-row select,
.conv-control-row input[type="text"] {
    flex: 1 1 120px;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font: inherit;
    font-size: 0.875rem;
    background: #fff;
}

.conv-control-row input[type="text"] {
    flex: 2 1 180px;
}

.conv-control-row select:focus,
.conv-control-row input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.conv-notes .conv-note {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.conv-notes .conv-note:last-child { border-bottom: none; padding-bottom: 0; }

.conv-note-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    align-items: baseline;
    margin-bottom: 0.35rem;
    font-size: 0.8125rem;
}

.conv-note-meta time {
    color: var(--muted);
    font-size: 0.75rem;
}

.conv-note p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text);
}

.conv-whmcs-tickets {
    margin-top: 0.75rem;
}

.conv-whmcs-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.conv-whmcs-head h2 {
    margin: 0;
}

.conv-whmcs-empty {
    margin: 0;
    padding: 0.25rem 0;
}

.whmcs-ticket-list {
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.whmcs-ticket-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.whmcs-ticket-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.65rem;
    min-width: 0;
    font-size: 0.875rem;
}

.whmcs-ticket-main span:not(.badge):not(.muted) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 28rem;
}

.whmcs-ticket-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.whmcs-ticket-actions form {
    margin: 0;
}

.whmcs-ticket-open {
    margin-top: 0.5rem;
}

.whmcs-ticket-open summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--primary);
}

.whmcs-ticket-open-form {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.whmcs-ticket-open-form label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
}

.whmcs-ticket-open-form input[type="text"],
.whmcs-ticket-open-form textarea {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--surface);
}

.whmcs-ticket-open-form textarea {
    resize: vertical;
    min-height: 5rem;
}

.badge-open {
    background: #dcfce7;
    color: #166534;
}

.badge-closed {
    background: #f3f4f6;
    color: #4b5563;
}

.canned-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.chat-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.chat-thread {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    max-height: 58vh;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-bubble {
    max-width: 78%;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    font-size: 0.9375rem;
    line-height: 1.45;
}

.chat-user {
    align-self: flex-start;
    background: #e6f7f7;
    color: var(--text);
    border: 1px solid #b8e6e6;
    border-bottom-left-radius: 4px;
}

.chat-assistant {
    align-self: flex-start;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-agent {
    align-self: flex-end;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.chat-bubble-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.chat-bubble-head .chat-role {
    margin-bottom: 0;
}

.chat-msg-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.chat-msg-actions .btn {
    padding: 0.15rem 0.45rem;
    font-size: 0.6875rem;
}

.chat-deleted {
    opacity: 0.72;
}

.chat-msg-removed {
    color: var(--muted);
    font-style: italic;
}

.chat-msg-edit-input {
    width: 100%;
    min-height: 4rem;
    padding: 0.5rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font: inherit;
    resize: vertical;
}

.chat-msg-edit-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.chat-system {
    align-self: center;
    background: #f8fafc;
    color: #475569;
    border: 1px solid #e2e8f0;
    font-size: 0.8125rem;
    max-width: 90%;
    text-align: center;
}

.chat-role {
    display: block;
    font-size: 0.625rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    opacity: 0.65;
    margin-bottom: 0.25rem;
}

.chat-time {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.6875rem;
    opacity: 0.55;
    font-weight: 400;
}

.reply-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.125rem;
    box-shadow: var(--shadow-sm);
}

.reply-form textarea {
    width: 100%;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9375rem;
    resize: vertical;
    min-height: 96px;
    margin-bottom: 0.75rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.reply-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.inline-form select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font: inherit;
    background: #fff;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.625rem 1.125rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 164, 166, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: #fff;
}

.btn-outline {
    background: #fff;
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    font-size: 0.8125rem;
    padding: 0.45rem 0.875rem;
}

.btn-end-chat {
    border: 1px solid #fecaca;
    background: #fff;
    color: #b42318;
    font-weight: 600;
}

.btn-end-chat:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}

.btn-danger {
    border: 1px solid #fca5a5;
    background: #fef2f2;
    color: #b42318;
    font-weight: 600;
}

.btn-danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.inbox-bulk-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.conv-end-chat input[type="text"] {
    flex: 1;
    min-width: 0;
}

.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* ---- Confirm dialog ---- */
.admin-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}

.admin-confirm-overlay[hidden] {
    display: none !important;
}

.admin-confirm-card {
    width: min(100%, 420px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.375rem 1.5rem 1.25rem;
}

.admin-confirm-title {
    margin: 0 0 0.5rem;
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--dark);
}

.admin-confirm-message {
    margin: 0 0 1.125rem;
    color: var(--text);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.admin-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.625rem;
    flex-wrap: wrap;
}

/* ---- Alerts ---- */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.text-ok { color: #15803d; font-weight: 600; }
.text-warn { color: #b91c1c; font-weight: 600; }

.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--muted);
    font-size: 0.9375rem;
}

/* ---- Auth ---- */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    padding: 1.5rem;
}

.auth-card {
    width: min(100%, 420px);
    background: var(--surface);
    padding: 2.25rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    display: grid;
    gap: 0.25rem;
}

.auth-card h1 {
    margin: 0 0 0.25rem;
    font-size: 1.375rem;
    font-weight: 800;
    color: var(--dark);
}

.auth-card .auth-subtitle {
    color: var(--muted);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

.auth-card label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-top: 0.75rem;
}

.auth-card .btn { margin-top: 1.25rem; }

.auth-logo {
    width: 56px;
    height: 56px;
    background: var(--primary-light);
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.75rem;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.auth-logo.has-photo {
    background: #fff;
    border: 1px solid var(--border);
    padding: 0.35rem;
}

.auth-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ---- Public preview home ---- */
.preview-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.preview-card {
    width: min(100%, 540px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.25rem 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.preview-card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.625rem;
    font-weight: 800;
    color: var(--dark);
}

.preview-card .lead {
    margin: 0;
    color: var(--muted);
    font-size: 0.9375rem;
    line-height: 1.55;
}

.preview-links {
    display: grid;
    gap: 0.625rem;
    margin-top: 1.5rem;
}

.preview-links a,
.preview-links button {
    display: block;
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 600;
    font: inherit;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.preview-links a:hover,
.preview-links button:hover {
    border-color: var(--primary);
    background: #f7fdfd;
    color: var(--primary-dark);
}

.preview-links a.primary,
.preview-links button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 164, 166, 0.3);
}

.preview-links a.primary:hover,
.preview-links button.primary:hover {
    background: var(--primary-dark);
    color: #fff;
}

.preview-checklist {
    margin: 1.5rem 0 0;
    padding: 1rem 1.125rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    list-style: none;
    display: grid;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.preview-checklist li::before {
    content: '→';
    color: var(--primary);
    margin-right: 0.5rem;
    font-weight: 700;
}

.preview-checklist code {
    font-size: 0.8125rem;
    background: #fff;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* ---- Error pages ---- */
.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.error-card {
    width: min(100%, 480px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    text-align: center;
}

.error-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    background: var(--primary-light);
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.75rem;
    overflow: hidden;
}

.error-logo.has-photo {
    background: #fff;
    border: 1px solid var(--border);
    padding: 0.35rem;
}

.error-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.error-code {
    margin: 0;
    font-size: clamp(3.5rem, 12vw, 5rem);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.04em;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.error-card h1 {
    margin: 0.75rem 0 0.5rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--dark);
}

.error-card .lead {
    margin: 0 auto;
    max-width: 34ch;
    color: var(--muted);
    font-size: 0.9375rem;
    line-height: 1.55;
}

.error-links {
    margin-top: 1.75rem;
}

.error-footnote {
    margin: 1.5rem 0 0;
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.02em;
}

/* ---- Profile meta ---- */
.profile-panel {
    max-width: 480px;
    margin-bottom: 1.25rem;
}

.profile-panel h2 {
    margin-top: 0;
}

.profile-meta {
    display: grid;
    gap: 0.75rem;
}

.page-toolbar {
    margin-bottom: 1.25rem;
}

.profile-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.profile-meta-row:last-child { border-bottom: none; }
.profile-meta-row span:first-child { color: var(--muted); font-weight: 500; }
.profile-meta-row span:last-child { font-weight: 600; color: var(--text); }

.profile-avatar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    align-items: center;
    margin-top: 0.75rem;
}

.profile-avatar-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.125rem;
    overflow: hidden;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--border);
}

.profile-avatar-preview.has-photo {
    background: #fff;
}

.json-editor {
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    tab-size: 2;
    min-height: 12rem;
    resize: vertical;
}

.json-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.json-schema-help {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fafbfc;
}

.json-schema-help summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.hint-list {
    margin: 0.65rem 0 0;
    padding-left: 1.15rem;
    color: var(--muted);
    font-size: 0.8125rem;
    line-height: 1.55;
}

.plan-preview-wrap {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.plan-preview-title {
    margin: 0 0 0.65rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
}

.plan-preview-table {
    width: 100%;
    font-size: 0.8125rem;
}

.plan-preview-table th,
.plan-preview-table td {
    padding: 0.5rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.plan-preview-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

.preview-home-logo {
    margin: 0 auto 1rem;
}

.brand-logo-preview img {
    object-fit: contain;
    padding: 0.35rem;
}

.profile-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar-form {
    flex: 1 1 220px;
    min-width: 0;
}

.profile-avatar-form label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.profile-avatar-form input[type="file"] {
    font: inherit;
    font-weight: 400;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .settings-field-grid,
    .settings-field-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar-toggle { display: inline-flex; }

    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .admin-shell.sidebar-open .admin-sidebar {
        transform: translateX(0);
    }

    .admin-main-wrap { margin-left: 0; }

    .admin-main { padding: 1.25rem; }

    .stat-grid,
    .stat-grid-3,
    .stat-grid-4 { grid-template-columns: 1fr 1fr; }

    .settings-tabs { overflow-x: auto; flex-wrap: nowrap; }

    .conv-control-wide { grid-column: 1 / -1; }

    .conv-toolbar { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stat-grid,
    .stat-grid-3,
    .stat-grid-4 { grid-template-columns: 1fr; }
}
