/* AI Assistant Styles - Extends Enhanced GPS Studio Design System */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;850&display=swap');

:root {
  /* BCC red brand colors */
  --brand-h: 354; --brand-s: 86%; --brand-l: 54%;          /* BCC red */
  --brand: hsl(var(--brand-h) var(--brand-s) var(--brand-l));
  --brand-600: hsl(var(--brand-h) var(--brand-s) calc(var(--brand-l) - 8%));
  --brand-700: hsl(var(--brand-h) var(--brand-s) calc(var(--brand-l) - 14%));

  /* dark neutrals */
  --bg:    hsl(222 18% 8%);     /* page */
  --surface:hsl(222 18% 12%);    /* cards/sections */
  --text:  hsl(0 0% 98%);
  --muted: hsl(220 10% 66%);
  --line:  hsl(220 12% 20%);

  --radius: 12px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35);
  --shadow-2: 0 10px 40px rgba(0,0,0,.45);
}

/* Light theme variant */
[data-theme="light"] {
  --bg: hsl(0 0% 100%);
  --surface: hsl(0 0% 100%);
  --text: hsl(222 24% 12%);
  --muted: hsl(222 10% 40%);
  --line: hsl(220 10% 88%);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    /* Procedural dots background */
    background:
        radial-gradient(hsl(0 0% 100% / .06) 1px, transparent 1px) 0 0 / 22px 22px,
        radial-gradient(hsl(0 0% 100% / .03) 1px, transparent 1px) 11px 11px / 22px 22px,
        var(--bg);
}

#app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 0; /* Remove padding to fix layout */
}

/* Header */
#app-header {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(1200px 600px at 80% -10%, hsl(var(--brand-h) var(--brand-s) / .18), transparent 60%),
        var(--surface);
    color: var(--text);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-2);
    z-index: 1000;
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
}

#app-header h1 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 850;
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
    line-height: .95;
    letter-spacing: -.01em;
    margin: 0;
}

#header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Mode Toggle Styles */
.mode-toggle {
    display: flex;
    background-color: hsl(220 12% 20%);
    border-radius: 20px;
    padding: 3px;
    position: relative;
    overflow: hidden;
}

.mode-toggle input[type="radio"] {
    display: none;
}

.mode-toggle label {
    padding: 6px 16px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    border-radius: 20px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    margin: 0;
    width: auto;
    color: var(--muted);
}

.mode-toggle input[type="radio"]:checked + label {
    color: white;
    background-color: var(--brand);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Settings Menu */
.settings-menu {
    position: relative;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    z-index: 1001;
    min-width: 120px;
    margin-top: 0.5rem;
}

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

.dropdown-content a:hover {
    background: hsl(222 18% 16%);
}

.settings-menu.active .dropdown-content {
    display: block;
}

/* Main Content */
#main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0; /* Allow flex items to shrink */
}

/* Left Panel - Threads */
#threads-panel {
    width: 400px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-1);
}

/* Form Sections */
.form-section {
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-1);
    position: relative;
}

.form-section.collapsed .section-content {
    display: none;
}

.section-header {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(800px 400px at 50% -20%, hsl(var(--brand-h) var(--brand-s) / .08), transparent 50%),
        hsl(222 18% 14%);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
    transition: all 0.2s ease;
}

.section-header:hover {
    background:
        radial-gradient(800px 400px at 50% -20%, hsl(var(--brand-h) var(--brand-s) / .12), transparent 50%),
        hsl(222 18% 16%);
}

.section-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.collapse-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--muted);
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.collapse-btn:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
}

.section-content {
    padding: 1rem;
}

/* Form Groups */
.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 0.875rem;
    background: hsl(222 18% 10%);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px hsl(var(--brand-h) var(--brand-s) / .1);
}

.form-group small {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--line);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--brand);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--brand-600);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--brand);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Search Input */
.search-input {
    padding: 6px 10px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.9em;
    background-color: hsl(222 18% 10%);
    color: var(--text);
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.search-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px hsl(var(--brand-h) var(--brand-s) / .2);
    outline: none;
}

