/* Reusable UI Components */

/* Profile Dropdown Menu */
.profile-menu {
    position: relative;
    display: inline-block;
}

.profile-toggle {
    cursor: pointer;
    padding: 0.5rem 1rem;
    font-size: 1.2rem;
}

.profile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.profile-menu:hover .profile-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.dropdown-item:hover {
    background-color: var(--bg-secondary);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.25rem 0;
}

/* Buttons */
/* Add .btn-close-view to the exclusion list */
button:not(.code-block-copy-btn):not(.toggle-fold-btn):not(.btn):not(.clear-search-btn):not(.btn-close-view):not(.cassette-btn):not(.mac-close-btn) {
    width: 100%;
    padding: 14px;
    background: var(--btn-primary-bg); /* was: #4e80fe */
    color: var(--btn-primary-text); /* was: white */
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

/* Hover */
button:not(.code-block-copy-btn):not(.toggle-fold-btn):not(.btn):not(.clear-search-btn):not(.btn-close-view):not(.cassette-btn):not(.mac-close-btn):hover {
    background: var(--btn-primary-hover); /* was: #3182ce */
}

/* Disabled */
button:not(.code-block-copy-btn):not(.toggle-fold-btn):not(.btn):not(.clear-search-btn):not(.btn-close-view):not(.cassette-btn):not(.mac-close-btn):disabled {
    background: var(--btn-disabled-bg); /* was: #a0aec0 */
    cursor: not-allowed;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    width: auto;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--btn-primary-bg); /* was: #4e80fe */
    color: var(--btn-primary-text); /* was: white */
}

.btn-primary:hover {
    background: var(--btn-primary-hover); /* was: #3182ce */
}

.btn-secondary {
    background: var(--btn-secondary-bg); /* was: #e2e8f0 */
    color: var(--btn-secondary-text); /* was: #4a5568 */
}

.btn-secondary:hover {
    background: var(--btn-secondary-hover); /* was: #cbd5e0 */
}

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

.btn-danger:hover {
    background: color-mix(in srgb, var(--text-danger) 85%, black);
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 20px;
}

.flash {
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 6px;
}

.error {
    background: var(--bg-flash-error); /* was: #fff5f5 */
    color: var(--text-error); /* was: #c53030 */
    border-left: 4px solid var(--border-error); /* was: #c53030 */
}

.info {
    background: var(--bg-flash-info); /* was: #ebf8ff */
    color: var(--text-info); /* was: #2b6cb0 */
    border-left: 4px solid var(--border-info); /* was: #2b6cb0 */
}

.success {
    background: var(--bg-flash-success); /* was: #f0fff4 */
    color: var(--text-success); /* was: #2f855a */
    border-left: 4px solid var(--border-success); /* was: #2f855a */
}

/* Loading states */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin: 20px 0;
    padding: 40px;
    color: var(--text-muted); /* was: #718096 */
    font-size: 16px;
}

/* Messages */
.message {
    background: var(--bg-message); /* was: white */
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: var(--shadow-light); /* was: 0 1px 3px rgba(0, 0, 0, 0.1) */
    border-left: 4px solid var(--border-light); /* was: #e2e8f0 */
}

.message.user {
    border-left-color: var(--message-border-user); /* was: #ffffff */
}

.message.assistant {
    border-left-color: var(--message-border-assistant); /* was: #4e80fe */
}

.message.system {
    border-left-color: var(--message-border-system); /* was: #ed8936 */
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light); /* was: #e2e8f0 */
    gap: 10px;
}

.message-content {
    /* Ensure long text wraps and doesn't overflow */
    overflow-wrap: break-word;
    word-wrap: break-word; /* Fallback for older browsers */
    word-break: break-word;
}

.message-content p {
    margin: 0 0 10px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Thinking Process Styles */
.thinking-content {
    background-color: var(--bg-thinking); /* was: #f7f8fa */
    border: 1px solid var(--border-thinking); /* was: #e1e5e9 */
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
    color: var(--text-thinking); /* was: #5a6c7d */
    font-size: 14px;
    line-height: 1.5;
}

.thinking-content:empty {
    display: none;
}

.thinking-header {
    display: none !important;
}

.thinking-text {
    white-space: pre-wrap; /* Preserve whitespace and newlines */
    word-wrap: break-word; /* Ensure long lines wrap */
}

/* Inline code (non-syntax highlighted) */
.message-content code:not(.highlight code) {
    font-family: 'Hack', monospace;
    background-color: var(--bg-inline-code); /* was: #eef2f7 */
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--text-inline-code); /* was: #2d3748 */
}

/* Code block components */
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-code-header); /* was: #334155 */
    padding: 8px 12px;
    color: #cbd5e0; /* Keep this as is - it's specific to code headers */
}

.code-block-lang {
    font-family: 'Hack', monospace;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
}

.code-block-copy-btn {
    width: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: transparent;
    border: 1px solid transparent;
    color: #cbd5e0; /* Keep this as is - it's specific to code headers */
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s, color 0.2s, transform 0.1s ease;
    transform-origin: center;
}

.code-block-copy-btn.clicked {
    animation: button-pop 0.2s ease-out;
}

