/* ═══════════════════════════════════════════════════════════════════════
   SECRETARIA MODULE — WhatsApp-like message viewer + Config
   ═══════════════════════════════════════════════════════════════════════ */

.sec-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topnav-height));
}

/* Tabs */
.sec-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.sec-tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sec-tab:hover { color: var(--text); background: var(--bg); }
.sec-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.sec-content {
    flex: 1;
    overflow: hidden;
}

/* ===== CHAT LAYOUT (WhatsApp-like) ===== */

.sec-chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100%;
}

/* Sidebar — conversation list */
.sec-sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sec-sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sec-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sec-search-wrap > i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.8rem;
    pointer-events: none;
}

.sec-search-wrap input {
    flex: 1;
    padding: 0.55rem 0.75rem 0.55rem 2.2rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg);
}

.sec-search-wrap input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.sec-add-contact-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    transition: all 0.15s;
}

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

.sec-delete-conv-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.35rem 0.55rem;
    font-size: 0.75rem;
    transition: all 0.15s;
}

.sec-delete-conv-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: #fef2f2;
}

/* Modal */
.sec-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sec-modal {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 90%;
    max-width: 420px;
    overflow: hidden;
}

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

.sec-modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sec-modal-close {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.2rem;
}

.sec-modal-close:hover {
    color: var(--danger);
}

.sec-modal-body {
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.sec-modal-body input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
}

.sec-modal-body input:focus {
    outline: none;
    border-color: var(--primary);
}

.sec-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 0.8rem 1.2rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.sec-modal-footer button {
    padding: 0.5rem 1.2rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    font-weight: 500;
}

.sec-modal-footer .btn-secondary {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.sec-modal-footer .btn-primary {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: #fff;
}

.sec-modal-footer .btn-primary:hover {
    opacity: 0.9;
}

.sec-conv-list {
    flex: 1;
    overflow-y: auto;
}

.sec-sidebar-footer {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.sec-stats-mini {
    display: flex;
    gap: 1rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.sec-stats-mini strong {
    color: var(--text);
}

/* Conversation item */
.sec-conv-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
}

.sec-conv-item:hover { background: var(--bg); }
.sec-conv-item.active { background: #e8f0fe; }

.sec-conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.sec-conv-info {
    flex: 1;
    min-width: 0;
}

.sec-conv-header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.sec-conv-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sec-conv-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.sec-conv-preview {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.15rem;
}

.sec-role-icon {
    font-size: 0.65rem;
    color: var(--primary);
    margin-right: 0.25rem;
}

.sec-conv-badge {
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.35rem;
    flex-shrink: 0;
}

/* ===== CHAT AREA ===== */

.sec-chat-area {
    display: flex;
    flex-direction: column;
    background: #d4e2f7;
    overflow: hidden;
}

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

.sec-chat-header-info strong {
    font-size: 0.92rem;
    display: block;
}

.sec-chat-phone {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sec-chat-status {
    font-size: 0.72rem;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    background: var(--bg);
    color: var(--text-secondary);
    font-weight: 500;
}

.sec-chat-status.online {
    background: #dcfce7;
    color: #166534;
}

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

.sec-chat-footer {
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sec-empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.sec-empty-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.sec-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    gap: 0.5rem;
}

/* Date divider */
.sec-date-divider {
    text-align: center;
    margin: 0.75rem 0;
}

.sec-date-divider span {
    background: rgba(255,255,255,0.85);
    padding: 0.25rem 0.85rem;
    border-radius: 8px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Message bubbles */
.sec-msg {
    display: flex;
    max-width: 75%;
}

.sec-msg-in {
    align-self: flex-start;
}

.sec-msg-out {
    align-self: flex-end;
}

.sec-msg-bubble {
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.45;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.sec-msg-in .sec-msg-bubble {
    background: white;
    border-bottom-left-radius: 3px;
}

.sec-msg-out .sec-msg-bubble {
    background: #d9fdd3;
    border-bottom-right-radius: 3px;
}

.sec-msg-text {
    word-wrap: break-word;
}

.sec-msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    margin-top: 0.25rem;
}

.sec-msg-time {
    font-size: 0.65rem;
    color: rgba(0,0,0,0.4);
}

.sec-msg-read {
    font-size: 0.6rem;
    color: #53bdeb;
}

.sec-msg-intent {
    font-size: 0.6rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 500;
}

/* ===== CONFIG ===== */

.sec-config {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - var(--topnav-height) - 50px);
}

.sec-config-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.sec-config-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
}

.sec-config-section h3 i {
    color: var(--primary);
}

.sec-config-field {
    margin-bottom: 0.85rem;
}

.sec-config-field label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    font-weight: 500;
}

.sec-config-field textarea,
.sec-config-field input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    background: var(--bg);
}

.sec-config-field textarea:focus,
.sec-config-field input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.sec-config-hint {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    display: block;
}

/* Working hours */
.sec-config-hours {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sec-hour-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sec-hour-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 120px;
    cursor: pointer;
}

.sec-hour-toggle input[type="checkbox"] {
    accent-color: var(--primary);
}

.sec-hour-day {
    font-size: 0.82rem;
    font-weight: 500;
}

.sec-hour-start,
.sec-hour-end {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    width: 110px;
}

.sec-hour-start:focus,
.sec-hour-end:focus {
    outline: none;
    border-color: var(--primary);
}

.sec-hour-sep {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Toggle options */
.sec-config-toggle {
    margin-bottom: 0.6rem;
}

.sec-config-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.sec-config-toggle input[type="checkbox"] {
    accent-color: var(--primary);
    width: 18px;
    height: 18px;
}

.sec-config-actions {
    padding: 0.5rem 0;
}

.sec-config-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
    gap: 0.5rem;
}


/* ===== HUMAN SECRETARY REPLY + TAKEOVER ===== */

/* Takeover badge in conversation list */
.sec-takeover-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.6rem;
    color: #d97706;
    margin-left: 0.25rem;
    vertical-align: middle;
}

