/**
 * Layout Styles
 * Base layout, containers, and grid systems
 */

body {
    font-family: var(--font-family);
    background: #fafafa;
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Main Content */
.main-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 10rem 1rem 12rem;
    width: 100%;
    max-width: 56rem;
    margin: 0 auto;
}

.messages-wrapper {
    max-width: 56rem;
    margin: 0 auto;
    width: 100%;
    opacity: 0;
    animation: fadeInMessages 0.8s ease-out 0.5s forwards;
}

/* Message Bubbles */
.message {
    display: flex;
    margin-bottom: 1.5rem;
    gap: 0.75rem;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-content {
    max-width: min(42rem, 90vw);
    width: 100%;
}

.message.user .message-content {
    text-align: right;
}

.message-bubble {
    background: var(--surface);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--surface-tertiary);
    text-align: left;
    display: inline-block;
    position: relative;
    max-width: 100%;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s ease;
}

.message-bubble:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.message.user .message-bubble {
    background: #ebebeb;
    color: rgb(100, 100, 100);
    border: none;
}

/* Responsive message bubbles */
@media (max-width: 768px) {
    .message-content {
        max-width: calc(100vw - 2rem);
    }
    
    .message-bubble {
        padding: 0.875rem 1rem;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: calc(100vw - 1rem);
    }
    
    .message-bubble {
        padding: 0.75rem 0.875rem;
        border-radius: 0.875rem;
    }
}

/* ========================================
   Typography & Content Formatting System
   ======================================== */

/* Base Typography - Vertical Rhythm (1.5rem baseline) */
.message-text {
    font-size: clamp(0.9375rem, 0.875rem + 0.25vw, 1rem);
    line-height: 1.65;
    color: var(--text-primary);
}