.code-block-copy-btn:hover {
    background-color: #475569; /* Keep this as is - it's specific to code headers */
    color: #ffffff;
}

.code-block-copy-btn .fas {
    font-size: 14px;
}

/* Toggle components */
.toggle-fold-btn {
    background: none;
    border: 1px solid var(--border-light); /* was: #e2e8f0 */
    color: var(--text-secondary); /* was: #4a5568 */
    cursor: pointer;
    padding: 2px 8px;
    width: auto;
    font-size: 12px;
    border-radius: 4px;
    transition: background 0.2s;
    margin-left: auto;
    flex-shrink: 0;
}

.toggle-fold-btn:hover {
    background: var(--bg-hover); /* was: #edf2f7 */
}

/* Assistant toggle UI - Keep complex component colors as-is for now */
.assistant-toggle-container {
    position: relative;
    display: inline-flex;
    gap: 2%;
    padding: 2%;
    border-radius: 25px;
    cursor: pointer;
    user-select: none;
    margin-left: auto;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.assistant-toggle-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 50px;
    height: 40px;
    font-size: 10px;
    font-weight: 600;
    color: #333;
    border-radius: 20px;
    filter: blur(2px);
    transition: all 0.25s ease;
    z-index: 1;
    background: rgba(255, 255, 255, 0.6);
    padding: 2px;
    text-align: center;
}

.assistant-toggle-item.unblurred {
    filter: blur(0);
}

.assistant-toggle-glass {
    position: absolute;
    top: 50%;
    left: 2%;
    border-radius: 20px;
    border: 2px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
    /* Magnifying glass effect - scale up the content underneath */
    transform-origin: center;
}

.assistant-toggle-glass::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 22%;
    width: 25%;
    height: 12%;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    transform: rotate(-35deg);
}

/* Magnifying effect - content under the glass appears larger */
.assistant-toggle-glass::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: inherit;
    /* This creates the magnification backdrop */
    backdrop-filter: blur(0px) contrast(1.1) brightness(1.05);
}

.assistant-toggle-icon {
    font-size: 16px;
    margin-bottom: 3px;
    transition: transform 0.25s ease;
}

/* When an item is under the glass (unblurred), scale up its content */
.assistant-toggle-item.unblurred .assistant-toggle-icon {
    transform: scale(1.15);
}

.assistant-toggle-item.unblurred {
    font-size: 11px; /* Slightly larger text when under glass */
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--background-color);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 400px;
    position: relative;
}

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

.modal-header h2 {
    margin: 0;
}

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

.modal-body #modalResult {
    margin-top: 1rem;
}

/* --- START: New Three-Layer Toggle Button Styles --- */
#layer-toggle-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2100; /* Was 1500. Increased to be higher than Layer 3 (2000) */
    
    display: flex;
    flex-direction: column;
    gap: 4px;
    
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

#layer-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.layer-square {
    width: 20px;
    height: 20px;
    background-color: var(--text-navbar);
    border-radius: 4px;
    opacity: 0.5;
    transition: all 0.3s ease;
}

/* --- START: MODIFIED - Active states for each layer (Reversed) --- */
/* Layer 3 lights up the TOP square */
#layer-toggle-btn.layer-3 .layer-square:nth-child(1),
/* Layer 2 lights up the MIDDLE square */
#layer-toggle-btn.layer-2 .layer-square:nth-child(2),
/* Layer 1 lights up the BOTTOM square */
#layer-toggle-btn.layer-1 .layer-square:nth-child(3) {
    opacity: 1;
    transform: scale(1.1);
}
/* --- END: MODIFIED --- */
/* --- END: New Three-Layer Toggle Button Styles --- */

/* NEW: Cassette-style filter tabs */
.cassette-tabs {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 4px 0 8px;
}

.cassette-btn {
    width: auto;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    background: linear-gradient(180deg, var(--bg-container), var(--bg-light));
    color: var(--text-secondary);
    box-shadow:
      0 2px 0 rgba(0,0,0,0.15),           /* outer drop shadow */
      inset 0 0 0 0 rgba(0,0,0,0.0);      /* will change when active */
    transition: transform .05s ease, box-shadow .15s ease, background .15s ease;
    font-weight: 600;
}

.cassette-btn:hover {
    background: linear-gradient(180deg, var(--bg-light), var(--bg-container));
}

.cassette-btn.is-active {
    transform: translateY(2px); /* pressed down */
    box-shadow:
      0 0 0 rgba(0,0,0,0),                /* remove outer */
      inset 0 2px 6px rgba(0,0,0,0.25);   /* inner pressed shadow */
    background: linear-gradient(180deg, var(--bg-light), var(--bg-container));
    color: var(--text-primary);
}

/* NEW: Source badges */
.chat-source-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    margin-right: 8px;
    line-height: 1;
    vertical-align: middle;
    transform: translateY(-1px);
    border: 1px solid var(--border-light);
}

.chat-source-badge.is-sync {
    background: var(--bg-light);
    color: var(--text-secondary);
}

.chat-source-badge.is-api {
    background: color-mix(in oklab, var(--btn-primary-bg) 15%, transparent);
    color: var(--btn-primary-bg);
    border-color: color-mix(in oklab, var(--btn-primary-bg) 35%, var(--border-light));
}