/**
 * INFINITE RENOVATIONS - V3: Warm Terracotta & Espresso — Dashboard Widget System
 * Styles for modular, customizable dashboard widgets
 * Last updated: Feb 10, 2026
 */

/* ========================================
   WIDGET WRAPPER
   ======================================== */

.widget-wrapper {
    position: relative;
    transition: all 0.3s ease;
}

.widget-wrapper.collapsed .widget-content {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
}

/* Hiding animation */
.widget-wrapper.hiding {
    opacity: 0;
    transform: translateX(-20px);
    max-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* Restoring animation */
.widget-wrapper.restoring {
    animation: widgetRestore 0.3s ease;
}

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

/* ========================================
   WIDGET HEADER & CONTROLS
   ======================================== */

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: default;
}

.widget-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.widget-drag-handle {
    display: none;
    cursor: grab;
    padding: 8px;
    margin: -4px;
    color: var(--text-muted);
    opacity: 0.5;
    transition: all 0.2s;
    border-radius: 0;
    user-select: none;
    -webkit-user-select: none;
}

.widget-drag-handle:hover {
    opacity: 1;
    background: rgba(212, 132, 90, 0.1);
    color: var(--primary);
}

.widget-drag-handle:active {
    cursor: grabbing;
    background: rgba(212, 132, 90, 0.2);
}

.widget-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.widget-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.widget-controls {
    display: none;
    align-items: center;
    gap: 4px;
}

.widget-control-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.widget-control-btn:hover {
    background: rgba(250, 243, 225, 0.05);
    border-color: var(--border-subtle);
    color: var(--text-secondary);
}

.widget-control-btn.widget-hide-btn:hover {
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.3);
    color: var(--danger);
}

/* Move buttons (mobile) */
.widget-move-controls {
    display: none;
    align-items: center;
    gap: 2px;
}

.widget-move-up,
.widget-move-down {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.2s;
}

.widget-move-up:hover,
.widget-move-down:hover {
    background: rgba(250, 243, 225, 0.05);
    color: var(--text-secondary);
}

/* ========================================
   CHANGE INDICATOR (Glow)
   ======================================== */

.widget-change-indicator {
    display: none;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    animation: changeGlow 2s ease-in-out infinite;
}

.widget-wrapper.has-changes .widget-change-indicator {
    display: block;
}

.widget-wrapper.has-changes {
    box-shadow: 0 0 0 1px rgba(212, 132, 90, 0.2),
                0 0 20px -5px rgba(212, 132, 90, 0.15);
}

@keyframes changeGlow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(212, 132, 90, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(212, 132, 90, 0);
    }
}

/* ========================================
   EDIT MODE
   ======================================== */

.dashboard-edit-mode .widget-drag-handle {
    display: flex;
    opacity: 0.7;
}

.dashboard-edit-mode .widget-drag-handle:hover {
    opacity: 1;
    transform: scale(1.1);
}

.dashboard-edit-mode .widget-controls {
    display: flex;
}

.dashboard-edit-mode .widget-wrapper {
    border: 2px dashed var(--border-primary);
    border-radius: 0;
    margin-bottom: 12px;
}

.dashboard-edit-mode .widget-wrapper .widget-header {
    cursor: grab;
}

.dashboard-edit-mode .widget-wrapper .widget-header:active {
    cursor: grabbing;
}

.dashboard-edit-mode .widget-wrapper .widget-header-left {
    cursor: grab;
}

.dashboard-edit-mode .widget-wrapper[draggable="true"] {
    cursor: default;
}

.dashboard-edit-mode .widget-wrapper.dragging {
    opacity: 0.4;
    cursor: grabbing;
    transform: scale(0.98);
    border-color: var(--primary) !important;
}

.dashboard-edit-mode .widget-wrapper.drag-over {
    border-color: var(--primary);
    background: rgba(212, 132, 90, 0.05);
}

/* Drop position indicators */
.dashboard-edit-mode .widget-wrapper.drag-over-above {
    border-top: 3px solid var(--primary) !important;
}

.dashboard-edit-mode .widget-wrapper.drag-over-below {
    border-bottom: 3px solid var(--primary) !important;
}