/* Buttons */
.btn {
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.1rem;
    border-radius: 999px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid hsl(0 0% 100% / .08);
    background: hsl(222 18% 14%);
    color: var(--text);
    box-shadow: var(--shadow-1);
    transition: transform .15s ease, box-shadow .2s ease, background .2s ease;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-primary {
    background: transparent;
    color: var(--text);
    border: 1px solid hsl(0 0% 100% / .3);
}

.btn-primary:hover {
    background: hsl(0 0% 100% / .1);
    border-color: hsl(0 0% 100% / .5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid hsl(0 0% 100% / .3);
}

.btn-outline:hover {
    background: hsl(0 0% 100% / .1);
    border-color: hsl(0 0% 100% / .5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Thread List */
#threads-list {
    max-height: 300px;
    overflow-y: auto;
}

.thread-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.thread-item:hover {
    background: hsl(222 18% 16%);
}

.thread-item.active {
    background: hsl(var(--brand-h) var(--brand-s) / .15);
    border-left: 4px solid var(--brand);
    padding-left: calc(0.75rem - 4px);
}

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

.thread-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.thread-preview {
    font-size: 0.75rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.thread-item:hover .thread-actions {
    opacity: 1;
}

.thread-action-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.thread-action-btn:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
}

/* Usage Stats */
.stats-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.875rem;
}

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

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

/* Chat Panel */
#chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    min-height: 0; /* Allow flex items to shrink */
    height: calc(100vh - 200px); /* Explicit height calculation */
}

#chat-header {
    padding: 1rem 1.5rem;
    background: hsl(222 18% 14%);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-info h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.chat-info span {
    font-size: 0.875rem;
    color: var(--muted);
}

.chat-controls {
    display: flex;
    gap: 0.5rem;
}

/* Chat Messages */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0; /* Allows shrinking below content size */
    max-height: calc(100vh - 280px); /* Explicit max height */
    scroll-behavior: smooth; /* Smooth scrolling */
}

.welcome-message {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
    background: hsl(222 18% 14%);
    border-radius: var(--radius);
    border: 1px solid var(--line);
}

.welcome-content h4 {
    color: var(--brand);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.welcome-content ul {
    text-align: left;
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.welcome-content li {
    margin-bottom: 0.5rem;
    color: var(--muted);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--brand);
    color: white;
}

.message.assistant .message-avatar {
    background: hsl(222 18% 20%);
    color: var(--text);
}

.message-content {
    background: hsl(222 18% 14%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
}
.message-content ol,
.message-content ul {
    padding-left: 0;
    margin-left: 1.2em;
}

.message.user .message-content {
    background: var(--brand);
    color: white;
    border-color: var(--brand-600);
}

.message-content p {
    margin-bottom: 0.5rem;
}

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

.message-content pre {
    background: hsl(222 18% 8%);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.75rem;
    margin: 0.5rem 0;
    overflow-x: auto;
    font-size: 0.875rem;
}

.message-content code {
    background: hsl(222 18% 8%);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-size: 0.875rem;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message.user .message-content pre,
.message.user .message-content code {
    background: rgba(255, 255, 255, 0.1);
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.5rem;
    text-align: right;
}

.message.user .message-timestamp {
    text-align: left;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    align-self: flex-start;
}

.typing-indicator .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: hsl(222 18% 20%);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
}

.typing-content {
    background: hsl(222 18% 14%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingPulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Streaming Message Styles */
.message.streaming {
    animation: streamingGlow 2s ease-in-out infinite alternate;
}

@keyframes streamingGlow {
    from {
        box-shadow: 0 0 5px hsl(var(--brand-h) var(--brand-s) / .2);
    }
    to {
        box-shadow: 0 0 15px hsl(var(--brand-h) var(--brand-s) / .4);
    }
}

.streaming-text {
    position: relative;
    min-height: 1.2em;
}

.streaming-cursor {
    display: inline-block;
    background: var(--brand);
    color: var(--brand);
    animation: cursorBlink 1s infinite;
    margin-left: 2px;
    font-weight: normal;
}

@keyframes cursorBlink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Streaming message content animation */
.message.streaming .message-content {
    border-color: hsl(var(--brand-h) var(--brand-s) / .3);
    background: hsl(222 18% 14%);
}

/* Input Container */
#input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    max-height: 200px; /* Prevent input area from taking too much space */
}

#input-area {
    padding: 1rem;
    max-width: 100%;
}

#file-upload-area {
    margin-bottom: 0.5rem;
}

.uploaded-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.uploaded-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: hsl(222 18% 14%);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.875rem;
}

.file-remove-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.125rem;
    border-radius: 3px;
    transition: all 0.2s;
}

.file-remove-btn:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
}

#message-input-container {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: hsl(222 18% 14%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.5rem;
}

.input-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-btn:hover:not(:disabled) {
    background: hsl(220 12% 25%);
    color: var(--text);
}

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

#send-btn:not(:disabled) {
    color: var(--brand);
}

#send-btn:hover:not(:disabled) {
    background: hsl(var(--brand-h) var(--brand-s) / .1);
    color: var(--brand-600);
}