/* Paragraphs */
.message-text p {
    margin: 0 0 1rem 0;
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

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

/* Headings - Responsive Scale */
.message-text h1 {
    font-size: clamp(1.75rem, 1.5rem + 1vw, 2.25rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 1.5rem 0 0.75rem 0;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.message-text h2 {
    font-size: clamp(1.5rem, 1.35rem + 0.75vw, 1.875rem);
    font-weight: 600;
    line-height: 1.3;
    margin: 1.5rem 0 0.75rem 0;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.message-text h3 {
    font-size: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
    font-weight: 600;
    line-height: 1.4;
    margin: 1.25rem 0 0.5rem 0;
    color: var(--text-primary);
}

.message-text h4 {
    font-size: clamp(1.125rem, 1.05rem + 0.35vw, 1.25rem);
    font-weight: 600;
    line-height: 1.5;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-primary);
}

.message-text h5 {
    font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    font-weight: 600;
    line-height: 1.5;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-secondary);
}

.message-text h6 {
    font-size: clamp(0.875rem, 0.85rem + 0.15vw, 1rem);
    font-weight: 600;
    line-height: 1.5;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* First heading has no top margin */
.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child,
.message-text h4:first-child,
.message-text h5:first-child,
.message-text h6:first-child {
    margin-top: 0;
}

/* Lists */
.message-text ul,
.message-text ol {
    margin: 0.75rem 0 1rem 0;
    padding-left: 1.75rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text li {
    margin: 0.375rem 0;
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text ul {
    list-style-type: disc;
}

.message-text ol {
    list-style-type: decimal;
}

.message-text li > ul,
.message-text li > ol {
    margin: 0.375rem 0;
}

.message-text ul ul {
    list-style-type: circle;
}

.message-text ul ul ul {
    list-style-type: square;
}

/* Nested lists */
.message-text li p {
    margin: 0.25rem 0;
}

/* Tables - Full Support */
.message-text table {
    width: 100%;
    max-width: 100%;
    margin: 1rem 0;
    border-collapse: collapse;
    border-spacing: 0;
    overflow-x: auto;
    display: block;
    font-size: clamp(0.8125rem, 0.75rem + 0.25vw, 0.9375rem);
}

.message-text thead {
    background: rgba(0, 0, 0, 0.03);
}

.message-text th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    white-space: nowrap;
}

.message-text th:last-child {
    border-right: none;
}

.message-text td {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text td:last-child {
    border-right: none;
}

.message-text tbody tr {
    transition: background-color 0.15s ease;
}

.message-text tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

.message-text tbody tr:last-child td {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Table wrapper for scroll on mobile */
.message-text table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .message-text table {
        font-size: 0.8125rem;
    }
    
    .message-text th,
    .message-text td {
        padding: 0.5rem 0.75rem;
    }
}

/* Code - Inline & Blocks */
.message-text code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
    font-size: 0.875em;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #c7254e;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.message-text pre {
    background: rgba(0, 0, 0, 0.04);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    line-height: 1.5;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    border: none;
    color: inherit;
    font-size: 0.875rem;
    display: block;
    white-space: pre;
}

/* Scrollbar for code blocks */
.message-text pre::-webkit-scrollbar {
    height: 8px;
}

.message-text pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.message-text pre::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.message-text pre::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Blockquotes */
.message-text blockquote {
    border-left: 4px solid var(--primary-500);
    padding: 0.75rem 0 0.75rem 1.25rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    background: rgba(135, 67, 225, 0.03);
    border-radius: 0 0.375rem 0.375rem 0;
    font-style: italic;
}

.message-text blockquote p {
    margin: 0;
}

.message-text blockquote p + p {
    margin-top: 0.75rem;
}

/* Links */
.message-text a {
    color: var(--primary-500);
    text-decoration: none;
    word-wrap: break-word;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.message-text a:hover {
    border-bottom-color: var(--primary-500);
}

/* Horizontal Rule */
.message-text hr {
    border: none;
    border-top: 2px solid rgba(0, 0, 0, 0.1);
    margin: 1.5rem 0;
}

/* Images */
.message-text img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1rem 0;
    display: block;
}

/* Emphasis */
.message-text strong,
.message-text b {
    font-weight: 600;
    color: var(--text-primary);
}

.message-text em,
.message-text i {
    font-style: italic;
}

/* Definition Lists */
.message-text dl {
    margin: 1rem 0;
}

.message-text dt {
    font-weight: 600;
    margin-top: 0.75rem;
}

.message-text dd {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Task Lists */
.message-text input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Keyboard Keys */
.message-text kbd {
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 0.25rem;
    padding: 0.125rem 0.375rem;
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 0.875em;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Abbreviations */
.message-text abbr {
    text-decoration: underline dotted;
    cursor: help;
}

/* Responsive Typography Adjustments */
@media (max-width: 768px) {
    .message-text {
        font-size: 0.9375rem;
    }
    
    .message-text ul,
    .message-text ol {
        padding-left: 1.5rem;
    }
    
    .message-text pre {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }
    
    .message-text blockquote {
        padding: 0.5rem 0 0.5rem 1rem;
        margin: 0.75rem 0;
    }
}

/* Print Styles */
@media print {
    .message-text {
        font-size: 12pt;
        line-height: 1.5;
    }
    
    .message-text h1 { font-size: 24pt; }
    .message-text h2 { font-size: 20pt; }
    .message-text h3 { font-size: 16pt; }
    .message-text h4 { font-size: 14pt; }
    .message-text h5 { font-size: 12pt; }
    .message-text h6 { font-size: 12pt; }
    
    .message-text a {
        color: #000;
        text-decoration: underline;
    }
}

/* Floating Input */
.floating-input {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 56rem;
    z-index: 75;
    opacity: 0;
    animation: slideUpInput 0.6s ease-out 0.7s forwards;
}

.input-container {
    background: var(--surface);
    border-radius: 1.5rem;
    padding: 1rem;
    box-shadow: var(--shadow-xl);
    border: 1px solid #e5e7eb;
}

.two-line-input {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.text-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.5;
    resize: none;
    max-height: 10rem;
    padding: 0.25rem 0;
}

.actions-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.actions-left, .actions-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Responsive */
@media (max-width: 768px) {
    .messages-container {
        padding: 8rem 1rem 10rem;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}
