/* Saniservice Master Estimator - Frontend Styles */
/* Mobile-First Design */

:root {
    --sme-primary: #1a5f7a;
    --sme-secondary: #57c5b6;
    --sme-bg: #ffffff;
    --sme-text: #2d3748;
    --sme-text-light: #718096;
    --sme-border: #e2e8f0;
    --sme-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --sme-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --sme-radius: 16px;
    --sme-radius-sm: 8px;
}

* {
    box-sizing: border-box;
}

/* Full Page Container */
.sme-fullpage {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--sme-bg);
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Chat Container */
.sme-chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    background: var(--sme-bg);
    position: relative;
}

@media (min-width: 768px) {
    .sme-chat-container {
        max-width: 800px;
        padding: 20px;
    }
}

/* Header */
.sme-header {
    background: linear-gradient(135deg, var(--sme-primary) 0%, var(--sme-secondary) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

@media (min-width: 768px) {
    .sme-header {
        border-radius: var(--sme-radius) var(--sme-radius) 0 0;
        margin-top: 20px;
    }
}

.sme-header-icon {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sme-header-icon svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.sme-header-content h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
}

.sme-header-content p {
    margin: 2px 0 0;
    font-size: 13px;
    opacity: 0.9;
}

/* Messages Area */
.sme-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8fafc;
    min-height: 0;
}

@media (min-width: 768px) {
    .sme-messages {
        padding: 24px;
        min-height: 400px;
        max-height: calc(100vh - 280px);
    }
}

/* Message Bubbles */
.sme-message {
    display: flex;
    gap: 10px;
    max-width: 90%;
    animation: sme-fadeIn 0.3s ease-out;
}

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

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

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

.sme-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

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

.sme-message.assistant .sme-message-avatar {
    background: var(--sme-secondary);
    color: white;
}

.sme-message-content {
    padding: 12px 16px;
    border-radius: var(--sme-radius);
    line-height: 1.5;
    font-size: 15px;
}

.sme-message.user .sme-message-content {
    background: var(--sme-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.sme-message.assistant .sme-message-content {
    background: white;
    color: var(--sme-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--sme-shadow);
}

/* Image in message */
.sme-message-image {
    max-width: 100%;
    border-radius: var(--sme-radius-sm);
    margin-bottom: 8px;
}

.sme-message-image img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--sme-radius-sm);
    object-fit: cover;
}

/* Typing Indicator */
.sme-typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.sme-typing span {
    width: 8px;
    height: 8px;
    background: var(--sme-text-light);
    border-radius: 50%;
    animation: sme-bounce 1.4s infinite ease-in-out;
}

.sme-typing span:nth-child(1) { animation-delay: -0.32s; }
.sme-typing span:nth-child(2) { animation-delay: -0.16s; }
.sme-typing span:nth-child(3) { animation-delay: 0s; }

@keyframes sme-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.sme-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid var(--sme-border);
    position: sticky;
    bottom: 0;
}

@media (min-width: 768px) {
    .sme-input-area {
        padding: 16px 24px;
        border-radius: 0 0 var(--sme-radius) var(--sme-radius);
    }
}

/* Image Preview */
.sme-image-preview {
    display: none;
    margin-bottom: 12px;
    position: relative;
    padding: 8px;
    background: #f1f5f9;
    border-radius: var(--sme-radius-sm);
}

.sme-image-preview.active {
    display: block;
}

.sme-image-preview img {
    max-height: 120px;
    border-radius: 6px;
}

.sme-image-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

/* Input Form */
.sme-input-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.sme-input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 8px 12px;
    border: 2px solid transparent;
    transition: border-color 0.2s, background 0.2s;
}

.sme-input-wrapper:focus-within {
    border-color: var(--sme-primary);
    background: white;
}

.sme-input-actions {
    display: flex;
    gap: 4px;
}

.sme-input-action {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sme-text-light);
    transition: background 0.2s, color 0.2s;
}

.sme-input-action:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--sme-primary);
}

.sme-input-action svg {
    width: 22px;
    height: 22px;
}

.sme-input-action input[type="file"] {
    display: none;
}

textarea.sme-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 16px;
    line-height: 1.4;
    padding: 8px 0;
    min-height: 24px;
    max-height: 120px;
    font-family: inherit;
    color: var(--sme-text);
}

textarea.sme-input:focus {
    outline: none;
}

textarea.sme-input::placeholder {
    color: var(--sme-text-light);
}

