/* --- FONT & GLOBAL SETUP --- */
body {
    font-family: 'Outfit', ui-sans-serif, system-ui, sans-serif;
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    font-optical-sizing: auto;
}

img, a {
    -webkit-user-drag: none;
}

input, textarea {
    -webkit-user-select: auto;
    user-select: auto;
}

/* --- THEME VARIABLES --- */
:root,
[data-theme='light'] {
    --bg-background: #F5F8FD;
    --bg-surface: #EAF0F8;
    --bg-surface-variant: #DCE5F2;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6B7B94;
    --border-base: #C8D5E6;
    --primary: #1E4A8E;
    --on-primary: #FFFFFF;
    --primary-btn: #1E4A8E;
    --on-primary-btn: #FFFFFF;
    --secondary: #3A5F9A;
    --tertiary: #5C527F;
    --error: #B3261E;
    --on-error: #FFFFFF;
    --success: #2D8A4E;
    --warning: #D4A017;
    --danger: #B3261E;
    --owner-max-color: #5C6BC0;
    --owner-ami-color: #E91E63;
}

[data-theme='dark'] {
    --bg-background: #111827;
    --bg-surface: #1E2433;
    --bg-surface-variant: #283040;
    --text-primary: #FFFFFF;
    --text-secondary: #B0BDD0;
    --text-muted: #7889A0;
    --border-base: #334155;
    --primary: #a8c7fa;
    --on-primary: #0A2A5C;
    --primary-btn: #2E5FAD;
    --on-primary-btn: #E8F0FE;
    --secondary: #8AB4F8;
    --tertiary: #D7AEFB;
    --error: #F2B8B5;
    --on-error: #601410;
    --success: #81c995;
    --warning: #fdd663;
    --danger: #F2B8B5;
    --owner-max-color: #7986CB;
    --owner-ami-color: #F06292;
}


/* --- CORE ELEMENT STYLING --- */
.material-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-base);
    border-radius: 20px;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        background-color 0.2s;
    cursor: pointer;
}

.material-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background-color: color-mix(in srgb, var(--primary) 5%, var(--bg-surface));
}

.material-card:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.styled-input {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-base);
    color: var(--text-primary);
    padding: 0.875rem 1.5rem;
    border-radius: 9999px;
    width: 100%;
    outline: none;
    font-size: 0.9375rem;
    transition: background-color 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.styled-input:focus {
    background-color: var(--bg-background);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.styled-input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

textarea.styled-input {
    border-radius: 16px;
    resize: vertical;
}


/* --- CHIPS & BADGES --- */
.chip-Batch {
    background-color: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
    font-size: 0.75rem;
}

.chip-Flow {
    background-color: color-mix(in srgb, var(--success) 15%, transparent);
    color: var(--success);
    font-size: 0.75rem;
}

.chip-Shared {
    background-color: color-mix(in srgb, var(--warning) 20%, transparent);
    color: var(--warning);
    font-size: 0.75rem;
}

.owner-badge {
    border-radius: 9999px;
    transition: transform 0.2s;
}

.owner-badge:hover {
    transform: scale(1.1);
    z-index: 10;
}

.owner-badge:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.owner-badge.owner-Max {
    border-color: var(--primary);
    color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 10%, var(--bg-surface));
}