#message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.4;
    resize: none;
    min-height: 20px;
    max-height: 120px;
    padding: 0.5rem;
    font-family: inherit;
}

#message-input:focus {
    outline: none;
}

#message-input::placeholder {
    color: var(--muted);
}

#input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.input-hint {
    font-size: 0.75rem;
    color: var(--muted);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(34, 40, 49, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--line);
    border-top: 4px solid var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Custom Scrollbars */
#threads-panel::-webkit-scrollbar,
#chat-messages::-webkit-scrollbar,
#threads-list::-webkit-scrollbar {
    width: 6px;
}

#threads-panel::-webkit-scrollbar-track,
#chat-messages::-webkit-scrollbar-track,
#threads-list::-webkit-scrollbar-track {
    background: var(--surface);
}

#threads-panel::-webkit-scrollbar-thumb,
#chat-messages::-webkit-scrollbar-thumb,
#threads-list::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

#threads-panel::-webkit-scrollbar-thumb:hover,
#chat-messages::-webkit-scrollbar-thumb:hover,
#threads-list::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Responsive Design */
@media (max-width: 1024px) {
    #main-content {
        flex-direction: column;
    }
    
    #threads-panel {
        width: 100%;
        max-height: 40vh;
        order: 2;
    }
    
    #chat-panel {
        min-height: 60vh;
        height: calc(100vh - 300px);
        order: 1;
    }
    
    #chat-messages {
        max-height: calc(60vh - 120px);
    }
    
    #input-container {
        order: 3;
    }
}

@media (max-width: 768px) {
    #app-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    #app-header h1 {
        font-size: 1.25rem;
    }
    
    #header-controls {
        gap: 0.5rem;
    }
    
    .mode-toggle label {
        padding: 4px 12px;
        font-size: 0.8rem;
    }
    
    #threads-panel {
        max-height: 50vh;
    }
    
    #chat-panel {
        height: calc(100vh - 320px);
    }
    
    #chat-messages {
        max-height: calc(50vh - 100px);
    }
    
    #chat-header {
        padding: 0.75rem 1rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    #input-area {
        padding: 0.75rem;
    }
}

/* Focus states for accessibility */
.collapse-btn:focus,
.btn:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* Animation for smooth transitions */
.section-content {
    transition: all 0.3s ease;
}

.form-section {
    transition: all 0.2s ease;
}

/* User Input Modal Styles */
.user-input-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(34, 40, 49, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(4px);
    animation: modalFadeIn 0.3s ease-out;
}

.user-input-modal.hidden {
    display: none;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(4px);
    }
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    line-height: 1.3;
}

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.modal-close:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
}

.modal-description {
    color: var(--muted);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-form-group {
    margin-bottom: 1.5rem;
}

.modal-form-group:last-child {
    margin-bottom: 0;
}

.modal-form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.modal-form-group input,
.modal-form-group select,
.modal-form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 0.9rem;
    background: hsl(222 18% 10%);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

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

.modal-form-group input:focus,
.modal-form-group select:focus,
.modal-form-group textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px hsl(var(--brand-h) var(--brand-s) / .1);
}

.modal-form-group small {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.modal-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.5rem;
}

.modal-checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-checkbox-item input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.modal-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.modal-radio-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-radio-item input[type="radio"] {
    width: auto;
    margin: 0;
}

.modal-footer {
    padding: 1rem 1.5rem 1.5rem 1.5rem;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.modal-btn-primary {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}

.modal-btn-primary:hover:not(:disabled) {
    background: var(--brand-600);
    border-color: var(--brand-600);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--brand-h) var(--brand-s) / .3);
}

.modal-btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--line);
}

.modal-btn-secondary:hover:not(:disabled) {
    background: hsl(222 18% 16%);
    border-color: var(--muted);
}

.modal-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.modal-validation-error {
    color: hsl(0 70% 60%);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    display: none;
}

.modal-validation-error.show {
    display: block;
}

.modal-form-group.error input,
.modal-form-group.error select,
.modal-form-group.error textarea {
    border-color: hsl(0 70% 60%);
    box-shadow: 0 0 0 3px hsl(0 70% 60% / .1);
}

/* Command execution indicator for user input */
.command-waiting-input {
    background: hsl(45 100% 50% / .1) !important;
    border-left: 3px solid hsl(45 100% 50%) !important;
}