.sme-send-btn {
    width: 48px;
    height: 48px;
    background: var(--sme-primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.sme-send-btn:hover {
    background: var(--sme-secondary);
}

.sme-send-btn:active {
    transform: scale(0.95);
}

.sme-send-btn:disabled {
    background: var(--sme-border);
    cursor: not-allowed;
}

.sme-send-btn svg {
    width: 22px;
    height: 22px;
}

/* Markdown Content Styling */
.sme-message-content h1,
.sme-message-content h2,
.sme-message-content h3,
.sme-message-content h4 {
    margin: 16px 0 8px;
    font-weight: 600;
}

.sme-message-content h1:first-child,
.sme-message-content h2:first-child,
.sme-message-content h3:first-child {
    margin-top: 0;
}

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

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

.sme-message-content ul,
.sme-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.sme-message-content li {
    margin: 4px 0;
}

.sme-message-content strong {
    font-weight: 600;
}

.sme-message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.sme-message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: var(--sme-radius-sm);
    overflow-x: auto;
    margin: 12px 0;
}

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

.sme-message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.sme-message-content th,
.sme-message-content td {
    border: 1px solid var(--sme-border);
    padding: 8px 12px;
    text-align: left;
}

.sme-message-content th {
    background: #f1f5f9;
    font-weight: 600;
}

/* Scope of Work Styling */
.sme-scope-of-work {
    background: #f8fafc;
    border: 1px solid var(--sme-border);
    border-radius: var(--sme-radius-sm);
    padding: 16px;
    margin: 12px 0;
}

/* Quote Summary */
.sme-quote-summary {
    background: linear-gradient(135deg, var(--sme-primary) 0%, var(--sme-secondary) 100%);
    color: white;
    padding: 16px;
    border-radius: var(--sme-radius-sm);
    margin: 12px 0;
}

.sme-quote-summary h3 {
    margin: 0 0 12px;
    color: white;
}

.sme-quote-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sme-quote-item:last-child {
    border-bottom: none;
    font-weight: 600;
    font-size: 1.1em;
    padding-top: 12px;
}

/* Welcome Message Styling */
.sme-welcome {
    text-align: center;
    padding: 40px 20px;
}

.sme-welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--sme-primary) 0%, var(--sme-secondary) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.sme-welcome-icon svg {
    width: 40px;
    height: 40px;
    fill: white;
}

.sme-welcome h2 {
    margin: 0 0 12px;
    color: var(--sme-text);
    font-size: 20px;
}

.sme-welcome p {
    color: var(--sme-text-light);
    margin: 0;
    line-height: 1.6;
}

/* Quick Actions */
.sme-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
    justify-content: center;
}

.sme-quick-action {
    background: white;
    border: 1px solid var(--sme-border);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 14px;
    color: var(--sme-text);
    cursor: pointer;
    transition: all 0.2s;
}

.sme-quick-action:hover {
    background: var(--sme-primary);
    color: white;
    border-color: var(--sme-primary);
}

.sme-quick-action.sme-upload-prompt {
    background: linear-gradient(135deg, var(--sme-primary) 0%, var(--sme-secondary) 100%);
    color: white;
    border-color: transparent;
}

.sme-quick-action.sme-upload-prompt:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

/* Loading State */
.sme-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sme-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--sme-border);
    border-top-color: var(--sme-primary);
    border-radius: 50%;
    animation: sme-spin 1s linear infinite;
}

@keyframes sme-spin {
    to { transform: rotate(360deg); }
}

/* Camera Modal */
.sme-camera-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    flex-direction: column;
}

.sme-camera-modal.active {
    display: flex;
}

.sme-camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    color: white;
}

.sme-camera-close {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sme-camera-preview {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.sme-camera-preview video {
    max-width: 100%;
    max-height: 100%;
}

.sme-camera-controls {
    padding: 20px;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.sme-camera-capture {
    width: 70px;
    height: 70px;
    background: white;
    border: 4px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

.sme-camera-capture:active {
    transform: scale(0.95);
}

/* Responsive Adjustments */
@media (max-width: 480px) {
    .sme-header {
        padding: 12px 16px;
    }
    
    .sme-header-content h1 {
        font-size: 16px;
    }
    
    .sme-messages {
        padding: 12px;
    }
    
    .sme-message {
        max-width: 95%;
    }
    
    .sme-message-content {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .sme-input-area {
        padding: 10px 12px;
    }
}

/* Safe Area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .sme-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .sme-fullpage.dark-mode {
        --sme-bg: #0f172a;
        --sme-text: #e2e8f0;
        --sme-text-light: #94a3b8;
        --sme-border: #334155;
    }
    
    .sme-fullpage.dark-mode .sme-messages {
        background: #1e293b;
    }
    
    .sme-fullpage.dark-mode .sme-message.assistant .sme-message-content {
        background: #334155;
        color: #e2e8f0;
    }
    
    .sme-fullpage.dark-mode .sme-input-area {
        background: #0f172a;
    }
    
    .sme-fullpage.dark-mode .sme-input-wrapper {
        background: #1e293b;
    }
}

/* Print Styles */
@media print {
    .sme-input-area,
    .sme-camera-modal {
        display: none !important;
    }
    
    .sme-messages {
        max-height: none;
        overflow: visible;
    }
}
