/* ==========================================================================
   Home Assistant Tools - Global Styles
   ========================================================================== */

/* Design Tokens
   --------------------------------------------------------------------------
   Centralized values for radius, shadows, transitions and motion preferences.
   Reuse via var(--ht-*) in component styles below.
   -------------------------------------------------------------------------- */
:root {
    --ht-radius-sm: 6px;
    --ht-radius: 10px;
    --ht-radius-lg: 16px;

    --ht-shadow-card: 0 2px 6px rgba(0, 0, 0, 0.12);
    --ht-shadow-card-hover: 0 6px 16px rgba(0, 0, 0, 0.18);

    --ht-transition-fast: 0.15s ease;
    --ht-transition: 0.2s ease;

    --ht-hover-overlay: rgba(255, 255, 255, 0.08);
}

/* Respect reduced-motion users: disable all hover/transition animations. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Visible focus ring for keyboard users (kept subtle for mouse users). */
:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
    border-radius: var(--ht-radius-sm);
}

/* Focus States */
h1:focus {
    outline: none;
}

/* Form Validation */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

/* Error Boundary */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhb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OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

/* ==========================================================================
   Card Base - Unified styles for all card components (CardShell)
   ========================================================================== */

.card-base {
    transition: transform var(--ht-transition), box-shadow var(--ht-transition);
    height: 100%;
    border-radius: var(--ht-radius);
}

.card-base:hover {
    transform: translateY(-2px);
    box-shadow: var(--ht-shadow-card-hover);
}

.card-base .mud-card-header {
    padding-bottom: 8px;
}

.card-base .mud-card-content {
    min-height: 40px;
}

.card-clickable {
    cursor: pointer;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ==========================================================================
   Chat Streaming
   ========================================================================== */

.blinking-cursor {
    animation: blink 0.8s step-end infinite;
    color: var(--mud-palette-primary);
    font-weight: 100;
    font-size: 0.9em;
    opacity: 0.7;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* ==========================================================================
   Form Floating Labels (Bootstrap compatibility)
   ========================================================================== */

.form-floating > .form-control-plaintext::placeholder, 
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, 
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ==========================================================================
   AppBar & Navigation
   ========================================================================== */

.app-bar {
    backdrop-filter: blur(8px);
}

.installation-selector {
    text-transform: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: var(--ht-radius-sm);
    transition: background-color var(--ht-transition);
}

.installation-selector:hover {
    background-color: var(--ht-hover-overlay);
}

.user-menu-btn {
    text-transform: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: var(--ht-radius-sm);
    transition: background-color var(--ht-transition);
}

.user-menu-btn:hover {
    background-color: var(--ht-hover-overlay);
}

/* ==========================================================================
   Light Card - Color Picker Styles
   ========================================================================== */

.color-preview {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--mud-palette-lines-default);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.hue-slider-container {
    position: relative;
}

.hue-slider-container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, 
        hsl(0, 100%, 50%), 
        hsl(60, 100%, 50%), 
        hsl(120, 100%, 50%), 
        hsl(180, 100%, 50%), 
        hsl(240, 100%, 50%), 
        hsl(300, 100%, 50%), 
        hsl(360, 100%, 50%)
    );
    pointer-events: none;
    z-index: 0;
}

.hue-slider .mud-slider-track {
    background: transparent !important;
}

.color-temp-slider {
    position: relative;
}

.color-temp-slider::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, 
        #ff9800,
        #fff5e6, 
        #e3f2fd,
        #64b5f6
    );
    pointer-events: none;
    z-index: 0;
}

.color-preset-btn {
    border-radius: 50% !important;
    padding: 0 !important;
    border: 2px solid var(--mud-palette-lines-default) !important;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.color-preset-btn:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.color-mode-chips .mud-chip {
    cursor: pointer;
}

.child-lights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-top: 8px;
    max-height: 500px;
    overflow-y: auto;
    padding: 4px;
}

.child-lights-grid .light-card {
    margin: 0;
}

.room-expansion-panel .mud-expand-panel {
    margin-bottom: 8px;
}

.room-expansion-panel .mud-expand-panel-header {
    padding: 12px 16px;
}

/* ==========================================================================
   Responsive Helpers
   ========================================================================== */

@media (max-width: 600px) {
    .hide-on-mobile {
        display: none !important;
    }
    
    .card-base .mud-card-header-content .mud-text {
        font-size: 0.9rem;
    }
    
    .color-preset-btn {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
    }
}

/* ==========================================================================
   Chat Page Styles
   ========================================================================== */

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    background: var(--mud-palette-surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--mud-palette-lines-default);
}

.chat-header {
    background: var(--mud-palette-background-gray);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: var(--mud-palette-surface);
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}

.chat-empty-icon {
    opacity: 0.3;
    margin-bottom: 16px;
}

.chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.chat-message-wrapper {
    display: flex;
    width: 100%;
}

.chat-message-wrapper.user {
    justify-content: flex-end;
}

.chat-message-wrapper.assistant {
    justify-content: flex-start;
}

.chat-message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-user-bubble {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-bottom-right-radius: 4px;
}

.chat-assistant-bubble {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-bottom-left-radius: 4px;
}

.chat-streaming-status {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--mud-palette-lines-default);
}

.chat-status-indicator {
    font-size: 0.8rem;
    opacity: 0.8;
    display: block;
}

.chat-inline-tool-progress {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.chat-tool-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: var(--mud-palette-success);
    color: var(--mud-palette-success-text);
    border-radius: 12px;
    white-space: nowrap;
}

.chat-waiting-text {
    opacity: 0.6;
    font-style: italic;
}

