/* Base Reset & Variables */
:root {
    --bg-dark: #0f1115;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent-color: #6366f1; /* Indigo */
    --accent-glow: rgba(99, 102, 241, 0.4);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Ambient Background Animations */
.ambient-glow {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(100px);
    z-index: 0;
    animation: drift 10s infinite alternate ease-in-out;
}
.glow-1 {
    top: -10%;
    left: -10%;
    background-color: rgba(99, 102, 241, 0.3);
}
.glow-2 {
    bottom: -10%;
    right: -10%;
    background-color: rgba(168, 85, 247, 0.2);
}

@keyframes drift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(30px, 50px); }
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 450px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
    position: relative;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    background: rgba(15, 17, 21, 0.8);
    backdrop-filter: blur(20px);
}

/* Header */
.glass-header {
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    padding: 20px;
    text-align: center;
    backdrop-filter: blur(10px);
}
.header-content h1 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 1px;
}
.status-indicator {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
}
.dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
}

/* Settings Button */
.settings-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: 0.2s;
    padding: 4px;
}
.settings-btn:hover {
    color: var(--text-primary);
    transform: rotate(45deg);
}

/* Settings Drawer (Sidebar) */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex;
    justify-content: flex-end;
    opacity: 1;
    transition: opacity 0.3s ease;
    border-radius: inherit; /* inherit from app-container */
    overflow: hidden;
}
.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.glass-panel {
    background: rgba(15, 17, 21, 0.95);
    backdrop-filter: blur(25px);
    border-left: 1px solid var(--glass-border);
    width: 80%;
    max-width: 300px;
    height: 100%;
    box-shadow: -10px 0 40px rgba(0,0,0,0.5);
    transform: translateX(0);
    transition: transform 0.3s ease;
}
.modal-overlay.hidden .glass-panel {
    transform: translateX(100%);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 10px 20px;
    border-bottom: 1px solid var(--glass-border);
}
.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}
.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}
.close-btn:hover {
    color: white;
}
.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Voice Toggle in Settings */
.voice-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.voice-toggle input {
    display: none;
}
.toggle-slider {
    position: relative;
    width: 36px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    transition: 0.3s;
    border: 1px solid var(--glass-border);
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    top: 2px;
    left: 2px;
    transition: 0.3s;
}
.voice-toggle input:checked + .toggle-slider {
    background-color: var(--accent-color);
}
.voice-toggle input:checked + .toggle-slider::before {
    transform: translateX(16px);
    background-color: white;
}
.settings-dropdown {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: 0.2s;
}
.settings-dropdown:hover {
    background: rgba(255, 255, 255, 0.15);
}
.settings-dropdown option {
    background: var(--bg-dark);
    color: white;
}

/* Theme Classes */
body.theme-blue {
    --accent-color: #0ea5e9;
    --accent-glow: rgba(14, 165, 233, 0.4);
}
body.theme-blue .glow-1 { background-color: rgba(14, 165, 233, 0.3); }
body.theme-blue .glow-2 { background-color: rgba(56, 189, 248, 0.2); }

body.theme-pink {
    --accent-color: #ec4899;
    --accent-glow: rgba(236, 72, 153, 0.4);
}
body.theme-pink .glow-1 { background-color: rgba(236, 72, 153, 0.3); }
body.theme-pink .glow-2 { background-color: rgba(219, 39, 119, 0.2); }

/* Avatar Area */
.avatar-area {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 120px;
    border-bottom: 1px solid var(--glass-border);
    position: relative;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: background-image 0.3s ease;
    animation: float 4s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Character Specific Mouths & Faces */
.avatar-mouth {
    position: absolute;
    transform-origin: center;
    transition: transform 0.05s linear, height 0.05s linear;
}

/* Robot Avatar */
.avatar-area.avatar-robot {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="20" width="50" height="50" rx="10" fill="%231e293b" stroke="%236366f1" stroke-width="4"/><circle cx="38" cy="40" r="6" fill="%236366f1"/><circle cx="62" cy="40" r="6" fill="%236366f1"/></svg>');
}
.avatar-area.avatar-robot .avatar-mouth {
    width: 30px;
    height: 4px;
    background: #6366f1;
    border-radius: 2px;
    bottom: 35px;
    box-shadow: 0 0 8px #6366f1;
}

/* Dragon Avatar */
.avatar-area.avatar-dragon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M10 50 Q 50 -10, 90 50 L 50 90 Z" fill="%2310b981"/><circle cx="35" cy="45" r="4" fill="%23ef4444"/><circle cx="65" cy="45" r="4" fill="%23ef4444"/><path d="M 20 40 Q 30 20 40 40 Z" fill="%23059669"/><path d="M 60 40 Q 70 20 80 40 Z" fill="%23059669"/></svg>');
}
.avatar-area.avatar-dragon .avatar-mouth {
    width: 24px;
    height: 4px;
    background: #ef4444;
    border-radius: 10px;
    bottom: 25px;
    box-shadow: 0 0 12px #ef4444;
}