/* Drop indicator line */
.drop-indicator-line {
    height: 4px;
    background: linear-gradient(90deg, #D4845A, #F5D5B8);
    border-radius: 0;
    margin: 4px 0;
    animation: dropLinePulse 1s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(212, 132, 90, 0.5);
}

@keyframes dropLinePulse {
    0%, 100% { opacity: 1; transform: scaleX(1); }
    50% { opacity: 0.7; transform: scaleX(0.98); }
}

/* Drop target highlighting */
.dashboard-edit-mode .widget-wrapper.drop-target {
    transition: border-color 0.15s ease, background 0.15s ease;
}

/* Showing drop zones state */
.dashboard-main.showing-drop-zones {
    min-height: 200px;
}

.dashboard-main.showing-drop-zones .widget-wrapper.drop-target:hover {
    border-color: var(--border-primary);
    background: rgba(212, 132, 90, 0.03);
}

/* Touch dragging state */
.dashboard-edit-mode .widget-wrapper.touch-dragging {
    opacity: 0.5;
    transform: scale(0.98);
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(212, 132, 90, 0.2);
}

/* Desktop drag ghost */
.drag-ghost {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
}

.drag-ghost-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 2px solid var(--primary);
    border-radius: 0;
    box-shadow: 0 8px 32px rgba(43, 37, 32, 0.4), 0 0 20px rgba(212, 132, 90, 0.3);
}

.drag-ghost-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.drag-ghost-icon svg {
    width: 18px;
    height: 18px;
}

.drag-ghost-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Mobile drag clone */
.mobile-drag-clone {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
    transition: transform 0.1s ease;
}

.mobile-clone-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    background: var(--bg-elevated);
    border: 2px solid var(--primary);
    border-radius: 0;
    box-shadow:
        0 12px 40px rgba(43, 37, 32, 0.5),
        0 0 30px rgba(212, 132, 90, 0.4),
        inset 0 1px 0 rgba(250, 243, 225, 0.1);
    animation: mobileCloneEnter 0.2s ease;
}

@keyframes mobileCloneEnter {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.mobile-drag-clone.dropping {
    animation: mobileCloneDrop 0.2s ease forwards;
}

@keyframes mobileCloneDrop {
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

.mobile-clone-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(212, 132, 90, 0.2);
    border-radius: 0;
    color: var(--primary);
}

.mobile-clone-icon svg {
    width: 20px;
    height: 20px;
}

.mobile-clone-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Show move buttons on mobile in edit mode */
@media (max-width: 768px) {
    .dashboard-edit-mode .widget-move-controls {
        display: flex;
    }

    .dashboard-edit-mode .widget-drag-handle {
        /* Show handle for long-press on mobile */
        display: flex;
        opacity: 0.5;
    }

    .dashboard-edit-mode .widget-drag-handle:active {
        opacity: 1;
        background: rgba(212, 132, 90, 0.1);
    }
}

/* ========================================
   CHANGE EXPLANATION POPOVER (Desktop)
   ======================================== */

.change-popover {
    position: fixed;
    width: 340px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 0;
    box-shadow:
        0 16px 48px rgba(43, 37, 32, 0.5),
        0 0 0 1px rgba(212, 132, 90, 0.1);
    z-index: 9999;
    opacity: 0;
    transform: translateY(-8px);
    transition: all 0.2s ease;
}

.change-popover.visible {
    opacity: 1;
    transform: translateY(0);
}

.change-popover.above {
    transform: translateY(8px);
}

.change-popover.above.visible {
    transform: translateY(0);
}

/* Arrow pointing up to indicator */
.change-popover-arrow {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 8px;
    overflow: hidden;
}

.change-popover-arrow::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-bottom: none;
    border-right: none;
}

.change-popover.above .change-popover-arrow {
    top: auto;
    bottom: -8px;
    transform: translateX(-50%) rotate(180deg);
}

.change-popover-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: linear-gradient(180deg, rgba(212, 132, 90, 0.05) 0%, transparent 100%);
    border-radius: 0;
}

.change-popover-icon {
    font-size: 1.125rem;
}

.change-popover-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.change-popover-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.change-popover-close:hover {
    color: var(--text-primary);
    background: rgba(250, 243, 225, 0.05);
    border-color: var(--border-subtle);
}

.change-popover-body {
    padding: 12px 16px;
    max-height: 220px;
    overflow-y: auto;
}

