/* ============================================
   Parladesk — Core Styles
   ============================================ */

/* --- Custom Properties --- */
:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;

    --header-height: 56px;

    --sidebar-width: 220px;
    --sidebar-bg: var(--color-surface);
    --sidebar-text: var(--color-text-muted);
    --sidebar-active: var(--color-primary);

    --radius: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.04);

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
}

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

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* --- Layout --- */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 200;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.app-header-right {
    display: flex;
    align-items: center;
}

.app-brand {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.app-brand:hover {
    text-decoration: none;
    color: var(--color-text);
}

.app-header-sep {
    width: 1px;
    height: 20px;
    background: var(--color-border);
}

.app-header .page-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-muted);
}

/* --- User Menu --- */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1);
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: opacity 0.15s;
}

.user-menu-trigger:hover {
    opacity: 0.8;
}

.user-menu-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 600;
    font-family: inherit;
    line-height: 1;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-2));
    width: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    overflow: hidden;
}

.user-menu.open .user-menu-dropdown {
    display: block;
}

.user-menu-info {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.user-menu-name {
    font-weight: 500;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.user-menu-role {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.user-menu-item {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.user-menu-item:hover {
    background: var(--color-bg);
    text-decoration: none;
    color: var(--color-text);
}

.app-body {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    flex: 1;
}

/* --- Footer --- */
.app-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-footer-text {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
}

/* --- Sidebar --- */
.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 100;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
}

.sidebar-close {
    display: none;
    padding: var(--space-3) var(--space-4);
    text-align: right;
}

.sidebar-close button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-3) 0;
}

.nav-section {
    padding: var(--space-4) var(--space-4) var(--space-2);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-light);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.nav-item:hover {
    background: var(--color-bg);
    text-decoration: none;
    color: var(--color-text);
}

.nav-item.active {
    background: var(--color-primary-light);
    border-left-color: var(--sidebar-active);
    color: var(--color-primary);
    font-weight: 500;
}

.nav-badge {
    margin-left: auto;
    background: var(--color-primary);
    color: #fff;
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}

/* --- Main Content --- */
.main-content {
    grid-column: 2;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--color-text);
    padding: var(--space-1);
}

.content-area {
    padding: var(--space-8) var(--space-6);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    font-size: var(--font-size-sm);
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.btn:hover { text-decoration: none; }

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

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
}

/* --- Forms --- */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: var(--space-1);
    color: var(--color-text);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

.form-group textarea {
    min-height: 120px;
    resize: vertical;
}

.form-row {
    display: flex;
    gap: var(--space-4);
}

.form-row .form-group { flex: 1; }
.form-row .form-group-small { flex: 0 0 120px; }

.form-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    padding-top: var(--space-4);
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

fieldset legend {
    font-weight: 600;
    font-size: var(--font-size-sm);
    padding: 0 var(--space-2);
}

/* --- Tables --- */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--color-border);
    background: var(--color-bg);
    white-space: nowrap;
}

tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

tbody tr:hover {
    background: var(--color-bg);
}

/* --- Cards --- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
}

.card-body {
    padding: var(--space-5);
}

/* --- Stat Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: 999px;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-open { background: var(--color-primary-light); color: var(--color-primary); }
.badge-pending { background: var(--color-warning-light); color: var(--color-warning); }
.badge-resolved { background: var(--color-success-light); color: var(--color-success); }
.badge-closed { background: #f1f5f9; color: var(--color-text-muted); }
.badge-info { background: var(--color-primary-light); color: var(--color-primary); }

.badge-low { background: #f1f5f9; color: var(--color-text-muted); }
.badge-normal { background: var(--color-primary-light); color: var(--color-primary); }
.badge-high { background: #ffedd5; color: #c2410c; }
.badge-urgent { background: var(--color-danger-light); color: var(--color-danger); }

/* --- Alerts --- */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
}

.alert-success { background: var(--color-success-light); color: #166534; border-color: #bbf7d0; }
.alert-error { background: var(--color-danger-light); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--color-warning-light); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--color-primary-light); color: #1e40af; border-color: #bfdbfe; }

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: var(--space-6);
    justify-content: center;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-2);
    font-size: var(--font-size-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    text-decoration: none;
}

.pagination a:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.pagination .active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.pagination .disabled {
    color: var(--color-text-light);
    pointer-events: none;
}

/* --- Ticket List --- */
.ticket-row {
    cursor: pointer;
}

.ticket-row:hover {
    background: var(--color-primary-light);
}

.ticket-subject {
    font-weight: 500;
}

.ticket-subject a {
    color: var(--color-text);
}

.ticket-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.ticket-unread .ticket-subject {
    font-weight: 700;
}

