:root {
    --bg-gradient: linear-gradient(135deg, #1a0533 0%, #4d327d 100%);
    --panel-bg: rgba(45, 18, 75, 0.9);
    --chat-bg: rgba(255, 255, 255, 0.08); /* Not directly used for chat-box background now, but define */
    --text-color: #e0e0e0;
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --button-bg: #a78bfa; /* Medium purple */
    --button-text: #312e81; /* Dark purple-blue */
    --button-hover-bg: #c4b5fd; /* Lighter purple */
    --border-radius-small: 8px;
    --border-radius-medium: 12px;
    --border-radius-large: 16px;
    --shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    --scroll-thumb: #a78bfa;
    --scroll-track: rgba(255, 255, 255, 0.05);
    --nav-bg: rgba(30, 10, 50, 0.95);
    --system-color-error: #ef4444; /* Red-400 */
    --system-color-success: #84cc16; /* Lime-500 */
    --system-color-info: #3b82f6; /* Blue-500 */
    --header-bg: rgba(255, 255, 255, 0.05); /* Not directly used for chat-header background now */
    --modal-bg: rgba(0, 0, 0, 0.7);
    --modal-content-bg: #3a1c69; /* Darker purple for modal */
    --cancel-button-bg: #6b7280; /* Gray-500 */
    --cancel-button-hover-bg: #4b5563; /* Gray-600 */
    --gemini-strong-color: #c4b5fd; /* Lighter purple for gemini strong */
    --user-strong-color: #d8b4fe; /* Even lighter purple for user strong */
    --code-bg: rgba(255, 255, 255, 0.1); /* White with opacity */
    --code-text: #bae6fd; /* Light blue */

    /* Code block specific variables */
    --code-block-bg: rgba(0, 0, 0, 0.3);
    --code-block-header-bg: rgba(0, 0, 0, 0.4);
    --code-file-name-color: #a78bfa;
    --code-action-btn-bg: rgba(255, 255, 255, 0.1);
    --code-action-btn-hover-bg: rgba(255, 255, 255, 0.2);
    --code-action-btn-text: #e0e0e0;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden; /* Prevent scrolling on html/body */
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 100%; /* Use full width/height on mobile */
    max-height: 100%;
    background: var(--panel-bg);
    border-radius: 0; /* No radius on full screen */
    box-shadow: none;
    overflow: hidden; /* Contain children */
}

.tab-nav {
    display: flex;
    justify-content: center;
    background: var(--nav-bg);
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* Prevent shrinking */
    z-index: 2;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Optional subtle shadow */
}

.tab-button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    padding: 10px 20px;
    margin: 0 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: color 0.3s ease, border-bottom-color 0.3s ease;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    white-space: nowrap; /* Prevent wrapping on buttons */
}

.tab-button i {
     margin-right: 5px;
}
.tab-button:last-child i {
     margin-right: 0;
     margin-left: 5px;
}


.tab-button.active {
    color: var(--button-bg);
    border-bottom-color: var(--button-bg);
}

.tab-button:hover:not(.active) {
    color: rgba(255, 255, 255, 0.8);
}


.tab-content-area {
    flex-grow: 1; /* Takes available vertical space */
    overflow: hidden; /* Crucial for scrollable content inside */
    padding: 20px; /* Outer padding around the active tab content */
    display: flex; /* Use flex to center content */
    position: relative;
}

.tab-content {
    display: none; /* Hidden by default */
    width: 100%;
    height: 100%;
    flex-direction: column;
    background: none; /* Background is on app-container */
    border-radius: 0;
    padding: 0; /* Padding is on tab-content-area */
    /* REMOVED: overflow-y: auto; and scrollbar styles from here */
    box-sizing: border-box; /* Include padding in width/height */
}

.tab-content.active {
    display: flex; /* Show active tab content */
    /* flex direction column handled here */
}

/* Ensure chat view still hides overflow, chat-box scrolls */
#chatView.tab-content.active {
    overflow-y: hidden;
}