.change-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 0;
}

.change-item:not(:last-child) {
    border-bottom: 1px solid var(--border-subtle);
}

/* Severity icons */
.change-severity-icon {
    font-size: 0.875rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.change-bullet {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}

.change-item.danger .change-bullet {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.4);
}

.change-item.warning .change-bullet {
    background: var(--warning);
    box-shadow: 0 0 8px rgba(210, 153, 34, 0.4);
}

.change-item.success .change-bullet {
    background: var(--success);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.4);
}

.change-item.info .change-bullet {
    background: var(--primary);
    box-shadow: 0 0 8px rgba(212, 132, 90, 0.4);
}

.change-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.change-item.danger .change-text {
    color: var(--danger);
}

.change-item.warning .change-text {
    color: var(--warning);
}

.change-item.success .change-text {
    color: var(--success);
}

.change-popover-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
    background: rgba(43, 37, 32, 0.15);
    border-radius: 0;
}

.change-time {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.change-time svg {
    opacity: 0.6;
}

.change-dismiss {
    padding: 6px 14px !important;
    font-size: 0.8125rem !important;
}

/* ========================================
   CHANGE EXPLANATION BOTTOM SHEET (Mobile)
   ======================================== */

.change-bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(43, 37, 32, 0.6);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.change-bottom-sheet-overlay.visible {
    opacity: 1;
}

.change-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border-radius: 0;
    box-shadow: 0 -8px 40px rgba(43, 37, 32, 0.5);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 80vh;
    overflow: hidden;
}

.change-bottom-sheet-overlay.visible .change-bottom-sheet {
    transform: translateY(0);
}

.change-bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-primary);
    border-radius: 0;
    margin: 12px auto 8px;
}

.change-bottom-sheet .change-popover-header {
    padding: 16px 20px;
    border-radius: 0;
}

.change-bottom-sheet .change-popover-body {
    padding: 16px 20px;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.change-bottom-sheet .change-item {
    padding: 14px 0;
}

.change-bottom-sheet .change-text {
    font-size: 0.9375rem;
}

.change-bottom-sheet .change-popover-footer {
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.change-bottom-sheet .change-dismiss {
    flex: 1;
    justify-content: center;
    padding: 12px 24px !important;
    font-size: 0.9375rem !important;
}

/* ========================================
   ENHANCED CHANGE INDICATOR
   ======================================== */

.widget-change-indicator {
    display: none;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}

.widget-change-indicator:hover {
    transform: scale(1.2);
}

.widget-wrapper.has-changes .widget-change-indicator {
    display: block;
    animation: changeIndicatorPulse 2s ease-in-out infinite;
}

.widget-wrapper.has-changes .widget-change-indicator.active {
    animation: changeIndicatorPulse 2s ease-in-out infinite, changeIndicatorGlow 1s ease-in-out infinite alternate;
}

@keyframes changeIndicatorPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(212, 132, 90, 0.5);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(212, 132, 90, 0);
    }
}

@keyframes changeIndicatorGlow {
    from {
        background: var(--primary);
    }
    to {
        background: #F5D5B8;
    }
}

/* Widget glow when has changes */
.widget-wrapper.has-changes {
    position: relative;
}

.widget-wrapper.has-changes::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow:
        0 0 0 1px rgba(212, 132, 90, 0.3),
        0 0 30px -10px rgba(212, 132, 90, 0.25),
        inset 0 0 20px -10px rgba(212, 132, 90, 0.1);
    animation: widgetChangeGlow 3s ease-in-out infinite;
}

@keyframes widgetChangeGlow {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* ========================================
   PRESET SWITCHER
   ======================================== */

.preset-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preset-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.preset-select {
    padding: 6px 32px 6px 12px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    background: var(--gradient-input);
    border: 1px solid var(--border-primary);
    border-radius: 0;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: all 0.2s;
}

.preset-select:hover {
    border-color: var(--border-subtle);
}

.preset-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ========================================
   EDIT LAYOUT BUTTONS
   ======================================== */

.edit-layout-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-primary);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-layout-btn:hover {
    background: rgba(250, 243, 225, 0.03);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.edit-layout-btn svg {
    width: 14px;
    height: 14px;
}

.done-editing-btn {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: white;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.done-editing-btn:hover {
    background: var(--primary-hover);
}

/* ========================================
   MANAGE WIDGETS BUTTON
   ======================================== */

.manage-widgets-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.manage-widgets-btn:hover {
    background: rgba(250, 243, 225, 0.03);
    color: var(--text-secondary);
}

.hidden-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--warning);
    color: white;
    font-size: 0.6875rem;
    font-weight: 700;
    border-radius: 0;
}