.chat-message-content {
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Chat message markdown rendering */
.chat-message-content p {
    margin: 0 0 0.5em 0;
}

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

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

.chat-message-content em {
    font-style: italic;
}

.chat-message-content code {
    background: var(--mud-palette-background-gray);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.chat-message-content pre {
    background: var(--mud-palette-background-gray);
    padding: 0.75em 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.chat-message-content pre code {
    background: none;
    padding: 0;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.chat-message-content li {
    margin: 0.25em 0;
}

.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
    margin: 0.75em 0 0.25em 0;
    font-weight: 600;
}

.chat-message-content h4 { font-size: 1.1em; }
.chat-message-content h5 { font-size: 1.05em; }
.chat-message-content h6 { font-size: 1em; }

.chat-message-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

.chat-message-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.chat-tool-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.chat-tool-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    padding: 8px 12px;
    margin: -12px -16px 12px -16px;
    background: var(--mud-palette-background);
    border-radius: 18px 18px 0 0;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-tool-summary:hover {
    background: var(--mud-palette-action-default-hover);
}

.chat-expand-icon {
    margin-left: auto;
    opacity: 0.6;
}

.chat-tool-details-expanded {
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.chat-tool-detail-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.8rem;
}

.chat-tool-name {
    opacity: 0.9;
}

.chat-tool-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

.chat-tool-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    opacity: 0.9;
}

.chat-cursor {
    animation: chat-blink 1s infinite;
    color: var(--mud-palette-primary);
}

@keyframes chat-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.chat-typing-indicator {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.chat-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--mud-palette-primary);
    animation: chat-bounce 1.4s infinite ease-in-out both;
}

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

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

.chat-status-text {
    font-size: 0.85rem;
    opacity: 0.8;
}

.chat-tool-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.chat-input-area {
    padding: 12px 16px;
    background: var(--mud-palette-background-gray);
    border-top: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-input {
    flex: 1;
}

.chat-input .mud-input-slot,
.chat-input .mud-input-outlined-border {
    border-radius: 24px !important;
}

.chat-input .mud-input-root-outlined {
    background: transparent !important;
}

.chat-input .mud-input-outlined {
    background: var(--mud-palette-surface) !important;
    border-radius: 24px !important;
}

.chat-mic-button {
    flex-shrink: 0;
    margin-bottom: 4px;
}

/* Chat mobile optimizations */
@media (max-width: 600px) {
    .chat-container {
        height: calc(100vh - 80px);
        max-height: calc(100vh - 80px);
        border-radius: 0;
    }
    
    .chat-message-bubble {
        max-width: 90%;
        padding: 10px 14px;
    }
    
    .chat-messages {
        padding: 12px;
    }
    
    .chat-input-area {
        padding: 10px 12px;
    }
}
/* ==========================================================================
   Login Page (Razor Page, no MudBlazor)
   ========================================================================== */

.login-body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.login-container {
    background: #1e1e2e;
    border-radius: var(--ht-radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    padding: 48px;
    width: 100%;
    max-width: 400px;
}

.login-title {
    color: #fff;
    text-align: center;
    margin-bottom: 8px;
    font-size: 28px;
    font-weight: 600;
}

.login-subtitle {
    color: #a0a0a0;
    text-align: center;
    margin-bottom: 32px;
    font-size: 14px;
}

.login-form-group {
    margin-bottom: 20px;
}

.login-form-group label {
    display: block;
    color: #b0b0b0;
    margin-bottom: 8px;
    font-size: 14px;
}

.login-form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #3a3a4a;
    border-radius: var(--ht-radius-sm);
    background: #2a2a3a;
    color: #fff;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color var(--ht-transition);
}

.login-form-group input:focus {
    outline: none;
    border-color: #7c3aed;
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
    color: #fff;
    border: none;
    border-radius: var(--ht-radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow var(--ht-transition);
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.btn-login:active {
    transform: translateY(0);
}

.login-error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 12px 16px;
    border-radius: var(--ht-radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo svg {
    width: 64px;
    height: 64px;
    fill: #7c3aed;
}

/* ==========================================================================
   Settings Page
   ========================================================================== */

.settings-url {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-url a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px;
    background: var(--mud-palette-background-grey);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--ht-radius-sm);
}

.settings-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    line-height: 1.1;
}

.settings-stat-value {
    font-weight: 600;
    color: var(--mud-palette-primary);
}

.settings-features {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.settings-log-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.settings-about {
    background: transparent !important;
    border: 1px dashed var(--mud-palette-lines-default);
}

/* ============================================================
   Shared dialog chrome
   - Title row supports a trailing close icon button (top-right)
   - app-dialog-tabbed: edge-to-edge tab content (no horizontal padding gap)
   ============================================================ */
.app-dialog .mud-dialog-title {
    padding-top: 12px;
    padding-bottom: 8px;
}

.app-dialog .app-dialog-title {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.app-dialog .app-dialog-title-spacer {
    flex: 1 1 auto;
}

.app-dialog .mud-dialog-content {
    padding: 16px 16px 0 16px;
}

/* For dialogs with MudTabs: remove horizontal padding so tabs span edge-to-edge */
.app-dialog-tabbed .mud-dialog-content {
    padding: 8px 0 0 0;
}

.app-dialog-tabbed .mud-tabs .mud-tabs-toolbar {
    padding-left: 16px;
    padding-right: 16px;
}

.app-dialog-tabbed .mud-tabs .mud-tabs-panels {
    padding: 0;
}

.app-dialog-tabbed .mud-tab-panel {
    padding: 16px;
}

.app-dialog-close {
    margin-left: auto;
}