.command-waiting-input .command-indicator {
    background: hsl(45 100% 50% / .1) !important;
    border-left: 3px solid hsl(45 100% 50%) !important;
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 1rem;
    }
    
    .modal-header {
        padding: 1rem 1rem 0.75rem 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem 1rem 1rem;
        flex-direction: column;
    }
    
    .modal-btn {
        width: 100%;
        justify-content: center;
    }
    
    .modal-checkbox-group,
    .modal-radio-group {
        gap: 0.5rem;
    }
}

/* Audio Player Modal Styles */
.audio-player-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(34, 40, 49, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3500;
    backdrop-filter: blur(4px);
    animation: modalFadeIn 0.3s ease-out;
}

.audio-player-modal.hidden {
    display: none;
}

.audio-modal-content {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
}

.audio-modal-header {
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.audio-modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    line-height: 1.3;
}

.audio-modal-body {
    padding: 1.5rem;
}

.audio-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}

.audio-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--line);
    border-top: 4px solid var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.audio-loading p {
    color: var(--muted);
    margin: 0;
}

.audio-player-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.audio-player-container.hidden {
    display: none;
}

#audio-player {
    width: 100%;
    background: hsl(222 18% 10%);
    border-radius: 8px;
    outline: none;
}

#audio-player::-webkit-media-controls-panel {
    background-color: hsl(222 18% 10%);
}

.audio-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: hsl(222 18% 14%);
    border-radius: 8px;
    border: 1px solid var(--line);
}

.audio-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.audio-info span {
    font-size: 0.875rem;
    color: var(--muted);
}

.audio-actions {
    display: flex;
    gap: 0.5rem;
}

.audio-action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.audio-action-btn:hover {
    background: var(--brand-600);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--brand-h) var(--brand-s) / .3);
}

.audio-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    gap: 1rem;
}

.audio-error.hidden {
    display: none;
}

.audio-error p {
    color: hsl(0 70% 60%);
    margin: 0;
}

/* Speaker Button Styles */
.message-speaker-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    transform: translateY(-2px);
}

.message.assistant .message-content {
    position: relative;
}

.message.assistant:hover .message-speaker-btn {
    opacity: 1;
    transform: translateY(0);
}

.message-speaker-btn:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
    transform: scale(1.1);
}

.message-speaker-btn:active {
    transform: scale(0.95);
}

.message-speaker-btn svg {
    width: 16px;
    height: 16px;
}

/* Speaker button loading state */
.message-speaker-btn.loading {
    opacity: 1;
    color: var(--brand);
    animation: speakerPulse 1.5s ease-in-out infinite;
}

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

/* Voice settings textarea styling */
#voice-instructions {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 0.875rem;
    background: hsl(222 18% 10%);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
}

#voice-instructions:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px hsl(var(--brand-h) var(--brand-s) / .1);
}

#voice-instructions::placeholder {
    color: var(--muted);
}

/* Responsive audio modal */
@media (max-width: 768px) {
    .audio-modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 1rem;
    }
    
    .audio-modal-header {
        padding: 1rem 1rem 0.75rem 1rem;
    }
    
    .audio-modal-body {
        padding: 1rem;
    }
    
    .audio-controls {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .audio-info {
        text-align: center;
    }
    
    .audio-actions {
        justify-content: center;
    }
    
    .audio-action-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Audio Player Section Styles */
#audio-player-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.audio-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: hsl(222 18% 10%);
    border-radius: 8px;
    border: 1px solid var(--line);
    min-height: 60px;
}

.audio-status-idle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.audio-status-idle svg {
    opacity: 0.6;
}

.audio-loading-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--brand);
    font-size: 0.875rem;
}

.audio-loading-status.hidden {
    display: none;
}

.audio-spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid var(--line);
    border-top: 2px solid var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.audio-now-playing {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.audio-now-playing.hidden {
    display: none;
}

.now-playing-info {
    flex: 1;
    min-width: 0;
}

.now-playing-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-playing-details {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.audio-player-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.audio-player-controls.hidden {
    display: none;
}

#main-audio-player {
    width: 100%;
    background: hsl(222 18% 8%);
    border-radius: 6px;
    outline: none;
    border: 1px solid var(--line);
}

#main-audio-player::-webkit-media-controls-panel {
    background-color: hsl(222 18% 8%);
}

.audio-control-buttons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.audio-control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: hsl(222 18% 16%);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 40px;
    height: 40px;
}

.audio-control-btn:hover {
    background: hsl(222 18% 20%);
    border-color: var(--brand);
    color: var(--brand);
    transform: translateY(-1px);
}

.audio-control-btn:active {
    transform: translateY(0);
}

