* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    -webkit-touch-callout: none;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    max-height: 800px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
}

.header-content {
    flex: 1;
    text-align: center;
}

.header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.header .status {
    font-size: 12px;
    opacity: 0.9;
}

.options-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    min-width: 44px;
    height: 44px;
}

.options-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: none;
    box-shadow: none;
}

.options-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

.options-btn svg {
    width: 24px;
    height: 24px;
}

.options-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100%;
    background: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.options-panel.open {
    right: 0;
}

.options-panel::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.options-panel.open::before {
    opacity: 1;
    pointer-events: auto;
}

.options-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.options-header h2 {
    font-size: 20px;
    margin: 0;
}

.close-btn {
    background: transparent;
    color: #1f2937;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    min-width: 44px;
    height: 44px;
}

.close-btn:hover {
    background: #f3f4f6;
    transform: none;
    box-shadow: none;
}

.close-btn svg {
    width: 24px;
    height: 24px;
}

.options-content {
    padding: 20px;
    flex: 1;
}

.settings-group {
    margin-bottom: 20px;
}

.settings-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #1f2937;
    font-size: 14px;
}

.settings-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.settings-group select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    margin-right: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #f9fafb;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-in;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.message.user {
    align-items: flex-end;
}

.message.ai {
    align-items: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.4;
    overflow-wrap: break-word;
}

.message.user .message-bubble {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .message-bubble {
    background: #e5e7eb;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    padding: 0 8px;
}

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

.ai-thinking {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-thinking span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.ai-thinking span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-thinking span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

.tool-call {
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 8px 0;
    font-size: 12px;
    color: #92400e;
}

.input-area {
    border-top: 1px solid #e5e7eb;
    padding: 20px;
    background: white;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
    display: flex;
    gap: 10px;
    align-items: stretch;
    min-width: 0;
}

input[type="text"] {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-width: 0;
}

input[type="text"]:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

button {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
    user-select: none;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}


.clear-btn {
    background: #ef4444;
    padding: 8px 16px;
    font-size: 12px;
}

.clear-btn:hover {
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 15px;
    border-left: 3px solid #ef4444;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    text-align: center;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* Mobile Optimization */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        max-width: 100%;
        height: 100vh;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
    }

    .header {
        padding: 15px;
    }

    .header h1 {
        font-size: 20px;
        margin-bottom: 3px;
    }

    .header .status {
        font-size: 11px;
    }

    .chat-area {
        padding: 12px;
    }

    .message {
        margin-bottom: 12px;
    }

    .message-bubble {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
        line-height: 1.3;
    }

    .message-time {
        font-size: 10px;
    }

    .input-area {
        padding: 12px;
        gap: 8px;
    }

    .input-wrapper {
        gap: 6px;
    }

    input[type="text"] {
        padding: 10px 14px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 20px;
    }

    button {
        padding: 10px 14px;
        font-size: 12px;
        border-radius: 18px;
        flex-shrink: 0;
    }

    .clear-btn {
        padding: 8px 12px;
        font-size: 11px;
    }


    .tool-call {
        padding: 8px 10px;
        font-size: 11px;
        margin: 6px 0;
    }

    .error-message {
        padding: 10px;
        font-size: 12px;
        margin-bottom: 10px;
    }

    .empty-state svg {
        width: 48px;
        height: 48px;
        margin-bottom: 12px;
    }

    .empty-state p {
        font-size: 13px;
        padding: 0 12px;
    }
}

/* Extra small phones (< 400px) */
@media (max-width: 400px) {
    .header h1 {
        font-size: 16px;
    }

    .header .status {
        font-size: 9px;
    }

    .chat-area {
        padding: 8px;
    }

    .message {
        margin-bottom: 8px;
    }

    .message-bubble {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 13px;
    }

    .input-area {
        padding: 8px;
        gap: 4px;
    }

    .input-wrapper {
        gap: 4px;
    }

    input[type="text"] {
        padding: 8px 12px;
        font-size: 15px;
    }

    button {
        padding: 8px 12px;
        font-size: 11px;
        padding: 8px 10px;
    }

    .clear-btn {
        padding: 8px 10px;
        font-size: 10px;
    }


    .tool-call {
        padding: 6px 8px;
        font-size: 10px;
    }
}

/* Landscape mode optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        height: 100vh;
    }

    .header {
        padding: 10px 15px;
    }

    .header h1 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .chat-area {
        padding: 8px;
    }

    .input-area {
        padding: 8px 12px;
    }

    button {
        padding: 8px 12px;
        font-size: 11px;
    }

    input[type="text"] {
        padding: 8px 12px;
        font-size: 14px;
    }

    select {
        min-width: 80px;
        font-size: 11px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    button {
        min-height: 44px;
        min-width: 44px;
    }

    input[type="text"] {
        min-height: 44px;
    }

    select {
        min-height: 44px;
    }

    button:active {
        background: linear-gradient(135deg, #5568d3 0%, #6b3d91 100%);
    }
}

/* Mobile-specific options panel styles */
@media (max-width: 768px) {
    .header {
        padding: 15px;
    }

    .header-content {
        flex: 1;
    }

    .options-btn {
        min-width: 40px;
        height: 40px;
        padding: 6px;
    }

    .options-btn svg {
        width: 20px;
        height: 20px;
    }

    .options-panel {
        width: 100%;
        right: -100%;
    }

    .options-header {
        padding: 16px;
    }

    .options-header h2 {
        font-size: 18px;
    }

    .close-btn {
        min-width: 40px;
        height: 40px;
        padding: 6px;
    }

    .close-btn svg {
        width: 20px;
        height: 20px;
    }

    .options-content {
        padding: 16px;
    }

    .settings-group {
        margin-bottom: 16px;
    }

    .settings-group label {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .settings-group select {
        padding: 12px;
        font-size: 16px;
        min-height: 44px;
    }
}

/* Extra small phones */
@media (max-width: 400px) {
    .header {
        padding: 12px;
    }

    .options-btn {
        min-width: 38px;
        height: 38px;
    }

    .options-panel {
        width: 90vw;
        right: -90vw;
    }

    .options-header {
        padding: 12px;
    }

    .options-header h2 {
        font-size: 16px;
    }

    .options-content {
        padding: 12px;
    }
}

/* Landscape mode */
@media (max-height: 500px) {
    .options-panel {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}