/* ========================================
   MANAGE WIDGETS MODAL
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(43, 37, 32, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.2s;
}

.modal-overlay.visible {
    opacity: 1;
}

.modal-content {
    width: 100%;
    max-width: 420px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 0;
    box-shadow: 0 20px 60px rgba(43, 37, 32, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.visible .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
}

.empty-state {
    text-align: center;
    padding: 24px;
}

.empty-state p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.empty-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 8px;
}

.hidden-widgets-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.restore-widget-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: rgba(250, 243, 225, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.restore-widget-btn:hover {
    background: rgba(212, 132, 90, 0.05);
    border-color: var(--primary);
}

.restore-widget-btn .widget-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(212, 132, 90, 0.1);
    border-radius: 0;
    color: var(--primary);
}

.restore-widget-btn .widget-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.restore-widget-btn .restore-label {
    font-size: 0.75rem;
    color: var(--primary);
    opacity: 0;
    transition: opacity 0.2s;
}

.restore-widget-btn:hover .restore-label {
    opacity: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
    background: rgba(43, 37, 32, 0.1);
}

/* Mobile modal */
@media (max-width: 768px) {
    .modal-content {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        border-radius: 0;
        max-height: 80vh;
        overflow-y: auto;
    }
}

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

.layout-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: var(--gradient-panel);
    border-bottom: 1px solid var(--border-subtle);
}

.layout-toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.layout-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ========================================
   COLLAPSED STATE INDICATOR
   ======================================== */

.widget-wrapper.collapsed .widget-header .collapse-icon {
    transform: rotate(-90deg);
}

.collapse-icon {
    transition: transform 0.2s;
}

/* ========================================
   SIDEBAR WIDGETS - PHASE 2 REORDERING
   ======================================== */

/* Sidebar widget header adjustments */
.sidebar-widget-header {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.sidebar-widget-header .section-title-v2 {
    flex: 1;
}

/* Sidebar drag handle - hidden by default */
.sidebar-drag-handle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    cursor: grab;
    opacity: 0;
    transition: opacity 0.2s;
}

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

