/* ==========================================================================
   Chatterly - Main Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Variables
   -------------------------------------------------------------------------- */
:root {
    --primary: #0066FF;
    --primary-dark: #0052CC;
    --primary-light: #E6F0FF;
    --success: #28A745;
    --warning: #FFC107;
    --danger: #DC3545;
    --info: #17A2B8;
    --gray-50: #F8F9FA;
    --gray-100: #F1F3F5;
    --gray-200: #E9ECEF;
    --gray-300: #DEE2E6;
    --gray-400: #CED4DA;
    --gray-500: #ADB5BD;
    --gray-600: #868E96;
    --gray-700: #495057;
    --gray-800: #343A40;
    --gray-900: #212529;
    --sidebar-width: 240px;
    --header-height: 56px;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --transition: 150ms ease;
}

/* --------------------------------------------------------------------------
   Reset / Normalize
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji',
                 'Segoe UI Emoji';
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--gray-900);
    background-color: var(--gray-50);
}

img, svg {
    display: block;
    max-width: 100%;
}

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

ul, ol {
    list-style: none;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--gray-900);
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
}

.header-brand {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}
.header-brand:hover {
    color: var(--primary-dark);
    text-decoration: none;
}

.header-brand svg {
    width: 24px;
    height: 24px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-operator-name {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--gray-700);
}
.hamburger svg {
    width: 24px;
    height: 24px;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    z-index: 900;
    padding: 0.75rem 0;
    transition: transform var(--transition);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-section {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-top: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--gray-700);
    border-radius: 0;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar-link:hover {
    background: var(--gray-100);
    color: var(--gray-900);
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}
.sidebar-link.active svg {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Main Content
   -------------------------------------------------------------------------- */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 1.5rem;
    min-height: calc(100vh - var(--header-height));
}

/* --------------------------------------------------------------------------
   Page Header
   -------------------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    margin: 0;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--gray-200);
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.table th,
.table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gray-600);
    position: sticky;
    top: 0;
}

.table-striped tbody tr:nth-child(even) {
    background: var(--gray-50);
}

.table tbody tr:hover {
    background: var(--primary-light);
}

.table td.actions {
    white-space: nowrap;
}

.table-empty {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
    font-style: italic;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition),
                color var(--transition), box-shadow var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}
.btn:hover {
    text-decoration: none;
}
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn svg {
    width: 16px;
    height: 16px;
}

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

.btn-secondary {
    background: #fff;
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover:not(:disabled) {
    background: #218838;
    border-color: #218838;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
    background: #c82333;
    border-color: #c82333;
}

.btn-warning {
    background: var(--warning);
    color: var(--gray-900);
    border-color: var(--warning);
}
.btn-warning:hover:not(:disabled) {
    background: #e0a800;
    border-color: #e0a800;
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-900);
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: 999px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}
.badge-warning {
    background: #fff3cd;
    color: #856404;
}
.badge-danger {
    background: #f8d7da;
    color: #721c24;
}
.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}
.badge-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.25rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.4375rem 0.625rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--gray-900);
    background: #fff;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.15);
}
.form-control:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}
.form-control::placeholder {
    color: var(--gray-400);
}

textarea.form-control {
    resize: vertical;
    min-height: 5rem;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23495057' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    padding-right: 2rem;
}

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

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

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

.form-check label {
    font-size: 0.8125rem;
    color: var(--gray-700);
    cursor: pointer;
}

.form-text {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-inline {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

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

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}
.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform var(--transition);
    margin: 1rem;
}
.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
    font-size: 1rem;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    padding: 0.25rem;
    border-radius: var(--radius);
    transition: background var(--transition);
}
.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    padding: 1rem;
}

.modal-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.modal-lg .modal {
    max-width: 720px;
}

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

.alert-success {
    background: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}
.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}
.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}
.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.tab-item {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-600);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}
.tab-item:hover {
    color: var(--gray-900);
}
.tab-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 0.75rem);
    right: 1rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toastIn 200ms ease forwards;
    max-width: 360px;
    color: #fff;
}
.toast-success { background: var(--success); }
.toast-danger  { background: var(--danger); }
.toast-warning { background: var(--warning); color: var(--gray-900); }
.toast-info    { background: var(--info); }

.toast.removing {
    animation: toastOut 200ms ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}

/* --------------------------------------------------------------------------
   Color Swatch
   -------------------------------------------------------------------------- */