/* Panels within tab content, centered and now scrollable themselves */
.models-view-panel,
.settings-panel {
    width: 100%;
    max-width: 800px; /* Limit width on larger screens */
    margin: 0 auto; /* Center horizontally */
    /* ADDED: Inner padding for content */
    padding: 0 20px 20px 20px; /* Top padding handled by margin/padding of h2 */
    /* ADDED: Scrollable properties */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    flex-grow: 1; /* Allow panels to take available height */
    box-sizing: border-box; /* Include padding in element size */
}

.models-view-panel::-webkit-scrollbar,
.settings-panel::-webkit-scrollbar { width: 8px; }
.models-view-panel::-webkit-scrollbar-track,
.settings-panel::-webkit-scrollbar-track { background: var(--scroll-track); border-radius: 10px; }
.models-view-panel::-webkit-scrollbar-thumb,
.settings-panel::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid rgba(45, 18, 75, 0.5); }


.models-view-panel h2,
.settings-panel h2 {
    color: var(--button-bg);
    margin-top: 0; /* Adjusted margin top */
    padding-top: 20px; /* Added padding top for space above h2 */
    margin-bottom: 20px;
    text-align: center;
    text-shadow: 0 0 5px rgba(167, 139, 250, 0.2);
}

.setting-group {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}
.setting-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.setting-group h3 {
    color: var(--button-bg);
    margin-top: 0;
    margin-bottom: 10px;
}
.setting-group p {
    font-size: 0.95em;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 0;
    margin-bottom: 15px;
}
.setting-group p:last-child {
     margin-bottom: 0;
}
.setting-group label {
     display: block;
     margin-bottom: 5px;
     color: rgba(255, 255, 255, 0.8);
     font-size: 0.95em;
}


.warning-note {
    font-size: 0.9em;
    color: #fca5a5; /* Light red */
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(252, 165, 165, 0.08); /* Light red with opacity */
    border-radius: var(--border-radius-small);
    border: 1px solid rgba(252, 165, 165, 0.15); /* Light red border */
}


input[type="text"],
input[type="number"],
textarea {
    display: block; /* Each on a new line */
    width: calc(100% - 20px); /* Account for padding */
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-small);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1em;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    outline: none;
    box-sizing: border-box; /* Include padding and border in element's total width and height */
}
/* Adjust bottom margin for specific cases in settings form */
.setting-group input:last-of-type:not([type="number"]),
.setting-group textarea:last-of-type {
    margin-bottom: 15px; /* Keep consistent */
}
#addModelForm input:last-of-type, /* This targets the last input before textarea/button */
#addModelForm textarea:last-of-type {
     margin-bottom: 15px; /* Keep consistent */
}


input[type="number"] {
    width: 120px; /* Fixed width for number input */
    display: inline-block; /* Allow text/button next to it */
    margin-right: 10px;
    margin-bottom: 15px;
    vertical-align: middle;
}

.token-limit-section label {
    display: inline-block; /* Align label with number input */
    margin-right: 10px;
    vertical-align: middle;
    margin-bottom: 5px; /* Add margin-bottom for label above input */
}

.token-limit-section input[type="number"] {
     margin-bottom: 5px; /* Reduce margin bottom to align better with button */
}
.token-limit-section button {
     width: auto; /* Button width based on content */
     display: inline-block;
     margin-bottom: 5px; /* Align with input */
     padding: 10px 15px;
     vertical-align: middle;
     margin-top: 5px; /* Add slight margin top */
}


input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
    border-color: var(--button-bg);
    box-shadow: 0 0 8px rgba(167, 139, 250, 0.4);
}

textarea {
    resize: vertical; /* Allow vertical resize */
    min-height: 60px;
    max-height: 180px;
}

button {
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.1s ease;
    padding: 10px 15px;
    width: 100%; /* Full width by default in settings/models panels */
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box; /* Include padding in width */
}

button i {
     margin-right: 5px;
}
button:disabled i {
     color: rgba(49, 46, 129, 0.6); /* Dim icon when disabled */
}


button:hover:not(:disabled) {
    background-color: var(--button-hover-bg);
}

button:active:not(:disabled) {
    transform: scale(0.98);
}

button:disabled {
    background-color: rgba(167, 139, 250, 0.3); /* Dim button background */
    cursor: not-allowed;
    color: rgba(49, 46, 129, 0.6); /* Dim text */
}

