/* ============================================
   Custom title bar styles
   Using unified spec: --z-light-titlebar (10300)
   ============================================ */
.custom-titlebar {
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-app-region: drag;
    user-select: none;
    flex-shrink: 0;
    position: relative;
    z-index: 10300; /* Matches --z-light-titlebar */
}

.titlebar-drag-region {
    display: flex;
    align-items: center;
    flex: 1;
    height: 100%;
    padding-left: 12px;
    gap: 8px;
}

.titlebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Title bar unread email count badge */
.titlebar-unread-badge {
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    margin-left: -8px;
    margin-top: -12px;
    background-color: #ff4d4f;
    color: white;
    font-size: 9px;
    font-weight: bold;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    z-index: 100;
    animation: badgePulse 2s ease-in-out infinite;
    flex-shrink: 0;
    position: relative;
    -webkit-app-region: no-drag;
    pointer-events: auto;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.titlebar-avatar {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}

.titlebar-title {
    color: white;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.titlebar-nat {
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
    font-weight: 400;
    margin-left: 8px;
    padding: 2px 8px;
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    white-space: nowrap;
}

.titlebar-controls {
    display: flex;
    -webkit-app-region: no-drag;
    height: 100%;
}

.titlebar-btn {
    width: 46px;
    height: 100%;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    padding: 0;
}

.titlebar-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.titlebar-btn.close:hover {
    background-color: #e81123;
}

.titlebar-btn.logout:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.titlebar-btn.debug:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.titlebar-btn svg {
    pointer-events: none;
}

html {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0px;
    background-color: #f5f5f5;
    font-size: 14px;
    line-height: 1.3;
    min-height: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Allow scrollbar to appear automatically after login */
body.logged-in {
    overflow: auto;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background-color: white;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
    padding: 0px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

h1 {
    color: #333;
    text-align: center;
    margin-bottom: 20px;
    font-size: 24px;
}

.config-section {
    margin-bottom: 0px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #fafafa;
    overflow: auto;
    max-height: 100vh;
}

.config-selector {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Account avatar container */
.config-avatar-container {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

/* Account avatar styles */
.config-avatar {
    width: 96px;
    height: 96px;
    border: 1px solid #ccc;
    border-radius: 4px;
    object-fit: cover;
}

.config-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.config-actions-secondary {
    margin-top: 4px;
}

/* Login button length doubled */
.btn-login {
    min-width: 120px;
    padding: 8px 32px;
}

.config-select {
    flex: 1;
    max-width: 400px;
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
    cursor: pointer;
}

.config-select:focus {
    border-color: #4CAF50;
    outline: none;
}

.lang-select {
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
    cursor: pointer;
    min-width: 110px;
}

.lang-select:focus {
    border-color: #4CAF50;
    outline: none;
}

.btn {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 8px 16px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin: 5px 1px;
    cursor: pointer;
    border-radius: 3px;
    transition: background-color 0.3s;
}

.btn:hover {
    background-color: #45a049;
}

/* Keep login button green */
.btn-login {
    background-color: #4CAF50;
}

.btn-login:hover {
    background-color: #45a049;
}

.btn-warning {
    background-color: #D4A017;
    color: white;
}

.btn-warning:hover {
    background-color: #B88A0F;
}

/* Add account button - small blue */
.btn-primary {
    background-color: #5B9BD5;
    color: white;
}

.btn-primary:hover {
    background-color: #4A8BC2;
}

.btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-secondary:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

/* Status message (using unified spec: --z-light-status) */
.status {
    padding: 8px 16px;
    margin: 0;
    border-radius: 3px;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    position: fixed;
    top: 32px;
    left: 32px;
    z-index: 10400; /* Matches --z-light-status */
    width: auto;
    max-width: 300px;
}

.status-animation {
    opacity: 1;
    transform: translateY(0);
    animation: statusFade 2s ease-in-out forwards;
}

@keyframes statusFade {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }

    10% {
        opacity: 1;
        transform: translateY(0);
    }

    90% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.status-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.status-success {
    background-color: rgba(212, 237, 218, 0.7);
    color: #155724;
    border: 1px solid rgba(195, 230, 203, 0.7);
}

.status-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.loading {
    text-align: center;
    padding: 15px;
}

.hidden-by-default {
    display: none;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4CAF50;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0 auto 8px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* New webcom layout styles */
.webcom-container {
    display: none;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    margin-top: 0px;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.webcom-container.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

/* Webcom wrapper (using unified spec: --z-shadow-floating) */
.webcom-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 10px;
    height: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    background-color: #fff;
    cursor: pointer;
    z-index: 100; /* Matches --z-shadow-floating */
    transition: all 0.3s ease;
    margin-right: 2px;
    margin-bottom: 2px;
}

/* First webcom (send email) keeps original styles */
.webcom-wrapper:first-child {
    position: relative;
    width: 240px;
    height: 100%;
    flex: 0 0 240px;
    z-index: 100; /* Matches --z-shadow-floating */
}

/* Active state chat webcom styles */
.webcom-wrapper.active {
    position: relative;
    top: auto;
    left: auto !important;
    width: auto !important;
    height: 100%;
    flex: 1 !important;
    min-height: 0;
    z-index: 50; /* Matches --z-shadow-content */
    cursor: default;
}

/* Chat webcom styles */
.webcom-wrapper:not(:first-child) {
    display: block;
    /* Fixed empty ruleset */
}

.webcom-wrapper h2 {
    margin: 0;
    padding: 10px;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    font-size: 16px;
    display: none;
}

.webcom-wrapper.active h2 {
    display: block;
}

.webcom-content {
    height: 100%;
    min-height: 0;
}

mailink-chat {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.header {
    text-align: center;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

.controls {
    margin-bottom: 15px;
    text-align: center;
}

.form-group {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
}

label {
    flex: 0 0 100px;
    margin-bottom: 0px;
    font-weight: bold;
    font-size: 13px;
    color: #555;
    text-align: left;
}

input,
textarea,
select {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 13px;
    box-sizing: border-box;
}

.checkbox-group {
    justify-content: flex-start;
    padding-left: 100px;
}

.checkbox-group input {
    flex: none;
    width: auto !important;
    margin-right: 8px;
}

.checkbox-group label {
    flex: none;
    width: auto;
}

#avatar-preview {
    margin: 5px 0 !important;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

textarea {
    height: 100px;
    resize: vertical;
}

.config-section.highlight {
    border: 2px solid #ff4d4f;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 77, 79, 0);
    }
}

/* ============================================
   后端 /rpc 就绪门遮罩（等就绪 → loading / 致命错误页）
   ============================================ */
.backend-ready-overlay {
    position: fixed;
    top: 32px; /* 标题栏之下 */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10200;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
}

.backend-ready-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px;
    max-width: 360px;
    text-align: center;
}

.backend-ready-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.backend-ready-spinner {
    width: 36px;
    height: 36px;
    border: 4px solid rgba(102, 126, 234, 0.25);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: backend-spin 0.9s linear infinite;
}

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

.backend-ready-text {
    font-size: 14px;
    color: #555;
    margin: 0;
    word-break: break-word;
}

.backend-fatal-icon {
    font-size: 40px;
    line-height: 1;
}