.ticket-row.highlighted {
    background: var(--color-primary-light);
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* --- Thread --- */
.thread-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.thread-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.thread-item-customer {
    background: var(--color-surface);
}

.thread-item-agent {
    background: var(--color-primary-light);
    border-color: #bfdbfe;
}

.thread-item-note {
    background: var(--color-warning-light);
    border-color: #fde68a;
    border-style: dashed;
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid inherit;
}

.thread-author {
    font-weight: 600;
}

.thread-date {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.thread-body {
    padding: var(--space-4);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    overflow-wrap: break-word;
}

.thread-body-frame {
    width: 100%;
    border: none;
    min-height: 60px;
}

.thread-body img {
    max-width: 100%;
    height: auto;
}

.thread-attachments {
    padding: var(--space-2) var(--space-4) var(--space-4);
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: var(--font-size-xs);
    color: var(--color-text);
}

.attachment-link:hover {
    background: var(--color-surface);
    text-decoration: none;
}

/* --- Reply Composer --- */
.reply-composer {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-top: var(--space-6);
}

.reply-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
}

.reply-tab {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    font-family: inherit;
}

.reply-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.reply-body {
    padding: var(--space-4);
}

/* --- Ticket Sidebar --- */
.ticket-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--space-6);
}

.ticket-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.sidebar-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.sidebar-section h3 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--space-3);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: var(--font-size-xs);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--color-border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--color-text-muted);
}

/* --- Filter Bar --- */
.filter-bar {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input[type="text"] {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-family: inherit;
}

/* --- Bulk Actions --- */
.bulk-bar {
    display: none;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-primary-light);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    font-size: var(--font-size-sm);
}

.bulk-bar.visible {
    display: flex;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--color-text-muted);
}

.empty-state h3 {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.empty-state p {
    margin-bottom: var(--space-4);
}

/* --- Activity Feed --- */
.activity-feed {
    list-style: none;
}

.activity-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-time {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    white-space: nowrap;
}

/* --- Utility --- */
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* --- Setup Page --- */
.setup-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.setup-container {
    width: 100%;
    max-width: 600px;
    padding: var(--space-8);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin: var(--space-4);
}

.setup-container h1 {
    text-align: center;
    margin-bottom: var(--space-6);
}

.setup-container h2 {
    margin-bottom: var(--space-4);
}

.setup-steps {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    margin-bottom: var(--space-6);
}

.setup-step {
    font-size: var(--font-size-xs);
    padding: var(--space-1) var(--space-3);
    border-radius: 999px;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-weight: 500;
}

.setup-step.active {
    background: var(--color-primary);
    color: #fff;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.login-wrapper {
    width: 100%;
    max-width: 400px;
    margin: var(--space-4);
}

.login-brand {
    text-align: center;
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.login-subtitle {
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-6);
}

.login-container {
    width: 100%;
    padding: var(--space-8);
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.login-footer {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    margin-top: var(--space-6);
}

/* Automation rule builder rows */
.rule-row {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    align-items: center;
}
.rule-row select,
.rule-row input[type="text"] {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
}
.rule-row select { flex: 0 0 auto; }
.rule-row input[type="text"] { flex: 1; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-header {
        padding: 0 var(--space-4);
    }

    .app-body {
        grid-template-columns: 1fr;
    }

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

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

    .sidebar-close {
        display: block;
    }

    .hamburger {
        display: block;
    }

    .main-content {
        grid-column: 1;
    }

    .content-area {
        padding: var(--space-4);
    }

    .ticket-layout {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
    }

    .form-row .form-group-small {
        flex: auto;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .app-footer {
        padding: var(--space-4);
        flex-direction: column;
        gap: var(--space-2);
        text-align: center;
    }
}

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

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

/* --- Checkbox in tables --- */
table input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* --- Presence / Collision Detection --- */
.presence-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 0;
}

.presence-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-border);
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: default;
}

.presence-badge.presence-replying {
    background: var(--color-warning-light);
    color: var(--color-warning);
    animation: presence-pulse 2s ease-in-out infinite;
}

@keyframes presence-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(217, 119, 6, 0); }
}

.collision-warning {
    padding: 8px 12px;
    background: var(--color-warning-light);
    color: var(--color-warning);
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
}

/* --- Saved Replies Dropdown --- */
.saved-replies-dropdown {
    position: relative;
    display: inline-block;
}

.saved-replies-menu {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: var(--space-2);
    width: 320px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.saved-replies-menu.open {
    display: block;
}

.saved-replies-search {
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

.saved-replies-search input {
    width: 100%;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
}

.saved-replies-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 240px;
    overflow-y: auto;
}

.saved-reply-item {
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
}

.saved-reply-item:last-child {
    border-bottom: none;
}

.saved-reply-item:hover {
    background: var(--color-primary-light);
}

.saved-reply-name {
    display: block;
    font-weight: 600;
    font-size: var(--font-size-sm);
}

.saved-reply-preview {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.saved-reply-category {
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
    pointer-events: none;
}

/* --- Star Toggle --- */
.star-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-lg);
    color: var(--color-text-light);
    padding: 0;
    line-height: 1;
}
.star-toggle:hover,
.star-toggle.starred {
    color: var(--color-warning);
}
.star-cell {
    width: 32px;
    text-align: center;
}