.quick-chat-btn {
    background-color: #8b5cf6; /* Violet-500 */
    margin-bottom: 15px;
}
.quick-chat-btn:hover:not(:disabled) {
    background-color: #a78bfa; /* Medium purple */
}


.status-message {
    font-size: 0.9em;
    margin-top: 5px; /* Adjusted margin top */
    margin-bottom: 15px;
    min-height: 1.2em; /* Ensure space even when empty */
    text-align: center;
    color: var(--system-color-info);
}

.status-message.success { color: var(--system-color-success); }
.status-message.error { color: var(--system-color-error); }
.hidden { display: none !important; }


.model-list {
    margin-top: 20px;
    margin-bottom: 0;
}

.model-item {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--border-radius-small);
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    word-break: break-word; /* Break long words in model names/instructions */
}

.model-item:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.model-item.active {
    background-color: rgba(167, 139, 250, 0.2);
    border-color: var(--button-bg);
    box-shadow: 0 0 5px rgba(167, 139, 250, 0.25);
}

.model-item-info {
    flex-grow: 1;
    margin-right: 10px;
    padding-right: 5px;
    min-width: 0; /* Allow flex item to shrink */
}

.model-item-info strong {
    display: block;
    font-size: 1em;
    margin-bottom: 3px;
    color: var(--button-bg);
    word-break: break-word;
}

.model-item-info span {
    display: block;
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.6);
     word-break: break-word;
}
.model-item-info span:last-child {
     margin-top: 5px;
}


.delete-model-btn {
    background: #ef4444; /* Red-400 */
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 1em;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    flex-shrink: 0; /* Prevent shrinking */
    transition: background-color 0.2s ease;
    line-height: 1;
}

.delete-model-btn i {
    margin: 0; /* Remove icon margin in round button */
}

.delete-model-btn:hover:not(:disabled) {
    background-color: #dc2626; /* Red-600 */
}


#chatView {
    flex-grow: 1; /* Takes available vertical space in tab-content-area */
    background: none;
    border-radius: 0;
    padding: 0; /* Inner padding handled by chat-box */
    max-width: 800px; /* Limit chat width */
    margin: 0 auto; /* Center chat */
    position: relative;
    overflow-y: hidden; /* Hide overflow for chat-box inside */
    display: flex; /* Use flex for header, actions, chat-box, input */
    flex-direction: column;
    box-sizing: border-box;
}


.chat-header {
    padding: 15px 0;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
    color: var(--button-bg);
    flex-shrink: 0; /* Prevent shrinking */
}

.token-display {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 5px;
    font-weight: normal;
}

.model-actions-panel {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
    flex-shrink: 0; /* Prevent shrinking */
}
.model-actions-panel button {
    width: auto; /* Width based on content */
    padding: 8px 12px;
    font-size: 0.95em;
}
.model-actions-panel button i {
     margin-right: 5px;
}


.chat-box {
    flex-grow: 1; /* Takes remaining vertical space */
    overflow-y: auto; /* Enable scrolling */
    padding-right: 10px; /* Space for scrollbar */
    margin-bottom: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    padding-bottom: 10px;
    box-sizing: border-box; /* Ensure padding is included */
}

.chat-box::-webkit-scrollbar { width: 8px; }
.chat-box::-webkit-scrollbar-track { background: var(--scroll-track); border-radius: 10px; }
.chat-box::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.08); }


.message {
    margin-bottom: 12px;
    padding: 10px 15px;
    border-radius: var(--border-radius-medium);
    max-width: 90%;
    line-height: 1.5;
    word-wrap: break-word;
    opacity: 0; /* Initial state for animation */
    transform: translateY(10px);
    animation: fadeInTranslate 0.3s ease forwards;
    display: flex; /* Use flex to align sender label and content */
    flex-direction: column; /* Stack sender and content */
}
.message strong {
    /* Style for the sender label */
     display: block; /* Ensure sender is on its own line */
     margin-bottom: 5px; /* Space between sender and content */
     font-weight: bold;
}
.message > span {
    /* Style for plain text content within the message, when not a code block */
    display: block; /* Ensure text spans take full width */
}


