/**
 * SmartCaddie Chat Layout & Components
 * Extracted from index.html inline <style> block.
 * Loaded after theme.css — uses --sc-* variables.
 * @version 2.0.0
 */

/* ===================================================================
   ANIMATIONS
   =================================================================== */

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

@keyframes slide-in-right {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slide-out-right {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

@keyframes pulse-ring {
    0%, 100% { transform: scale(0.95); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.7; }
}

@keyframes recording-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.animate-fade-in { animation: fade-in 0.3s ease-out; }
.animate-slide-in-right { animation: slide-in-right 0.3s ease-out; }
.animate-slide-out-right { animation: slide-out-right 0.3s ease-in; }
.animate-pulse-ring { animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
.animate-recording-dot { animation: recording-dot 1.5s ease-in-out infinite; }

/* ===================================================================
   CHAT CONTAINER
   =================================================================== */

/* Scrollbar hidden to prevent flicker */
#chat-container {
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: var(--sc-bg-primary);
}

#chat-container::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* Message input auto-resize */
#message-input {
    resize: none;
    min-height: 44px;
    max-height: 120px;
}

/* ===================================================================
   MOBILE-OPTIMIZED FIXED LAYOUT
   Header stays at top, footer at bottom, chat scrolls in between
   =================================================================== */

html, body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
    background: var(--sc-bg-primary);
}

body {
    display: flex;
    flex-direction: column;
}

/* ===================================================================
   ELEMENT THEMING (dark theme, no !important)
   =================================================================== */

/* Header — replaces bg-gradient-to-r green overrides */
#main-header {
    background: var(--sc-bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* Chat input area */
.chat-input-area {
    background: transparent;
    border: none;
}

/* Input field focus & placeholder */
#message-input {
    background: var(--sc-bg-surface);
    color: var(--sc-text-primary);
    border: 1px solid rgba(255,255,255,0.1);
}

#message-input:focus {
    border-color: var(--sc-emerald, #10B981);
    outline: none;
    box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}

#message-input::placeholder {
    color: var(--sc-text-muted);
}

/* Send button — emerald gradient */
#send-button {
    background: linear-gradient(135deg, #10B981, #06B6D4);
    border: none;
    box-shadow: 0 4px 16px rgba(16,185,129,0.3);
}

#send-button:hover:not(:disabled) {
    box-shadow: 0 6px 24px rgba(16,185,129,0.45);
    transform: translateY(-1px);
}

#send-button:disabled {
    background: var(--sc-bg-elevated) !important;
    box-shadow: none;
    opacity: 0.5;
}

/* Voice button */
#voice-button {
    background: rgba(255,255,255,0.06);
    color: var(--sc-text-secondary);
    border: 1px solid rgba(255,255,255,0.08);
}

#voice-button:hover {
    background: rgba(255,255,255,0.12);
    color: var(--sc-text-primary);
}

/* Connection status */
.connection-status {
    color: var(--sc-text-muted);
}

/* Chat messages — outer container is layout-only (flex wrapper).
   Background/border lives on the inner bubble created by ui-renderer.js. */
.message-user {
    background: transparent !important;
    border: none !important;
    color: white !important;
}

.message-bot {
    background: transparent !important;
    border: none !important;
    color: var(--sc-text-primary) !important;
}

/* Header icon buttons */
.header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    background-color: rgba(255, 255, 255, 0.06);
    border: none;
    font-size: 1.35rem;
    color: var(--sc-emerald, #10B981);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.header-icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}

.header-icon-btn:focus-visible {
    outline: 2px solid rgba(16,185,129,0.4);
    outline-offset: 2px;
}

/* Hamburger menu overrides */
#hamburger-menu .border-b,
#hamburger-menu .border-t {
    border-color: rgba(255,255,255,0.06) !important;
}

#hamburger-menu nav button {
    color: var(--sc-text-secondary);
}

#hamburger-menu nav button:hover {
    background: rgba(255,255,255,0.06);
    color: var(--sc-text-primary);
}

/* Conversation sidebar toggle */
#conversation-sidebar-toggle:hover {
    background: var(--sc-bg-elevated) !important;
}

/* ===================================================================
   LAYOUT
   =================================================================== */

/* Header: fixed at top */
header {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 30;
}