/* Takeover button in chat header */
.sec-takeover-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: 0.5rem;
}

.sec-takeover-btn:hover {
    background: #fef3c7;
    border-color: #d97706;
    color: #92400e;
}

.sec-takeover-btn.active {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1d4ed8;
}

.sec-takeover-btn.active:hover {
    background: #bfdbfe;
}

/* Reply footer */
.sec-reply-footer {
    padding: 0.5rem 0.75rem;
}

.sec-reply-input-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.sec-reply-input-wrap input {
    flex: 1;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg);
    transition: border-color 0.15s;
}

.sec-reply-input-wrap input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.sec-reply-input-wrap input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sec-reply-send {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.sec-reply-send:hover {
    background: var(--primary-dark, #2563eb);
}

.sec-reply-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sec-reply-hint {
    display: block;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.35rem;
    padding: 0 0.25rem;
}

.sec-reply-hint.sec-hint-active {
    color: #d97706;
}

/* Sender labels on messages */
.sec-msg-sender {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.sec-sender-clara {
    color: #7c3aed;
}

.sec-sender-secretary {
    color: #d97706;
}

/* Secretary message bubble — slightly different color */
.sec-msg-secretary .sec-msg-bubble {
    background: #fef9c3;
    border-bottom-right-radius: 3px;
}

/* Chat header actions flex */
.sec-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════════════════
   SIDEBAR MESSAGING — Contacts + Chat in right sidebar
   ═══════════════════════════════════════════════════════════════════════ */

/* ===== SIDEBAR INTERNAL MESSAGES ===== */

.ctx-msg-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

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

.ctx-msg-header-left {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.ctx-msg-title {
    font-weight: 600;
    font-size: 0.8rem;
}

.ctx-msg-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.08rem 0.35rem;
    border-radius: 9px;
    min-width: 16px;
    text-align: center;
}

.ctx-msg-filters {
    display: flex;
    gap: 0.3rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.ctx-filter-chip {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.ctx-filter-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.ctx-msg-feed {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 0.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ctx-msg-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.ctx-feed-msg {
    padding: 0.4rem 0.55rem;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 3px solid var(--border);
}

.ctx-feed-msg.ctx-feed-me {
    background: #eff6ff;
    border-left-color: var(--primary);
}

.ctx-feed-top {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-bottom: 0.15rem;
}

.ctx-feed-sender {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text);
}

.ctx-feed-role {
    font-size: 0.55rem;
    font-weight: 600;
    padding: 0.05rem 0.3rem;
    border-radius: 6px;
}

.ctx-feed-target {
    font-size: 0.58rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.ctx-feed-target i {
    font-size: 0.5rem;
}

.ctx-feed-time {
    font-size: 0.58rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.ctx-feed-text {
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text);
    word-break: break-word;
}

.ctx-msg-compose {
    border-top: 1px solid var(--border);
    padding: 0.4rem 0.5rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.ctx-compose-to {
    display: flex;
}

.ctx-compose-select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.4rem;
    font-size: 0.7rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.ctx-compose-select:focus {
    border-color: var(--primary);
}

/* Multi-select dropdown */
.ctx-multiselect {
    position: relative;
    width: 100%;
}

.ctx-multiselect-btn {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    text-align: left;
}

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

.ctx-multiselect-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    color: var(--text-secondary);
}

.ctx-multiselect-arrow {
    font-size: 0.55rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.ctx-multiselect-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
    padding: 0.3rem 0;
    margin-bottom: 4px;
}

.ctx-multiselect-group {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.35rem 0.6rem 0.15rem;
}

.ctx-multiselect-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text);
}

.ctx-multiselect-item:hover {
    background: #f0f5ff;
}

.ctx-multiselect-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* Doctor reply button on messages */
.ctx-reply-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 0.2rem;
    font-size: 0.6rem;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.ctx-feed-msg:hover .ctx-reply-btn {
    opacity: 1;
}

.ctx-reply-btn:hover {
    color: var(--primary);
}

/* Doctor reply bar */
.ctx-reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #eff6ff;
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    color: var(--text);
}

.ctx-reply-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.ctx-reply-label i {
    color: var(--primary);
    font-size: 0.6rem;
}

.ctx-reply-cancel {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.15rem;
    font-size: 0.65rem;
    border-radius: 50%;
    line-height: 1;
}

.ctx-reply-cancel:hover {
    color: var(--danger);
    background: rgba(0,0,0,0.05);
}

.ctx-compose-row {
    display: flex;
    gap: 0.3rem;
}

.ctx-compose-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    outline: none;
    font-family: inherit;
}

.ctx-compose-input:focus {
    border-color: var(--primary);
}

.ctx-compose-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.ctx-compose-btn:hover {
    opacity: 0.85;
}

.ctx-compose-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ctx-compose-btn i {
    font-size: 0.7rem;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 900px) {
    .sec-chat-layout {
        grid-template-columns: 250px 1fr;
    }

}

@media (max-width: 700px) {
    .sec-chat-layout {
        grid-template-columns: 1fr;
    }
    .sec-sidebar {
        max-height: 40vh;
    }
}


/* ===== CONTACTS TAB ===== */

.sec-contatos-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: 100%;
}

.sec-contatos-sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sec-contatos-toolbar {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sec-contatos-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.sec-filter-select {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.78rem;
    font-family: inherit;
    background: var(--bg);
    cursor: pointer;
}

.sec-filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

.sec-btn-icon {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    transition: all 0.15s;
    flex-shrink: 0;
}

.sec-btn-icon:hover {
    background: var(--bg-card);
    color: var(--primary);
    border-color: var(--primary);
}

.sec-btn-add {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.sec-btn-add:hover {
    background: var(--primary-dark, #2563eb);
    color: white;
}

.sec-contatos-list {
    flex: 1;
    overflow-y: auto;
}

.sec-contatos-detail {
    padding: 1.25rem;
    overflow-y: auto;
    background: var(--bg);
}

/* Contact item */
.sec-contact-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.7rem 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
}

.sec-contact-item:hover { background: var(--bg); }
.sec-contact-item.active { background: #e8f0fe; }
.sec-contact-item.blocked { opacity: 0.6; }

.sec-contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sec-contact-info {
    flex: 1;
    min-width: 0;
}

.sec-contact-header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.sec-contact-name {
    font-weight: 600;
    font-size: 0.84rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sec-contact-time {
    font-size: 0.68rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.sec-contact-phone {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

.sec-contact-badges {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.2rem;
}

.sec-contact-badge {
    font-size: 0.62rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
}

.sec-contact-badge.linked {
    background: #dcfce7;
    color: #166534;
}

.sec-contact-badge.unlinked {
    background: #fef3c7;
    color: #92400e;
}

.sec-contact-badge.blocked {
    background: #fee2e2;
    color: #991b1b;
}

.sec-source-icon {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

/* Contact detail card */
.sec-contact-detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 500px;
}

.sec-contact-detail-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.sec-contact-detail-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.sec-contact-detail-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.sec-contact-detail-phone {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sec-contact-detail-info {
    margin-bottom: 1.25rem;
}

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

.sec-detail-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.sec-contact-detail-notes {
    margin-bottom: 1.25rem;
}

.sec-contact-detail-notes label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.sec-contact-detail-notes textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    background: var(--bg);
    margin-bottom: 0.5rem;
}

.sec-contact-detail-notes textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.sec-contact-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.sec-btn-action {
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.15s;
}

.sec-btn-action:hover {
    background: var(--bg-card);
    border-color: var(--primary);
    color: var(--primary);
}

.sec-btn-block:hover {
    border-color: #f59e0b;
    color: #d97706;
    background: #fef3c7;
}

.sec-btn-unblock:hover {
    border-color: #10b981;
    color: #059669;
    background: #dcfce7;
}

.sec-btn-delete:hover {
    border-color: #ef4444;
    color: #dc2626;
    background: #fee2e2;
}

.sec-btn-small {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.15s;
}

.sec-btn-small:hover {
    background: var(--bg-card);
    color: var(--text);
}

/* Patient picker overlay */
.sec-picker-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.97);
    padding: 1.5rem;
    z-index: 10;
    border-radius: 12px;
    overflow-y: auto;
}

.sec-patient-picker h4 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.sec-patient-picker-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
}

.sec-patient-pick-item {
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.sec-patient-pick-item:hover {
    background: #e8f0fe;
}

.sec-patient-pick-item:last-child {
    border-bottom: none;
}

.sec-patient-pick-item strong {
    font-weight: 600;
}

.sec-patient-pick-item span {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

/* Responsive */
@media (max-width: 900px) {
    .sec-contatos-layout {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 700px) {
    .sec-contatos-layout {
        grid-template-columns: 1fr;
    }
    .sec-contatos-detail {
        display: none;
    }
}

/* Contact avatar photo */
.sec-contact-avatar img,
.sec-contact-detail-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