.owner-badge.owner-Ami {
    border-color: #f28b82;
    color: #f28b82;
    background-color: color-mix(in srgb, #f28b82 10%, var(--bg-surface));
}


/* --- BUTTONS --- */
button {
    user-select: none;
    -webkit-touch-callout: none;
}

/* Native touch feedback (squish) */
button:active,
[role="button"]:active,
.list-item:active,
.material-card:active,
.shopping-card:active,
.draggable-card:active {
    transform: scale(0.96);
    transition: transform 0.05s ease-out !important;
}

.filter-btn {
    border: 1px solid var(--border-base);
    background-color: transparent;
    color: var(--text-secondary);
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
    border-radius: 9999px;
}

.filter-btn:hover {
    background-color: var(--bg-surface-variant);
    border-color: var(--text-muted);
}

.filter-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.filter-btn.active {
    background-color: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 500;
}

button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

button.loading {
    position: relative;
    pointer-events: none;
}

button.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

.toggle-btn {
    border: 1px solid var(--border-base);
    background-color: transparent;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
    border-radius: 9999px;
}

.toggle-btn:hover:not(.selected) {
    border-color: var(--text-muted);
}

.toggle-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.toggle-btn.selected {
    background-color: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
}

.toggle-btn.selected:hover {
    filter: brightness(1.1);
}

.fb-auth-btn:hover:not(.bg-\[\#a8c7fa\]) {
    border-color: var(--text-muted);
}

.fb-sent-btn:hover {
    border-color: var(--text-muted);
}


/* --- NAVIGATION --- */
.nav-tab {
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    cursor: pointer;
    letter-spacing: 0.02em;
}

.nav-tab:hover {
    color: var(--text-primary);
}

.nav-tab:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.nav-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
    font-weight: 600;
}


/* --- MODALS --- */
.modal-backdrop {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    transform: translateY(20px) scale(0.98);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
        opacity 0.2s ease;
}

.modal-backdrop.open .modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Trap focus within modal */
.modal-backdrop:not(.hidden) {
    z-index: 50;
}


/* --- CALENDAR & DRAG/DROP --- */
.day-circle {
    transition: background-color 0.2s, border-color 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.day-circle:hover {
    background-color: var(--bg-surface-variant);
}

.day-circle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.day-circle.active {
    background-color: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
}


/* --- GOOGLE TASK VIEW --- */
.gtask-check {
    min-width: 24px;
    min-height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.1s;
    cursor: pointer;
}

.gtask-check i {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s;
}

.gtask-check:hover {
    border-color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 10%, transparent);
}

.gtask-check:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.gtask-check:active {
    transform: scale(0.9);
}

.gtask-check.checked {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
    animation: check-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gtask-check.checked i {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

@keyframes check-pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.draggable-card {
    transition: border-color 0.2s, background-color 0.2s;
    border-radius: 16px;
}

.draggable-card:hover {
    border-color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 5%, var(--bg-surface));
}

.draggable-card:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.draggable-card.owner-Max {
    border-left: 4px solid var(--owner-max-color);
}

.draggable-card.owner-Ami {
    border-left: 4px solid var(--owner-ami-color);
}

.droppable-area.drag-over {
    background-color: color-mix(in srgb, var(--primary) 10%, transparent);
    transition: background-color 0.2s;
}

.task-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-base);
    cursor: pointer;
    transition: background-color 0.2s;
}

.task-row:last-child {
    border-bottom: none;
}

.task-row:hover {
    background-color: var(--bg-surface-variant);
}

.task-row:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

/* --- SHOPPING LIST VIEW --- */
#shopping-options-menu {
    transform: scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.2s ease-out, opacity 0.2s ease-out, visibility 0.2s;
}

#shopping-options-menu.open {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

.shopping-category-header {
    font-size: 0.75rem;
    /* 12px - minimum acceptable */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem;
    color: var(--primary);
}

/* Empty states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.shopping-item-row {
    display: flex;
    align-items: flex-start;
    /* Changed from center to allow vertical stacking */
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-base);
    cursor: pointer;
    transition: background-color 0.2s;
}

.shopping-item-row:last-child {
    border-bottom: none;
}

.shopping-item-row:hover {
    background-color: var(--bg-surface-variant);
}

.shopping-item-row.completed {
    opacity: 0.6;
}

.shopping-item-row.completed .item-text {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.shopping-checkbox {
    min-width: 24px;
    min-height: 24px;
    border-radius: 8px;
    border: 2px solid var(--border-base);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 1rem;
    margin-top: 0.25rem;
    /* Adjust alignment */
    transition: background-color 0.2s, border-color 0.2s;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.shopping-checkbox:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.shopping-checkbox.checked {
    background-color: var(--success);
    border-color: var(--success);
    color: var(--on-primary);
}

/* --- SHOPPING CARD GRID (Desktop) --- */
.shopping-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-base);
    border-radius: 1.25rem;
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    width: 100% !important;
}

@media (min-width: 640px) {
    .shopping-card {
        border-radius: 1.75rem;
        padding: 1rem 1.25rem;
    }
}

.shopping-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.shopping-card:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.shopping-card.completed {
    opacity: 0.55;
}

.shopping-card.completed:hover {
    opacity: 0.75;
}

.shopping-card.completed .item-text {
    text-decoration: line-through;
    color: var(--text-secondary);
}

/* Action buttons: hidden on desktop, shown on hover */
.shopping-card .card-actions {
    opacity: 0;
    transition: opacity 0.15s;
}

.shopping-card:hover .card-actions {
    opacity: 1;
}

/* On touch devices / mobile, always show actions */
@media (hover: none) {
    .shopping-card .card-actions {
        opacity: 1;
    }
}

/* Inline add input */
.shopping-inline-add {
    background-color: var(--bg-surface);
    border: 2px dashed var(--border-base);
    border-radius: 1.75rem;
    padding: 0.875rem 1.25rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.shopping-inline-add:focus-within {
    border-color: var(--primary);
    border-style: solid;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}


/* --- UTILITIES --- */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}