/* Main content: fills remaining space */
main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Chat main: flex column with scrollable area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Preserve Tailwind utility behavior when JS toggles visibility. */
.chat-main.hidden {
    display: none !important;
}

/* Messages area: scrollable */
.chat-main > div:first-child {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Input area: fixed at bottom */
.chat-main > div:last-child {
    flex-shrink: 0;
}

/* Mobile: safe areas (iPhone notch, etc) */
@media (max-width: 768px) {
    header {
        padding-top: env(safe-area-inset-top);
    }

    .chat-main > div:last-child {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    /* Ensure map container fills available space when visible on mobile */
    #hole-map-container:not(.hidden) {
        flex: 1 1 0%;
        min-height: 0;
    }
}

.chat-header-inner {
    flex-wrap: wrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.quick-actions {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.quick-actions::-webkit-scrollbar {
    display: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Location Toggle States */
#location-toggle-btn.location-off-not-logged-in {
    background-color: rgba(234, 179, 8, 0.7);
    border-color: rgba(234, 179, 8, 0.5);
}

#location-toggle-btn.location-off-logged-in {
    background-color: rgba(220, 38, 38, 0.7);
    border-color: rgba(220, 38, 38, 0.5);
}

#location-toggle-btn.location-on {
    background-color: rgba(34, 197, 94, 0.4);
    border-color: rgba(34, 197, 94, 0.3);
}

/* Send button emoji/arrow toggle */
#send-button .send-emoji {
    display: none;
    font-size: 1.4rem;
}

#send-button .send-arrow {
    width: 1.1rem;
    height: 1.1rem;
}

/* Loading spinner */
.spinner {
    border: 2px solid rgba(255,255,255,0.1);
    border-top: 2px solid var(--sc-emerald, #10B981);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
}

/* Text truncation */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Desktop/Mobile Toggle */
.desktop-only {
    display: inline-flex;
}

.mobile-only {
    display: none;
}

/* Hamburger Menu Transform */
#hamburger-menu.open {
    transform: translateX(0);
}

/* Menu backdrop overlay */
.menu-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 35;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.menu-backdrop.active {
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ===================================================================
   RESPONSIVE (max-width: 768px)
   Many Android phones report 700-720px CSS width; 640 missed them.
   =================================================================== */

@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: inline-flex !important; }

    /* Compact Mobile Header */
    .chat-header {
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }

    .chat-header-inner {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    .chat-header-actions {
        flex: 0 0 auto;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    .chat-header-actions .header-icon-btn {
        flex: 0 0 auto;
        width: 2.5rem;
        height: 2.5rem;
    }

    .chat-header-actions .header-icon-btn svg {
        width: 1.5rem;
        height: 1.5rem;
    }

    /* Hide subtitle and location badge on mobile */
    .desktop-subtitle,
    .desktop-location-badge {
        display: none !important;
    }

    .chat-header h1 {
        font-size: 1.1rem;
    }

    .chat-header .w-10 {
        width: 2rem;
        height: 2rem;
        font-size: 1.25rem;
    }

    .quick-actions {
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 0.75rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding: 0 0.5rem;
    }

    #chat-container {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    #chat-container .message {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    #chat-container [data-card-type] {
        padding: 1rem !important;
        border-width: 1px !important;
        border-radius: 0.9rem !important;
    }

    #chat-container [data-card-type] h3 {
        font-size: 1.05rem;
    }

    #chat-container [data-card-type] .text-sm {
        font-size: 0.85rem;
    }

    #chat-container [data-card-type] .text-lg {
        font-size: 1rem;
    }

    #chat-container [data-card-type] button {
        padding: 0.65rem 0.75rem !important;
        font-size: 0.9rem !important;
    }

    .chat-main {
        padding-left: 1rem;
        padding-right: 1rem;
        padding-top: 0.75rem !important;
        padding-bottom: 0.5rem !important;
    }

    .chat-main > div:first-child {
        margin-bottom: 0.5rem !important;
    }

    #message-input {
        padding: 0.75rem 0.85rem;
        font-size: 0.95rem;
    }

    #send-button {
        padding: 0.6rem 1rem;
        gap: 0.35rem;
    }

    #send-button .send-text,
    #send-button .send-arrow {
        display: none;
    }

    #send-button .send-emoji {
        display: inline;
    }
}