.color-swatch {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 3px;
    border: 1px solid var(--gray-300);
    vertical-align: middle;
}

/* --------------------------------------------------------------------------
   Status Indicator
   -------------------------------------------------------------------------- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.375rem;
}
.status-dot-success { background: var(--success); }
.status-dot-warning { background: var(--warning); }
.status-dot-info    { background: var(--info); }
.status-dot-danger  { background: var(--danger); }
.status-dot-gray    { background: var(--gray-400); }

/* --------------------------------------------------------------------------
   Filters Bar
   -------------------------------------------------------------------------- */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.filters-bar .form-group {
    margin-bottom: 0;
    min-width: 140px;
}

/* --------------------------------------------------------------------------
   Dashboard Multi-Panel Layout
   -------------------------------------------------------------------------- */
.dashboard-layout {
    display: flex;
    gap: 0;
    min-height: calc(100vh - var(--header-height));
    margin: -1.5rem;
}

.dashboard-left {
    flex: 1;
    min-width: 380px;
    overflow: auto;
    padding: 1.5rem;
}

.chat-panels-container {
    display: flex;
    flex-shrink: 0;
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    overflow-x: auto;
}

/* --------------------------------------------------------------------------
   Transcript / Chat Panel
   -------------------------------------------------------------------------- */
.chat-panel {
    width: 340px;
    height: 100%;
    background: #fff;
    border-left: 1px solid var(--gray-200);
    box-shadow: -2px 0 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    animation: panelSlideIn 200ms ease;
}

@keyframes panelSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

.chat-panel-flash {
    animation: panelFlash 600ms ease;
}

