/* =========================================================================
   NextPointe Text for Webex — Embedded App Styles
   Webex-themed, responsive, dark/light mode aware
   ========================================================================= */

:root {
    --nxp-primary: #07C1E4;
    --nxp-primary-hover: #059ab8;
    --nxp-success: #2ecc71;
    --nxp-danger: #e74c3c;
    --nxp-warning: #f39c12;

    /* Light mode defaults */
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f7;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f0;
    --text-primary: #121212;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Dark mode (Webex dark theme) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #242424;
        --bg-card: #2a2a2a;
        --bg-hover: #333333;
        --text-primary: #f0f0f0;
        --text-secondary: #b0b0b0;
        --text-muted: #777777;
        --border-color: #3a3a3a;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-hover: 0 2px 8px rgba(0, 0, 0, 0.4);
    }
}

/* ---- Reset & Base ---- */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "CiscoSans", "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

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

a:hover {
    text-decoration: underline;
}

/* ---- Layout ---- */

.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
}

/* ---- Header ---- */

.app-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.app-header .logo {
    width: 28px;
    height: 28px;
    background: var(--nxp-primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.app-header .title {
    font-size: 16px;
    font-weight: 600;
}

.app-header .subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ---- Views (show/hide) ---- */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ---- Loading ---- */

.loading-view {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--nxp-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-view p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ---- Error ---- */

.error-view {
    text-align: center;
    padding: 40px 20px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.error-view h2 {
    font-size: 18px;
    margin-bottom: 8px;
}

.error-view p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ---- Auth view ---- */

.auth-view {
    text-align: center;
    padding: 40px 20px;
}

.auth-view .welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--nxp-primary), #059ab8);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 28px;
    color: white;
}

.auth-view h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.auth-view p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.auth-view .tenant-badge {
    display: inline-block;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 16px;
    margin-bottom: 24px;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-view .tenant-badge strong {
    color: var(--text-primary);
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    border: none;
    border-radius: 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--nxp-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--nxp-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* ---- Conversations view ---- */

.conversations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.conversations-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.conversations-header .user-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.conversation-list {
    list-style: none;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid var(--border-color);
}

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

.conversation-item:hover {
    background: var(--bg-hover);
}

.conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.conversation-body {
    flex: 1;
    min-width: 0;
}

.conversation-phone {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-meta {
    text-align: right;
    flex-shrink: 0;
}

.conversation-time {
    font-size: 11px;
    color: var(--text-muted);
}

.conversation-count {
    display: inline-block;
    background: var(--nxp-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 7px;
    margin-top: 4px;
}

/* ---- Empty state ---- */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

/* ---- Conversation detail ---- */

.detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.detail-header .back-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--nxp-primary);
    padding: 4px 8px;
    border-radius: 6px;
}

.detail-header .back-btn:hover {
    background: var(--bg-hover);
}

.detail-header-text {
    flex: 1;
    min-width: 0;
}

.detail-header .detail-phone {
    font-size: 16px;
    font-weight: 600;
}

.detail-did {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.conversation-did {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 16px;
}

.message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-inbound {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-outbound {
    align-self: flex-end;
    background: var(--nxp-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--text-secondary);
}

.message-outbound .message-sender {
    color: rgba(255, 255, 255, 0.8);
}

.message-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
}

.message-outbound .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* ---- Message media attachments ---- */

.message-media {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.message-media-img {
    max-width: 100%;
    max-height: 240px;
    border-radius: 10px;
    object-fit: contain;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.message-media-img:hover {
    opacity: 0.85;
}

.message-media-link {
    display: block;
    line-height: 0;
}

.message-media-video {
    max-width: 100%;
    max-height: 240px;
    border-radius: 10px;
}

.message-media-audio {
    width: 100%;
    max-width: 250px;
}

.message-media-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--bg-hover);
    color: var(--nxp-primary);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s ease;
}

.message-media-file:hover {
    background: var(--border-color);
    text-decoration: none;
}

.message-outbound .message-media-file {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-outbound .message-media-file:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ---- Header actions (New + Refresh) ---- */

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ---- Compose form ---- */

.compose-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
}

.compose-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: -8px;
}

.compose-input,
.compose-select,
.compose-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.15s ease;
}

.compose-input:focus,
.compose-select:focus,
.compose-textarea:focus {
    outline: none;
    border-color: var(--nxp-primary);
}

.compose-textarea {
    resize: vertical;
    min-height: 60px;
}

.compose-select {
    appearance: auto;
}

.compose-send-btn {
    align-self: flex-end;
    margin-top: 4px;
}

.compose-error {
    font-size: 12px;
    color: var(--nxp-danger);
    min-height: 16px;
    text-align: center;
}

/* ---- Status badges ---- */

.status-connected {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--nxp-success);
    font-size: 12px;
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ---- Refresh button ---- */

.refresh-btn {
    background: none;
    border: none;
    color: var(--nxp-primary);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.refresh-btn:hover {
    background: var(--bg-hover);
}

/* ---- Toast notifications ---- */

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-hover);
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 13px;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
}

.toast.toast-error {
    border-color: var(--nxp-danger);
    color: var(--nxp-danger);
}

.toast.toast-success {
    border-color: var(--nxp-success);
    color: var(--nxp-success);
}

/* ---- Channel badges ---- */

.channel-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 5px;
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 4px;
}

.channel-badge--sms {
    background: rgba(7, 193, 228, 0.15);
    color: var(--nxp-primary);
}

.channel-badge--wa {
    background: rgba(37, 211, 102, 0.15);
    color: #25d366;
}

/* ---- Reply bar ---- */

.reply-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
}

.reply-input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 13px;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.15s ease;
}

.reply-input:focus {
    outline: none;
    border-color: var(--nxp-primary);
}