@keyframes fadeInTranslate {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Basic markdown styles for text parts */
.message em { font-style: italic; } /* Base style */
/* Inline code */
.message code {
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    background-color: var(--code-bg);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--code-text);
}


.user-message {
    background-color: rgba(167, 139, 250, 0.25); /* User purple background */
    color: var(--text-color);
    margin-left: auto; /* Align to right */
    border-bottom-right-radius: 4px; /* Squared corner */
    align-items: flex-end; /* Align items to the right within the flex container */
}

.user-message strong {
    color: var(--user-strong-color);
    text-align: right;
}
.user-message > span {
     text-align: right; /* Align user text to the right */
}


.gemini-message {
    background-color: rgba(139, 92, 246, 0.15); /* Gemini violet background */
    color: var(--text-color);
    margin-right: auto; /* Align to left */
    border-bottom-left-radius: 4px; /* Squared corner */
     align-items: flex-start; /* Align items to the left within the flex container */
}

.gemini-message strong {
    color: var(--gemini-strong-color);
    text-align: left;
}
.gemini-message > span {
     text-align: left; /* Align gemini text to the left */
}


.system-error {
    background-color: rgba(239, 68, 68, 0.15); /* Red background */
    color: var(--system-color-error);
    margin: 10px auto; /* Center */
    text-align: center;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--border-radius-medium); /* Full radius */
    max-width: 95%; /* Adjust max width */
     align-items: center; /* Center items within the flex container */
}
.system-error strong {
    color: #f87171; /* Red-300 */
}


.info-message {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    text-align: center;
    padding: 15px;
    border-radius: var(--border-radius-medium);
    margin: 20px auto;
    max-width: 80%;
    font-style: italic;
    opacity: 0; /* Initial state for animation */
    animation: fadeIn 0.5s ease forwards;
}
.info-message p { margin: 5px 0; }
.info-message p:first-child { margin-top: 0; }
.info-message p:last-child { margin-bottom: 0; }

@keyframes fadeIn {
    to { opacity: 1; }
}

/* Typing indicator dots */
.thinking-dots {
    display: inline-block;
}
.thinking-dots span {
    animation: blink 1.4s infinite both;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}


.input-area {
    display: flex;
    align-items: flex-end; /* Align items to the bottom (textarea and button) */
    gap: 10px;
    flex-shrink: 0; /* Prevent shrinking */
    width: auto; /* Use content width (flex handles stretching) */
    margin-top: auto; /* Push to the bottom */
}

.input-area textarea {
    flex-grow: 1; /* Take remaining space */
    margin-bottom: 0;
    width: auto; /* Override block display width */
    min-height: 40px;
    max-height: 150px;
    padding: 10px 15px;
    box-sizing: border-box; /* Include padding in element's size */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    resize: none; /* Disable manual resize */
}
.input-area textarea::-webkit-scrollbar { width: 8px; }
.input-area textarea::-webkit-scrollbar-track { background: var(--scroll-track); border-radius: 10px; }
.input-area textarea::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid var(--input-bg); }

.input-area button {
     width: auto; /* Width based on content */
     padding: 10px 20px;
     margin-bottom: 0;
     flex-shrink: 0; /* Prevent shrinking */
     height: 40px; /* Match min-height of textarea */
}

.scroll-to-bottom-btn {
    position: absolute;
    bottom: 80px; /* Above the input area */
    right: 30px;
    background-color: rgba(167, 139, 250, 0.8); /* Purple with transparency */
    color: var(--button-text);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
    box-shadow: var(--shadow);
    cursor: pointer;
    opacity: 0; /* Hidden by default */
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.2s ease;
    z-index: 10;
    backdrop-filter: blur(2px); /* Optional: blur background behind the button */
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-to-bottom-btn:hover {
    background-color: var(--button-hover-bg);
}
.scroll-to-bottom-btn:active {
    transform: scale(0.9);
}


.creator-credit {
    text-align: center;
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 20px;
    margin-bottom: 10px;
}


/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--modal-content-bg);
    padding: 30px;
    border-radius: var(--border-radius-large);
    box-shadow: var(--shadow);
    max-width: 500px;
    width: 90%;
    max-height: 90vh; /* Limit modal height */
    overflow-y: auto; /* Enable scrolling if content overflows */
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    display: flex; /* Use flex for layout inside modal */
    flex-direction: column;
}
.modal-content::-webkit-scrollbar { width: 8px; }
.modal-content::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 10px; }
.modal-content::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid var(--modal-content-bg); }


