:root {
    --primary: #10B981;
    --secondary: #6EE7B7;
    --accent: #34D399;
    --bg-light: #F9FAFB;
    --bg-card: #FFFFFF;
    --text-dark: #1F2937;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
}

.gradient-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #10B981 0%, #34D399 100%);
    opacity: 0.03;
    pointer-events: none;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.header {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.2);
    flex-shrink: 0;
    /* Prevent header from shrinking */
    padding-top: max(1rem, env(safe-area-inset-top));
    /* Handle notch */
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

.logo {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.status-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-image: url('/assets/media/logos/bot-logo.png');
    background-size: cover;
    background-repeat: no-repeat;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    scroll-behavior: smooth;
    min-height: 0;
    /* Allow flex shrinking */
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
}

.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

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

.message-content {
    max-width: 75%;
    background: var(--bg-card);
    padding: 0.875rem 1.125rem;
    border-radius: 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    line-height: 1.5;
    border: 1px solid var(--border-color);
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-bottom-right-radius: 4px;
    border: none;
}

.message.bot .message-content {
    border-bottom-left-radius: 4px;
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: all 0.3s;
    display: block;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.message-text {
    display: block;
}

/* 3D Viewer Modal */
.viewer-3d-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.viewer-3d-modal.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.viewer-3d-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background: white;
    border-radius: 12px;
    padding: 2rem;
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.viewer-3d-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--primary);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 10;
}

.viewer-3d-close:hover {
    background: var(--accent);
    transform: rotate(90deg);
}

.viewer-3d-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

#threesixty {
    border-radius: 8px;
    overflow: hidden;
    background: #f0f0f0;
}

.viewer-3d-hint {
    text-align: center;
    color: var(--text-muted);
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* @media (max-width: 480px) {
    .viewer-3d-content {
        max-width: 95%;
        padding: 1rem;
    }

    .viewer-3d-close {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
        top: 0.6rem;
        right: 0.6rem;
    }
} */

/* Image Viewer Modal */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background: white;
    border-radius: 12px;
    padding: 2rem;
    animation: zoomIn 0.3s ease-out;
}

.lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    /* box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5); */
}

.lightbox-hint {
    text-align: center;
    color: var(--text-muted);
    margin-top: 1rem;
    font-size: 0.875rem;
}

.lightbox-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 1rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-10px);
    }
}

.input-container {
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    /* Prevent input from shrinking */
    position: relative;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    /* Handle notch/home indicator */
}

.input-wrapper {
    display: flex;
    /* gap: 0.75rem; */
    align-items: center;
    background: var(--bg-light);
    border-radius: 25px;
    margin-left: 10px;
    margin-right: 10px;
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    transition: all 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

.float-container {
    position: relative;
    width: 100%;
}

.message-input {
    width: 100%;
    padding: 0.6rem 0.5rem;
    background: none;
    border: none;
    outline: none;
    font-size: 1rem;
    color: var(--text-dark);
}

/* Label berperan sebagai placeholder */
.float-label {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    max-width: calc(100% - 1rem);
    overflow: hidden;
    text-overflow: ellipsis; /* shrink saat ruang kecil */
}

/* Input kosong → label muncul
   Input ada isi → label hilang */
.message-input:not(:placeholder-shown) + .float-label {
    opacity: 0;
}
.message-input:focus + .float-label {
    opacity: 0;
}

.qr-scan-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: 0px solid var(--primary);
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

/* Modal scanner fullscreen */
#qrScannerModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(3px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 20px;
}

/* Reader box */
#qrReader {
    width: 100%;
    max-width: 380px;
    height: 380px;
    background: #111;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 0 25px rgba(0,255,150,0.3);
}

#qr-shaded-region{
   border-width: 20px 20px !important;
}

/* Optional: green scanning frame */
#qrReader::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 3px solid rgba(0,255,140,0.7);
    border-radius: 12px;
    box-sizing: border-box;
    pointer-events: none;
}

/* Tombol Tutup */
#qrCloseBtn {
    margin-top: 20px;
    padding: 10px 22px;
    font-size: 16px;
    border-radius: 10px;
    background: #ff4444;
    border: none;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

#qrCloseBtn:hover {
    background: #cc0000;
}

.qr-error-message {
    display: none;
    background: #dc2626;
    color: white;
    padding: 10px;
    margin: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
}

.qr-scan-btn:hover {
    /* background: var(--primary); */
    /* color: white; */
    transform: scale(1.05);
}

.qr-scan-btn:active {
    transform: scale(0.95);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

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

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

.welcome-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
}

.welcome-screen.active {
    display: flex;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.welcome-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    max-width: 500px;
}

.chip {
    background: var(--bg-card);
    padding: 0.625rem 1.25rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.875rem;
}

.chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.offline-badge {
    position: fixed;
    top: 70px;
    right: 1rem;
    background: #FF6B6B;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

@media (min-width: 768px) {
    .app-container {
        max-width: 800px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
}

/* AUDIO PLAYER */
.audio-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
    position: relative; /* penting untuk overlap */
}

.audio-play-btn {
    flex-shrink: 0;                 /* tombol play tidak mengecil */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.audio-progress {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    min-width: 80px;
    position: relative;
    z-index: 1;
}

.audio-progress-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    border-radius: 3px;
    transition: width 0.1s linear;
    position: relative;
}

/* Ini trik utamanya: durasi jadi absolute dan boleh overlap */
.audio-duration {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 42px;
    text-align: right;
    
    /* Magic happens here */
    position: absolute;
    right: 12px;           /* jarak dari kanan container */
    top: 50%;
    transform: translateY(-50%);
    background: var(--message-bg, #fff);  /* warna background bubble */
    padding: 0 6px;
    border-radius: 3px;
    pointer-events: none;  /* biar tetap bisa klik progress bar di bawahnya */
    z-index: 2;
    white-space: nowrap;
}

/* Khusus pesan user (biasanya background gelap) */
.message.user .audio-duration {
    background: var(--user-message-bg, #005c4b);
    color: white;
}

/* Opsional: saat layar masih lebar, durasi tetap di luar (seperti semula) */
@media (min-width: 420px) {
    .audio-duration {
        position: static;
        transform: none;
        background: none;
        padding: 0;
        pointer-events: auto;
    }
}