@keyframes panelFlash {
    0%, 100% { background: #fff; }
    50%      { background: var(--primary-light); }
}

.chat-panel-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.chat-message {
    max-width: 85%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    line-height: 1.45;
}
.chat-message-visitor {
    background: var(--gray-100);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}
.chat-message-operator {
    background: var(--primary-light);
    color: var(--primary-dark);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.chat-message-system {
    background: var(--gray-100);
    color: var(--gray-600);
    font-style: italic;
    align-self: center;
    font-size: 0.75rem;
}

.chat-message-meta {
    font-size: 0.6875rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.chat-panel-input {
    padding: 0.75rem;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.chat-panel-input .form-control {
    margin-bottom: 0.5rem;
}

/* Transcript Detail inside modal */
.transcript-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.transcript-meta-item {
    font-size: 0.8125rem;
}
.transcript-meta-item strong {
    display: block;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
    margin-bottom: 0.125rem;
}

/* --------------------------------------------------------------------------
   Login Page
   -------------------------------------------------------------------------- */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--gray-50) 100%);
}

.login-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.login-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-brand h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.login-brand p {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.login-error {
    display: none;
    padding: 0.625rem 0.75rem;
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}
.login-error.visible {
    display: block;
}

/* --------------------------------------------------------------------------
   Utility: Flex
   -------------------------------------------------------------------------- */
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.flex-wrap      { flex-wrap: wrap; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.items-end      { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-1          { flex: 1; }

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-5 { gap: 1.5rem; }

/* --------------------------------------------------------------------------
   Utility: Spacing
   -------------------------------------------------------------------------- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.5rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.5rem; }

.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }

/* --------------------------------------------------------------------------
   Utility: Typography
   -------------------------------------------------------------------------- */
.text-muted   { color: var(--gray-500); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }
.text-primary { color: var(--primary); }
.text-sm      { font-size: 0.75rem; }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.font-bold    { font-weight: 600; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* --------------------------------------------------------------------------
   Utility: Visibility
   -------------------------------------------------------------------------- */
.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   Loading Spinner
   -------------------------------------------------------------------------- */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 0.5rem;
    color: var(--gray-500);
    font-size: 0.8125rem;
}

/* --------------------------------------------------------------------------
   Empty State
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-500);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    color: var(--gray-600);
    margin-bottom: 0.375rem;
}

.empty-state p {
    font-size: 0.8125rem;
    max-width: 320px;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Responsive: <= 768px
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .hamburger {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-bar .form-group {
        min-width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .header-operator-name {
        display: none;
    }

    .dashboard-layout {
        flex-direction: column;
    }

    .dashboard-left {
        min-width: 0;
        padding: 1rem;
    }

    .chat-panels-container {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 800;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-panels-container:empty {
        display: none;
    }

    .chat-panel {
        width: 100vw;
        min-width: 100vw;
    }

    .modal {
        max-width: calc(100% - 1rem);
        margin: 0.5rem;
    }

    .modal-lg .modal {
        max-width: calc(100% - 1rem);
    }
}

/* --------------------------------------------------------------------------
   Sidebar Backdrop (mobile only)
   -------------------------------------------------------------------------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 899;
}
.sidebar-backdrop.open {
    display: block;
}

/* --------------------------------------------------------------------------
   Predefined Reply Suggestion Rows
   -------------------------------------------------------------------------- */
.suggestion-row {
    padding: 6px 8px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.8125rem;
}
.suggestion-row:hover {
    background: var(--primary-light);
}
.suggestion-row:last-child {
    border-bottom: none;
}

/* --------------------------------------------------------------------------
   Notification Modal Pulse
   -------------------------------------------------------------------------- */
#notification-modal.open .modal {
    animation: notifPulse 0.4s ease;
}
@keyframes notifPulse {
    0%   { transform: scale(0.9); opacity: 0; }
    50%  { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}

/* --------------------------------------------------------------------------
   Invite Operator Row
   -------------------------------------------------------------------------- */
.invite-operator-row:last-child {
    border-bottom: none !important;
}

/* --------------------------------------------------------------------------
   Stats Grid & Cards
   -------------------------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --------------------------------------------------------------------------
   Filter Bar (Stats Pages)
   -------------------------------------------------------------------------- */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.filter-bar select,
.filter-bar input[type="date"] {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   Emoji Picker (Operator Dashboard)
   -------------------------------------------------------------------------- */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 280px;
    max-height: 320px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
}

.emoji-picker-search {
    padding: 6px 8px;
    border-bottom: 1px solid var(--gray-200);
}

.emoji-search-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.8125rem;
    outline: none;
}

.emoji-search-input:focus {
    border-color: var(--primary);
}

.emoji-picker-cats {
    display: flex;
    gap: 2px;
    padding: 4px 6px;
    border-bottom: 1px solid var(--gray-200);
    overflow-x: auto;
    flex-shrink: 0;
}

.emoji-cat-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.emoji-cat-btn:hover { opacity: 0.8; }
.emoji-cat-btn.active { opacity: 1; background: var(--gray-100); }

.emoji-picker-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px;
    overflow-y: auto;
    max-height: 220px;
}

.emoji-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    font-size: 1.15rem;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.1s;
}

.emoji-item:hover {
    background: var(--gray-100);
}

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */
.cp-typing-indicator {
    font-size: 0.75rem;
    color: var(--gray-600);
    font-style: italic;
    padding: 0.25rem 1rem;
    border-top: 1px solid var(--gray-100);
}

.dot-anim {
    animation: dotPulse 1.5s infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 1; }
}

/* --------------------------------------------------------------------------
   Chat Attachment Link
   -------------------------------------------------------------------------- */
.chat-attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chat-attachment-link a {
    color: var(--primary);
    text-decoration: underline;
    font-size: 0.8125rem;
}

.chat-attachment-link a:hover {
    color: var(--primary-dark);
}

/* --------------------------------------------------------------------------
   Outline Button Variant
   -------------------------------------------------------------------------- */
.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

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

/* --------------------------------------------------------------------------
   Logo Upload Area (Sites Admin)
   -------------------------------------------------------------------------- */
.logo-upload-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logo-preview {
    width: 200px;
    height: 60px;
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--gray-50);
    position: relative;
}

.logo-preview.has-logo {
    border-style: solid;
    border-color: var(--gray-200);
    background: #fff;
}

.logo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--gray-400);
}

.logo-placeholder span {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.logo-upload-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-change-link {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}

.logo-change-link:hover {
    text-decoration: underline;
}

.logo-upload-area .form-text {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin: 0;
}

.logo-upload-spinner {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