.modal-content h3 {
    color: var(--button-bg);
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
}

.modal-content label {
    display: block;
    margin-bottom: 5px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.95em;
}

.modal-content input[type="text"],
.modal-content input[type="number"],
.modal-content textarea {
    width: calc(100% - 20px); /* Account for padding */
    padding: 10px;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.modal-content textarea {
     min-height: 100px;
     max-height: 300px;
}

.modal-content input[type="number"] {
     width: 120px;
     margin-right: 0;
     display: inline-block;
}


.modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.modal-actions button {
    flex-grow: 1;
    width: auto; /* Override full width button style */
    padding: 10px 15px;
}

.modal-actions .cancel-button {
    background-color: var(--cancel-button-bg);
    color: white;
}
.modal-actions .cancel-button:hover {
     background-color: var(--cancel-button-hover-bg);
}

.modal-content .status-message {
    margin-top: 10px;
    margin-bottom: 0;
}


/* === Code Block Styles === */
.code-block {
    background-color: var(--code-block-bg);
    border-radius: var(--border-radius-small);
    margin: 10px 0; /* Space around the code block */
    overflow: hidden; /* Contains inner floats/flex */
    display: flex;
    flex-direction: column;
    max-width: 100%; /* Ensure it doesn't exceed message bubble width */
}

.code-block-header {
    background-color: var(--code-block-header-bg);
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer; /* Indicate clickable header */
}

.code-block-header .code-file-name {
     font-weight: bold;
     color: var(--code-file-name-color);
     flex-grow: 1; /* Allow name to take space */
     margin-right: 10px;
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
}

.code-block-actions {
    display: flex;
    gap: 5px; /* Space between action buttons */
    flex-shrink: 0; /* Prevent shrinking */
}

.code-action-btn {
    background-color: var(--code-action-btn-bg);
    color: var(--code-action-btn-text);
    border: none;
    border-radius: var(--border-radius-small);
    padding: 4px 8px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: auto; /* Override default full width button */
    height: auto; /* Override default height */
    line-height: 1.2; /* Adjust line height */
    display: flex;
    align-items: center;
    justify-content: center; /* Center icon */
    min-width: 30px; /* Ensure buttons aren't too small */
}
.code-action-btn i {
     margin: 0; /* Remove margin inside icon-only button */
     font-size: 0.9em;
}
.code-action-btn:hover:not(:disabled) {
    background-color: var(--code-action-btn-hover-bg);
}
.code-action-btn:active:not(:disabled) {
    transform: scale(0.95);
}
.code-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.code-action-btn.error {
    background-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
.code-action-btn.close-button {
     /* Already styled above, just ensure no text-specific overrides */
}


.code-block-body {
    max-height: 0; /* Start collapsed */
    overflow: hidden;
    transition: max-height 0.5s ease-in-out; /* Smooth collapse/expand */
    padding: 0 15px; /* Add horizontal padding */
}
.code-block-body.expanded {
    max-height: 300px; /* Reasonable preview height */
    overflow-y: auto; /* Add scrollbar if content exceeds max-height */
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--code-block-bg);
    padding-bottom: 15px; /* Add bottom padding when expanded */
}
/* Style for the scrollbar inside the collapsed/expanded body */
.code-block-body::-webkit-scrollbar { width: 8px; }
.code-block-body::-webkit-scrollbar-track { background: var(--code-block-bg); border-radius: 10px; }
.code-block-body::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid rgba(0,0,0,0.2); }