.custom-scrollbar {
    -webkit-overflow-scrolling: touch;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--border-base);
    border-radius: 4px;
    border: 2px solid var(--bg-surface-variant);
}

.custom-scrollbar:hover::-webkit-scrollbar-thumb {
    background: var(--text-muted);
}

@keyframes animate-fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.animate-fade-in-up {
    animation: animate-fade-in-up 0.5s ease-out forwards;
}

/* --- SKIP TO MAIN CONTENT LINK --- */
.skip-link {
    position: absolute;
    left: -9999px;
}

.skip-link:focus {
    left: 0;
    z-index: 200;
}

/* --- SCROLL INDICATOR FOR FILTER CHIPS --- */
.filter-scroll-indicator {
    position: relative;
}

.filter-scroll-indicator::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--bg-background));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.filter-scroll-indicator.has-scroll::after {
    opacity: 1;
}

/* --- REDUCED MOTION SUPPORT --- */
@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;
    }
}

/* --- RESPONSIVE BREAKPOINTS --- */
@media (min-width: 420px) {
    .xs\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* --- HIGH CONTRAST MODE SUPPORT --- */
@media (prefers-contrast: high) {

    .filter-btn,
    .toggle-btn,
    button {
        border-width: 2px;
    }

    .styled-input:focus,
    button:focus-visible {
        outline-width: 3px;
    }
}


/* --- Chat Suggestion Chips --- */
.chat-suggestion-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 9999px;
    border: 1px solid var(--border-base);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.18s, border-color 0.18s, color 0.18s, transform 0.15s;
    white-space: nowrap;
}

.chat-suggestion-chip:hover {
    background: color-mix(in srgb, var(--primary) 12%, var(--bg-surface-variant));
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.chat-suggestion-chip:active {
    transform: translateY(0);
}

.chat-suggestion-chip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}


/* Jules Styles - Removed Chat Specifics, keeping generic if needed or cleaning up */

/* Hide suggestion chips once user has sent a message */
#chat-suggestions.hidden {
    display: none;
}

/* --- Notification View Layout Fix --- */
#view-notifications {
    box-sizing: border-box;
    /* Mobile: Fixed overlay */
    position: fixed;
    top: calc(64px + env(safe-area-inset-top));
    /* Header height */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background-color: var(--bg-background);
    padding: 0 1rem;
    height: auto;
    max-height: none;
    overflow: hidden;
    overflow-x: hidden;
    width: auto;
    max-width: 100%;
}

/* Desktop: no bottom nav, py-8 on main = 32px */
@media (min-width: 640px) {
    #view-notifications {
        position: static;
        z-index: auto;
        height: calc(100dvh - calc(120px + env(safe-area-inset-top)));
        max-height: calc(100dvh - calc(120px + env(safe-area-inset-top)));
        padding: 0 1.5rem;
    }
}

/* --- Chat View Layout Fix (prevents overflow bleeding on mobile) --- */
#view-chat {
    box-sizing: border-box;
    /* Mobile: top nav (64px) + bottom nav (80px) + main top pad (16px) + extra buffer (8px) */
    height: calc(100dvh - calc(168px + env(safe-area-inset-top)));
    max-height: calc(100dvh - calc(168px + env(safe-area-inset-top)));
    overflow: hidden;
}

/* Desktop: no bottom nav, py-8 on main = 32px */
@media (min-width: 640px) {
    #view-chat {
        height: calc(100dvh - calc(120px + env(safe-area-inset-top)));
        max-height: calc(100dvh - calc(120px + env(safe-area-inset-top)));
    }
}

#view-chat * {
    max-width: 100%;
}

.message .bubble {
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* --- Desktop Kanban Layout --- */
@media (min-width: 1024px) {
    #view-google-tasks .grid[class*="grid-cols-\[350px"] {
        min-height: calc(100dvh - 200px);
        align-items: stretch;
    }
}

/* --- HomeOS Chat Panel --- */
#chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--bg-surface);
    border: 1px solid var(--border-base);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s, transform 0.2s;
    transform-origin: bottom right;
    z-index: 1000;
}

#chat-panel.hidden {
    display: none;
}

.chat-header {
    background: var(--bg-surface-variant);
    padding: 16px;
    border-bottom: 1px solid var(--border-base);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
}

#chat-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

#chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    max-width: 85%;
}

.message.user {
    align-self: flex-end;
}

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

.message .bubble {
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.4;
    font-size: 0.95rem;
}

.message.user .bubble {
    background: var(--primary);
    color: var(--on-primary);
    border-bottom-right-radius: 2px;
}