/* --- Tag Badges --- */
.tag-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    margin: 1px 2px;
    white-space: nowrap;
}
.tag-badge .tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-xs);
    margin-left: 2px;
    padding: 0;
    opacity: 0.6;
    color: inherit;
}
.tag-badge .tag-remove:hover { opacity: 1; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-green { background: #dcfce7; color: #166534; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-yellow { background: #fef3c7; color: #92400e; }
.tag-purple { background: #f3e8ff; color: #6b21a8; }
.tag-orange { background: #ffedd5; color: #9a3412; }
.tag-gray { background: #f1f5f9; color: #475569; }
.tag-teal { background: #ccfbf1; color: #115e59; }

#tag-picker {
    margin-top: var(--space-2);
    width: 100%;
    font-size: var(--font-size-sm);
}

/* --- Live Search Dropdown --- */
.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 150px;
}
.search-wrapper input[name="search"] {
    width: 100%;
}
.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
}
.search-dropdown.open {
    display: block;
}
.search-result {
    display: block;
    padding: var(--space-2) var(--space-3);
    text-decoration: none;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
}
.search-result:last-child {
    border-bottom: none;
}
.search-result:hover,
.search-result.highlighted {
    background: var(--color-primary-light);
}
.search-result-number {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--color-primary);
}
.search-result-subject {
    font-size: var(--font-size-sm);
    margin-left: var(--space-2);
}
.search-result-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

/* --- Customer History --- */
.customer-history {
    list-style: none;
}
.customer-history-item a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
    font-size: var(--font-size-xs);
}
.customer-history-item:last-child a {
    border-bottom: none;
}
.customer-history-item a:hover {
    color: var(--color-primary);
}
.customer-history-number {
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
}
.customer-history-subject {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.customer-history-date {
    color: var(--color-text-muted);
    white-space: nowrap;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.status-open { background: var(--color-success); }
.status-dot.status-pending { background: var(--color-warning); }
.status-dot.status-resolved { background: var(--color-primary); }
.status-dot.status-closed { background: var(--color-text-muted); }

/* --- Signature Preview --- */
.signature-preview {
    padding: var(--space-2) var(--space-3);
    margin: 0 0 var(--space-3) 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}
.signature-separator {
    margin-bottom: var(--space-1);
}
.signature-text {
    line-height: 1.5;
}

/* --- Rich Text Editor --- */
.editor-toolbar {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar-btn {
    padding: var(--space-1) var(--space-2);
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    line-height: 1;
    min-width: 28px;
    text-align: center;
}
.toolbar-btn:hover {
    background: var(--color-surface);
    border-color: var(--color-border);
}
.editor-area {
    min-height: 150px;
    max-height: 400px;
    overflow-y: auto;
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--color-surface);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    outline: none;
}
.editor-area:focus {
    border-color: var(--color-primary);
}
.editor-area:empty::before {
    content: 'Type your reply...';
    color: var(--color-text-light);
    pointer-events: none;
}
.editor-area blockquote {
    border-left: 3px solid var(--color-border);
    margin: 0.5em 0;
    padding: 0 0.8em;
    color: var(--color-text-muted);
}
.editor-area ul, .editor-area ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}
.editor-area a {
    color: var(--color-primary);
    text-decoration: underline;
}

/* --- CC/BCC Fields --- */
.cc-bcc-toggle {
    padding: 0 0 var(--space-2) 0;
}
.cc-bcc-toggle a {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-decoration: none;
}
.cc-bcc-toggle a:hover {
    color: var(--color-primary);
}
.cc-bcc-fields .form-group {
    margin-bottom: var(--space-2);
}
.thread-cc {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    padding: 0 var(--space-3);
    margin-bottom: var(--space-2);
}

/* --- Forward To Field --- */
.forward-to-field {
    margin-bottom: var(--space-2);
}

/* --- Merge Results --- */
.merge-results { margin-top: var(--space-2); }
.merge-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: var(--space-1);
    gap: var(--space-2);
}

/* --- Undo Send Banner --- */
.undo-banner {
    background: var(--color-primary-light);
    border: 1px solid #bfdbfe;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    margin-top: var(--space-6);
    font-size: var(--font-size-sm);
}
.undo-banner a {
    font-weight: 600;
    text-decoration: underline;
}

/* Collision warning pulsing dot */
.collision-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-danger);
    animation: pulse 1.5s ease-in-out infinite;
    vertical-align: middle;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