/* Dog Avatar */
.avatar-area.avatar-dog {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><ellipse cx="50" cy="50" rx="40" ry="30" fill="%23d97706" /><ellipse cx="15" cy="40" rx="12" ry="25" fill="%2392400e" /><ellipse cx="85" cy="40" rx="12" ry="25" fill="%2392400e" /><circle cx="35" cy="45" r="5" fill="%23000" /><circle cx="65" cy="45" r="5" fill="%23000" /><ellipse cx="50" cy="55" rx="8" ry="6" fill="%23000" /></svg>');
}
.avatar-area.avatar-dog .avatar-mouth {
    width: 16px;
    height: 4px;
    background: #ec4899;
    border-radius: 0 0 10px 10px;
    bottom: 30px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    animation: fadeIn 0.3s ease-out forwards;
    opacity: 0;
    transform: translateY(10px);
}
.system-message {
    align-self: flex-start;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    border-bottom-left-radius: 4px;
}
.user-message {
    align-self: flex-end;
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
    border-bottom-right-radius: 4px;
}
.ai-message {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

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

/* Loading Animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Footer / Input Area */
.glass-footer {
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
    padding: 15px 20px;
    backdrop-filter: blur(10px);
}
#commandForm {
    display: flex;
    gap: 10px;
}
#commandInput {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 12px 20px;
    color: white;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
}
#commandInput:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
}
.send-btn {
    background: var(--accent-color);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 0 15px var(--accent-glow);
}
.send-btn:hover {
    transform: scale(1.05);
    background: #4f46e5;
}
.send-btn:active {
    transform: scale(0.95);
}

.mic-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}
.mic-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}
.mic-btn.recording {
    background: #ef4444; /* Red for recording */
    color: white;
    border-color: #ef4444;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Main Content & Tabs */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding-bottom: 70px; /* Space for bottom nav */
}
.tab-view {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
}
.tab-view.active {
    display: flex;
}

/* Bottom Navigation */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(15, 17, 21, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    z-index: 50;
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
}
.nav-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: 0.2s;
    width: 80px;
}
.nav-btn.active {
    color: var(--accent-color);
}
.nav-btn:hover {
    color: white;
}

/* Devices Tab Specifics */
.devices-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}
.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: 0.2s;
}
.icon-btn:hover {
    color: white;
}
.devices-grid {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}
.category-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-left: 5px;
}
.devices-category-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}
.device-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    cursor: pointer;
    transition: 0.2s;
    min-height: 100px; /* Optional: gives a nice uniform minimum height */
}
.device-card:hover {
    background: rgba(255, 255, 255, 0.08);
}
.device-icon {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
}
.device-card.is-on.domain-light {
    border-color: #fbbf24;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
}
.device-card.is-on.domain-switch {
    border-color: #3b82f6;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}
.device-card.is-on.domain-sensor {
    border-color: #10b981;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}
.device-card.is-on.domain-media_player {
    border-color: #8b5cf6;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}
.device-card.is-on .device-icon {
    background: rgba(255, 255, 255, 0.1);
}
.device-info {
    margin-top: auto;
}
.device-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.device-state {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.device-card.is-on .device-state {
    color: var(--accent-color);
}

/* Bottom Sheet Modal (For Devices) */
.bottom-sheet {
    transform: translateY(100%);
    width: 100%;
    max-width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
    padding-bottom: 30px;
    position: absolute;
    bottom: 0;
    left: 0;
}
.modal-overlay:not(.hidden) .bottom-sheet {
    transform: translateY(0);
}

/* Device Control Elements */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}
.control-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.big-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: pointer;
}
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: 2px solid white;
    border-radius: 50%;
}

/* Desktop sizing adjustments */
@media (min-width: 600px) {
    .app-container {
        height: 85vh;
        border-radius: 30px;
        border: 1px solid var(--glass-border);
        overflow: hidden;
    }
}

.presets-row {
    display: flex;
    gap: 15px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.preset-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    transition: 0.2s;
}
.preset-btn:hover {
    transform: scale(1.15);
    border-color: rgba(255, 255, 255, 0.8);
}
.preset-btn:active {
    transform: scale(0.95);
}