.audio-error-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: hsl(0 60% 5%);
    border: 1px solid hsl(0 60% 20%);
    border-radius: 8px;
    text-align: center;
}

.audio-error-display.hidden {
    display: none;
}

.audio-error-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: hsl(0 70% 60%);
    font-size: 0.875rem;
}

.audio-retry-btn {
    padding: 0.5rem 1rem;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.audio-retry-btn:hover {
    background: var(--brand-600);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--brand-h) var(--brand-s) / .3);
}

/* Now Playing Indicator for Chat Messages */
.message.now-playing {
    position: relative;
}

.message.now-playing::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--brand);
    border-radius: 2px;
    animation: nowPlayingPulse 2s ease-in-out infinite;
}

@keyframes nowPlayingPulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

.message.now-playing .message-content {
    border-left-color: var(--brand);
    background: hsl(var(--brand-h) var(--brand-s) / .05);
}

/* Updated Speaker Button Styles */
.message-speaker-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    transform: translateY(-2px);
}

.message.assistant .message-content {
    position: relative;
}

.message.assistant:hover .message-speaker-btn {
    opacity: 1;
    transform: translateY(0);
}

.message-speaker-btn:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
    transform: scale(1.1);
}

.message-speaker-btn:active {
    transform: scale(0.95);
}

.message-speaker-btn svg {
    width: 16px;
    height: 16px;
}

/* Speaker button loading state */
.message-speaker-btn.loading {
    opacity: 1;
    color: var(--brand);
    animation: speakerPulse 1.5s ease-in-out infinite;
}

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

/* Responsive audio player */
@media (max-width: 768px) {
    .audio-status {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        min-height: auto;
    }
    
    .now-playing-details {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .audio-control-buttons {
        gap: 0.25rem;
    }
    
    .audio-control-btn {
        min-width: 36px;
        height: 36px;
        padding: 0.375rem;
    }
}

/* Print styles */
@media print {
    #app-header,
    #threads-panel,
    #input-container,
    .user-input-modal {
        display: none;
    }
    
    #chat-panel {
        width: 100%;
        height: 100vh;
    }
    
    .message-speaker-btn {
        display: none;
    }
}

/* Company API Status Styling */
.company-api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 6px;
    color: #28a745;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-indicator {
    font-size: 1.1em;
    line-height: 1;
}

/* Drag Handle Styles */
.drag-handle {
    background: none;
    border: none;
    color: var(--muted);
    cursor: grab;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    flex-shrink: 0;
}

.drag-handle:hover {
    background: hsl(220 12% 25%);
    color: var(--text);
    opacity: 1;
    transform: scale(1.1);
}

.drag-handle:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.section-header:hover .drag-handle {
    opacity: 1;
}

/* Drag and Drop States */
.form-section.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
    z-index: 1000;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.form-section.drag-over {
    border-color: var(--brand);
    background: hsl(var(--brand-h) var(--brand-s) / .05);
    transform: translateY(-2px);
}

.form-section.drag-over::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--brand);
    border-radius: 2px;
    z-index: 10;
}

.form-section.drag-over-bottom::before {
    top: auto;
    bottom: -2px;
}

/* Drag placeholder */
.drag-placeholder {
    height: 4px;
    background: var(--brand);
    border-radius: 2px;
    margin: 0.5rem 0;
    opacity: 0.8;
    animation: dragPlaceholderPulse 1.5s ease-in-out infinite;
}

@keyframes dragPlaceholderPulse {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 0.8;
    }
}

/* Prevent text selection during drag */
.form-section[draggable="true"] {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth transitions for reordering */
.form-section {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

/* Disable pointer events on section content during drag */
.form-section.dragging .section-content,
.form-section.dragging .section-header h3,
.form-section.dragging .collapse-btn {
    pointer-events: none;
}

/* Focus states for drag handles */
.drag-handle:focus {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    opacity: 1;
}

/* Accessibility improvements */
.drag-handle[aria-pressed="true"] {
    background: hsl(220 12% 25%);
    color: var(--text);
    opacity: 1;
}

/* Mobile drag handle adjustments */
@media (max-width: 768px) {
    .drag-handle {
        padding: 0.375rem;
        opacity: 1; /* Always visible on mobile */
    }
    
    .drag-handle svg {
        width: 14px;
        height: 14px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .drag-handle {
        border: 1px solid var(--line);
    }
    
    .drag-handle:hover,
    .drag-handle:focus {
        border-color: var(--brand);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .form-section {
        transition: none;
    }
    
    .drag-placeholder {
        animation: none;
    }
    
    .form-section.dragging {
        transform: none;
    }
}