.message.assistant .bubble {
    background: var(--bg-surface-variant);
    color: var(--text-primary);
    border-bottom-left-radius: 2px;
    white-space: pre-wrap;
    /* Preserve newlines */
}

/* Typing indicator */
.typing .dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite ease-in-out;
}

.typing .dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typing {

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

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

.chat-input-area {
    padding: 12px;
    border-top: 1px solid var(--border-base);
    display: flex;
    gap: 8px;
    background: var(--bg-surface);
}

#chat-input {
    flex: 1;
    background: var(--bg-surface-variant);
    border: 1px solid var(--border-base);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 24px;
    outline: none;
}

#chat-input:focus {
    border-color: var(--primary);
}

#chat-send {
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    #chat-panel {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        /* Full screen on mobile */
        border-radius: 0;
        border: none;
        z-index: 1100;
        /* Above bottom nav */
    }
}


/* --- Environment Branding --- */
.dev-mode-icon {
    background-color: var(--danger) !important;
}

/* Prevent horizontal shift due to scrollbar */
html {
    overflow-y: scroll;
    overscroll-behavior-y: none;
}

/* --- STANDARDIZED LIST ITEM (New Component) --- */
.list-item {
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.1s;
    border-radius: 16px;
}

.list-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.list-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- MEAL DRAG & DROP (mobile long-press) --- */
[data-meal-draggable-id] {
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.meal-dragging-active {
    overflow: hidden;
    touch-action: none;
}

.meal-dragging-active * {
    touch-action: none !important;
}

.meal-dragging {
    opacity: 0.35;
    transform: scale(0.97);
    transition: opacity 0.15s, transform 0.15s;
}

.meal-drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    pointer-events: none;
    border-radius: 20px;
    background: var(--bg-surface);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45), 0 0 0 2px var(--primary);
    overflow: hidden;
    opacity: 0.96;
    will-change: transform;
    transform: translate(-9999px, -9999px);
    transition: box-shadow 0.15s, opacity 0.15s;
}

.meal-drag-ghost-img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
}

.meal-drag-ghost-title {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.meal-hour-row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    min-height: 56px;
    border-top: 1px solid color-mix(in srgb, var(--border-base) 45%, transparent);
    padding: 2px 0;
    position: relative;
}

.meal-hour-row:first-child {
    border-top: none;
}

.meal-hour-label {
    flex-shrink: 0;
    width: 54px;
    padding-top: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: right;
}

.meal-hour-row.is-current-hour .meal-hour-label {
    color: var(--primary);
}

.meal-drop-zone {
    flex: 1 1 auto;
    min-height: 50px;
    padding: 4px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background-color 0.15s, box-shadow 0.15s;
}

.meal-hour-row.drag-over .meal-drop-zone {
    background-color: color-mix(in srgb, var(--primary) 18%, transparent);
    box-shadow: inset 0 0 0 2px var(--primary);
}

.meal-hour-row.is-current-hour::before {
    content: '';
    position: absolute;
    left: 54px;
    right: 0;
    top: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
    z-index: 1;
}

.meal-scheduled-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: color-mix(in srgb, var(--primary) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
    border-radius: 12px;
    cursor: grab;
    transition: background-color 0.15s;
}

.meal-scheduled-chip:hover {
    background: color-mix(in srgb, var(--primary) 22%, transparent);
}

.meal-scheduled-chip-img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.meal-scheduled-chip-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}

.meal-scheduled-chip-meta {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.meal-empty-slot-hint {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0;
    padding: 4px;
    transition: opacity 0.15s;
}

.meal-hour-row.drag-over .meal-empty-slot-hint {
    opacity: 0.85;
    color: var(--primary);
}

/* --- ACCENT PICKER --- */
.accent-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-base);
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.accent-swatch:hover {
    transform: scale(1.12);
}

.accent-swatch.selected {
    border-color: var(--bg-surface);
    box-shadow: 0 0 0 2px var(--text-primary);
}

.accent-custom,
.accent-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.accent-custom {
    position: relative;
    overflow: hidden;
    border: 2px dashed var(--border-base);
    font-size: 10px;
}

.accent-custom:hover,
.accent-reset:hover {
    color: var(--text-primary);
}

.accent-custom input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: none;
    padding: 0;
    cursor: pointer;
}

.accent-reset {
    border: none;
    font-size: 11px;
}

/* --- CONTROLS CUSTOMIZATION (edit mode) --- */
/* Each customizable section gets a relative anchor + room for the overlay. */
#ha-content.ha-editing [data-ha-section] {
    position: relative;
    outline: 1px dashed color-mix(in srgb, var(--border-base) 70%, transparent);
    outline-offset: 4px;
    border-radius: 12px;
}