.code-block pre {
    margin: 0; /* Remove default pre margin */
    padding: 0; /* Padding moved to code-block-body */
    background-color: transparent; /* Background handled by code-block */
    overflow-x: auto; /* Allow horizontal scroll for code lines */
    word-wrap: normal; /* Prevent breaking long lines */
    white-space: pre; /* Preserve whitespace */
    word-break: normal; /* Prevent breaking words */
     /* Style scrollbar for pre if it overflows horizontally */
     scrollbar-width: thin;
     scrollbar-color: var(--scroll-thumb) transparent;
}
.code-block pre::-webkit-scrollbar { height: 6px; } /* Horizontal scrollbar height */
.code-block pre::-webkit-scrollbar-track { background: transparent; }
.code-block pre::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.2); border-radius: 10px; }


.code-block pre code {
    display: block; /* Ensure code block fills pre */
    padding: 0; /* Padding moved to code-block-body */
    background-color: transparent; /* Background handled by code-block */
    color: var(--text-color); /* Inherit text color */
    font-size: 0.95em; /* Slightly smaller font */
}

/* Basic code highlighting styles (replace with Prism.js theme if used) */
/* These are just placeholders; use a dedicated Prism.js theme CSS for real highlighting */
.code-block pre code.language-javascript { color: #f8c555; } /* Example */
.code-block pre code.language-css { color: #61dafb; }       /* Example */
.code-block pre code.language-html { color: #a78bfa; }       /* Example */
.code-block pre code.language-python { color: #8be9fd; }     /* Example */
/* Add more language styles or use a Prism theme CSS file */


/* === Full-screen Code Modal Styles === */
.code-modal-content {
     max-width: 95%; /* Wider than regular modals */
     max-height: 95vh; /* Taller than regular modals */
     padding: 0; /* No padding on the modal content itself */
     display: flex; /* Use flex column */
     flex-direction: column;
}

.code-modal-header {
    background-color: var(--code-block-header-bg);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1em;
    color: rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* Prevent header from shrinking */
}
.code-modal-header .code-file-name {
    flex-grow: 1;
    margin-right: 20px;
    font-weight: bold;
    color: var(--code-file-name-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.code-modal-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}
.code-modal-actions .code-action-btn {
     padding: 6px 12px; /* Slightly larger buttons in modal header */
     font-size: 0.9em;
}


.code-modal-body {
     flex-grow: 1; /* Code body takes all available space */
     overflow: hidden; /* Hide overflow for the pre element inside */
     padding: 15px 20px; /* Inner padding for the code */
     box-sizing: border-box;
     /* Ensure scrollbar here */
     overflow-y: auto;
     scrollbar-width: thin;
     scrollbar-color: var(--scroll-thumb) rgba(0,0,0,0.2);
}
.code-modal-body::-webkit-scrollbar { width: 8px; }
.code-modal-body::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 10px; }
.code-modal-body::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid rgba(0,0,0,0.3); }


.code-modal-body pre {
     margin: 0;
     padding: 0;
     background: transparent;
     overflow: visible; /* Let pre content determine horizontal scroll */
     width: 100%;
     height: 100%;
     word-wrap: normal; /* Allow wrapping in pre if needed */
     white-space: pre-wrap; /* Wrap lines within pre */
     word-break: break-word; /* Break words if necessary */
}

/* Horizontal scrollbar for pre inside modal body */
.code-modal-body pre {
     overflow-x: auto; /* Enable horizontal scroll for wide lines */
     scrollbar-width: thin;
     scrollbar-color: var(--scroll-thumb) rgba(0,0,0,0.2);
}
.code-modal-body pre::-webkit-scrollbar { height: 8px; } /* Horizontal scrollbar height */
.code-modal-body pre::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.code-modal-body pre::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 10px; border: 2px solid rgba(0,0,0,0.3); }


.code-modal-body code {
     display: block;
     padding: 0;
     background: transparent;
     color: var(--text-color);
     font-size: 1em; /* Normal font size in modal */
}


/* === Responsive adjustments based on Orientation and Max Width === */

/* Styles for screens up to 768px wide (general small screen adjustments) */
@media (max-width: 768px) {
    .app-container {
        border-radius: 0; /* Full screen */
        box-shadow: none;
    }
    .tab-content-area {
        padding: 10px; /* Reduce outer padding */
    }
    .tab-nav {
        padding: 5px 0; /* Reduce padding */
    }
    .tab-button {
        padding: 8px; /* Reduce padding */
        margin: 0 3px; /* Reduce margin */
        font-size: 1em;
    }

    /* Reduced inner padding for panels on small screens */
     .models-view-panel,
     .settings-panel {
         padding: 0 10px 10px 10px; /* Reduced inner padding */
     }
      .models-view-panel h2,
      .settings-panel h2 {
         padding-top: 10px; /* Reduce padding top for h2 */
      }


     input[type="text"], input[type="number"], textarea, button {
         padding: 8px;
     }
     input[type="number"] {
        width: 80px; /* Smaller width */
     }
     .setting-group button {
        padding: 8px 12px;
     }
     .token-limit-section label { /* Adjust label alignment on small screens */
         display: block;
         margin-right: 0;
         margin-bottom: 5px;
     }
     .token-limit-section input[type="number"] {
        display: inline-block; /* Keep inline */
        margin-bottom: 5px;
     }
     .token-limit-section button {
         display: inline-block; /* Keep inline */
         margin-top: 0;
         margin-bottom: 5px;
     }

     .message {
         padding: 8px 12px;
     }
     .input-area {
        gap: 8px; /* Smaller gap */
     }
     .input-area textarea {
         padding: 8px 12px;
         min-height: 35px; /* Slightly smaller */
         max-height: 120px; /* Slightly smaller */
     }
      .input-area button {
        padding: 8px 15px;
        height: 35px; /* Match textarea min-height */
        font-size: 0.95em;
      }
      .chat-header {
        font-size: 1.1em;
        padding: 10px 0;
      }
      .token-display {
        font-size: 0.7em;
      }
       .model-actions-panel {
         gap: 10px;
         margin-bottom: 10px;
       }
       .model-actions-panel button {
         padding: 6px 10px;
         font-size: 0.9em;
       }
       .scroll-to-bottom-btn {
        bottom: 65px; /* Adjust position */
        right: 15px;
        width: 32px; /* Smaller size */
        height: 32px;
        font-size: 1em;
      }

      .modal-content {
         padding: 20px;
         max-width: 95%;
      }
       .modal-content input[type="text"],
       .modal-content input[type="number"],
       .modal-content textarea {
           width: calc(100% - 16px); /* Adjust padding */
           padding: 8px;
       }
        .modal-actions {
            flex-direction: column; /* Stack buttons */
        }
         .modal-actions button {
             width: 100%; /* Full width when stacked */
         }

    /* Code block adjustments on small screens */
    .code-block-header {
        padding: 6px 10px;
        font-size: 0.8em;
    }
    .code-block-actions {
        gap: 3px;
    }
    .code-action-btn {
        padding: 3px 6px;
        font-size: 0.75em;
        min-width: 24px; /* Make them slightly smaller */
    }
    .code-action-btn i {
         margin: 0;
    }
     .code-action-btn.close-button {
         margin-left: 6px;
     }

    .code-block-body {
        padding: 0 10px; /* Adjust padding */
    }
     .code-block-body.expanded {
         padding-bottom: 10px;
     }

    .code-block pre code {
         font-size: 0.9em;
    }

    /* Full screen code modal adjustments on small screens */
    .code-modal-content {
         max-width: 98%; /* Even wider */
         max-height: 98vh; /* Even taller */
    }
    .code-modal-header {
         padding: 8px 10px;
         font-size: 0.9em;
    }
     .code-modal-header .code-file-name {
          margin-right: 10px;
     }
     .code-modal-actions {
          gap: 5px;
     }
    .code-modal-actions .code-action-btn {
         padding: 4px 8px;
         font-size: 0.8em;
    }
     .code-modal-body {
          padding: 10px; /* Adjust padding */
     }
    .code-modal-body code {
         font-size: 0.95em;
    }
}

/* Styles specifically for PORTRAIT orientation (regardless of exact width) */
@media (orientation: portrait) {
    .models-view-panel,
    .settings-panel {
        max-width: none; /* Отменяем ограничение по максимальной ширине */
        margin: 0;       /* Отменяем центрирование */
        /* Inner padding is handled by the max-width query if applicable,
           otherwise it uses the default padding */
    }
    /* h2 padding-top is handled by max-width query or default */
}