/* Sidebar widget controls - hidden by default */
.sidebar-widget-controls {
    display: none;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.sidebar-move-up,
.sidebar-move-down {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sidebar-move-up:hover,
.sidebar-move-down:hover {
    background: rgba(250, 243, 225, 0.05);
    color: var(--text-secondary);
    border-color: var(--border-primary);
}

/* Edit mode - show sidebar controls */
.dashboard-edit-mode .sidebar-section {
    border: 1px dashed var(--border-subtle);
    border-radius: 0;
    margin-bottom: 8px;
    transition: border-color 0.2s, background 0.2s;
}

.dashboard-edit-mode .sidebar-section:hover {
    border-color: var(--border-primary);
}

.dashboard-edit-mode .sidebar-drag-handle {
    display: flex;
    opacity: 0.5;
}

.dashboard-edit-mode .sidebar-section:hover .sidebar-drag-handle {
    opacity: 1;
}

.dashboard-edit-mode .sidebar-widget-controls {
    display: flex;
}

/* Sidebar drop targets */
.dashboard-edit-mode .sidebar-section.drop-target {
    border-color: var(--border-primary);
}

.dashboard-edit-mode .sidebar-section.drag-over-above {
    border-top: 3px solid var(--primary) !important;
}

.dashboard-edit-mode .sidebar-section.drag-over-below {
    border-bottom: 3px solid var(--primary) !important;
}

.dashboard-edit-mode .sidebar-section.touch-dragging {
    opacity: 0.5;
    border-color: var(--primary) !important;
}

/* Sidebar showing drop zones */
.dashboard-sidebar.showing-drop-zones .sidebar-section {
    transition: border-color 0.15s ease;
}

/* Legacy styles for widget-wrapper in sidebar (if any) */
.dashboard-sidebar .widget-wrapper {
    /* Keep for backwards compatibility */
}

.dashboard-edit-mode .dashboard-sidebar .widget-wrapper {
    border: 1px dashed var(--border-subtle);
    margin-bottom: 8px;
}

.dashboard-edit-mode .dashboard-sidebar .widget-drag-handle {
    display: flex;
    opacity: 0.5;
}

.dashboard-sidebar .widget-move-controls {
    display: none;
}

.dashboard-edit-mode .dashboard-sidebar .widget-move-controls {
    display: flex;
}

/* ========================================
   INTEGRATION WITH EXISTING SECTIONS
   ======================================== */

/* Widget content inherits section padding */
.widget-wrapper .widget-content {
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
    overflow: hidden;
}

/* Remove duplicate headers - content sections no longer need their own headers */
.widget-wrapper .widget-content > .section-header-v2:first-child {
    display: none;
}

/* Dashboard section styles inside widget content */
.widget-wrapper .widget-content {
    padding: 0 20px 20px 20px;
}

/* Dual section specific fix */
.widget-wrapper[data-widget-id="lead-pipeline-estimate"] .widget-content {
    padding: 0 20px 20px 20px;
}

.widget-wrapper[data-widget-id="lead-pipeline-estimate"] .dual-section-grid {
    margin-top: 0;
}

/* Fix for sections that had padding */
.widget-wrapper .dashboard-section {
    padding: 0;
    border-bottom: none;
}

.widget-wrapper .dual-section {
    padding: 0;
    border-bottom: none;
}

/* Widget header inherits section styling */
.widget-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    background: transparent;
}

/* Widget header matches section-header-v2 styling */
.widget-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Section subtitle in widget header */
.widget-header .section-subtitle {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-left: 8px;
}

/* Section actions in widget header */
.widget-header .section-actions {
    display: flex;
    gap: 8px;
    margin-right: 16px;
}

/* Layout toolbar spacing */
.layout-toolbar {
    margin-bottom: 0;
}

/* Smooth transitions for reorder */
.dashboard-main .widget-wrapper {
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* First widget doesn't need top border in non-edit mode */
.dashboard-main .widget-wrapper:first-child .widget-header {
    border-top: none;
}

/* Add subtle separator between widgets */
.dashboard-main .widget-wrapper {
    border-bottom: 1px solid var(--border-subtle);
}

.dashboard-main .widget-wrapper:last-child {
    border-bottom: none;
}

/* Edit mode spacing */
.dashboard-edit-mode .dashboard-main .widget-wrapper {
    border-bottom: none;
    margin-bottom: 12px;
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    .layout-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 16px;
    }

    .layout-toolbar-left,
    .layout-toolbar-right {
        justify-content: space-between;
    }

    .preset-switcher {
        flex: 1;
    }

    .preset-select {
        flex: 1;
    }

    .widget-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .widget-header-left {
        flex: 1;
        min-width: 0;
    }

    .widget-title {
        font-size: 0.75rem;
    }

    .widget-header .section-actions {
        order: 3;
        width: 100%;
        margin-right: 0;
        margin-top: 8px;
    }

    .widget-controls {
        flex-shrink: 0;
    }

    /* Ensure move buttons show on mobile edit mode */
    .dashboard-edit-mode .widget-move-controls {
        display: flex !important;
    }

    .dashboard-edit-mode .widget-drag-handle {
        display: none !important;
    }
}

/* ========================================
   TOAST NOTIFICATIONS (Fallback)
   ======================================== */

.toast-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 0;
    box-shadow: 0 8px 32px rgba(43, 37, 32, 0.4);
    z-index: 10001;
    animation: toastIn 0.3s ease;
}

.toast-notification.toast-info {
    border-color: var(--primary);
}

.toast-notification.toast-success {
    border-color: var(--success);
}

.toast-notification.toast-warning {
    border-color: var(--warning);
}

.toast-notification.toast-danger {
    border-color: var(--danger);
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-primary);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

/* Mobile toast positioning */
@media (max-width: 768px) {
    .toast-notification {
        bottom: calc(24px + env(safe-area-inset-bottom, 0px));
        left: 16px;
        right: 16px;
        transform: none;
        text-align: center;
    }

    @keyframes toastIn {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes toastOut {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(20px);
        }
    }
}