/* Freeze tile interactions while editing so drags/hides don't toggle devices.
   Edit controls (.ha-edit-ctl) opt back in. */
#ha-content.ha-editing #ha-main-list a,
#ha-content.ha-editing #ha-main-list button:not(.ha-edit-ctl),
#ha-content.ha-editing #ha-main-list input,
#ha-content.ha-editing #ha-main-list [role="slider"] {
    pointer-events: none;
}

#ha-content.ha-editing .ha-edit-ctl {
    pointer-events: auto;
}

.ha-edit-overlay {
    display: none;
}

#ha-content.ha-editing .ha-edit-overlay {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    position: absolute;
    top: -0.5rem;
    right: 0.25rem;
    z-index: 6;
}

.ha-drag-handle,
.ha-eye-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    border-radius: 9999px;
    background: var(--bg-surface);
    border: 1px solid var(--border-base);
    color: var(--text-secondary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    touch-action: none;
}

.ha-drag-handle {
    cursor: grab;
}

.ha-drag-handle:active {
    cursor: grabbing;
}

.ha-eye-toggle[aria-pressed="false"] {
    color: var(--text-muted);
}

/* Block being dragged + container freeze (mirrors the meal-drag idiom). */
#ha-content.ha-drag-active {
    overflow: hidden;
    touch-action: none;
}

#ha-content.ha-drag-active * {
    touch-action: none !important;
}

.ha-dragging {
    opacity: 0.5;
    transform: scale(0.99);
    transition: opacity 0.15s, transform 0.15s;
}

/* Hidden / empty sections shown as dimmed placeholders while editing. */
#ha-content.ha-editing .ha-block-disabled {
    opacity: 0.45;
}

/* Empty (no-data) blocks collapse to nothing — give them a grabbable box. */
#ha-content.ha-editing [data-ha-state="empty"] {
    min-height: 3rem;
    background: color-mix(in srgb, var(--bg-surface-variant) 50%, transparent);
    border-radius: 12px;
}

#ha-content.ha-editing [data-ha-state="hidden"]::after,
#ha-content.ha-editing [data-ha-state="empty"]::after {
    position: absolute;
    top: -0.5rem;
    left: 0.5rem;
    z-index: 5;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 9999px;
    background: var(--bg-surface-variant);
    color: var(--text-muted);
}

#ha-content.ha-editing [data-ha-state="hidden"]::after {
    content: "Hidden";
}

#ha-content.ha-editing [data-ha-state="empty"]::after {
    content: "No data";
}

/* Unpin (×) button on pinned tiles, visible only while editing. */
.ha-unpin-btn {
    display: none;
    position: absolute;
    top: -0.4rem;
    right: -0.4rem;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 7;
}

#ha-content.ha-editing .ha-unpin-btn {
    display: flex;
}

/* Per-tile hide toggle on Climate tiles (only rendered in edit mode). */
.ha-tile-hide {
    position: absolute;
    top: -0.4rem;
    right: -0.4rem;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background: var(--bg-surface);
    border: 1px solid var(--border-base);
    color: var(--text-secondary);
    font-size: 11px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 7;
}

.ha-tile-hide[aria-pressed="false"] {
    color: var(--text-muted);
}

.ha-tile-hidden {
    opacity: 0.4;
}

/* Bottom edit toolbar. */
.ha-edit-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: min(92vw, 28rem);
    padding: 0.6rem 0.75rem;
    border-radius: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-base);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

/* Entity picker modal. */
.ha-pin-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    padding: 0;
}

@media (min-width: 640px) {
    .ha-pin-modal-overlay {
        align-items: center;
        padding: 1rem;
    }
}

.ha-pin-modal {
    width: 100%;
    max-width: 32rem;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-background);
    border: 1px solid var(--border-base);
    border-radius: 20px 20px 0 0;
    padding: 1rem;
}

@media (min-width: 640px) {
    .ha-pin-modal {
        border-radius: 20px;
    }
}

.ha-pin-list {
    overflow-y: auto;
    flex: 1;
    margin: -0.25rem;
    padding: 0.25rem;
}

.ha-pin-group-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.75rem 0.25rem 0.35rem;
}

.ha-pin-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 52px;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    text-align: left;
}

.ha-pin-row:hover {
    background: var(--bg-surface-variant);
}

.ha-pin-check {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    border: 1px solid var(--border-base);
    color: var(--text-muted);
    font-size: 11px;
}

.ha-pin-check.is-pinned {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}
