/* ============================================
   Dashboard Widgets System
   ============================================ */

/* Widget Grid Container */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    grid-auto-rows: 40px;
    gap: 10px;
    padding: 20px;
    min-height: calc(100vh - var(--header-height) - 40px);
    position: relative;
    align-items: stretch;
}

/* Placeholder for drag & drop */
.widget-grid.dragging {
    background: linear-gradient(to right, rgba(45, 90, 39, 0.03) 1px, transparent 1px),
                linear-gradient(to bottom, rgba(45, 90, 39, 0.03) 1px, transparent 1px);
    background-size: calc(100% / 24) 40px;
}

.widget-grid-placeholder {
    background: rgba(45, 90, 39, 0.1);
    border: 2px dashed var(--primary-green);
    border-radius: var(--radius-md);
    grid-column: span 8;
    grid-row: span 6;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

/* Dashboard Widget */
.dashboard-widget {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    overflow: hidden;
    height: 100%;
    min-height: 0;
}

.dashboard-widget:hover {
    box-shadow: var(--shadow-md);
}

.dashboard-widget.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.dashboard-widget.drag-over {
    border: 2px dashed var(--primary-green);
}

/* Widget Sizes */
.widget-size-small {
    grid-column: span 3;
    grid-row: span 2;
}

.widget-size-medium {
    grid-column: span 4;
    grid-row: span 3;
}

.widget-size-large {
    grid-column: span 6;
    grid-row: span 3;
}

.widget-size-wide {
    grid-column: span 8;
    grid-row: span 3;
}

.widget-size-tall {
    grid-column: span 4;
    grid-row: span 5;
}

.widget-size-full {
    grid-column: span 12;
    grid-row: span 4;
}

/* Widget Header */
.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);
    cursor: move;
    flex-shrink: 0;
}

.widget-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.widget-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: white;
}

.widget-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dashboard-widget:hover .widget-actions {
    opacity: 1;
}

.widget-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.widget-btn:hover {
    background: var(--bg-main);
    color: var(--text-primary);
}

.widget-remove:hover {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

/* Widget Content */
.widget-content {
    flex: 1;
    padding: 12px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Widget Resize Handles */
.widget-resize-handle {
    position: absolute;
    background: transparent;
    z-index: 10;
    transition: background 0.2s ease;
}

.widget-resize-e {
    right: 0;
    top: 0;
    width: 8px;
    height: 100%;
    cursor: e-resize;
}

.widget-resize-e:hover {
    background: rgba(45, 90, 39, 0.2);
}

.widget-resize-s {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 8px;
    cursor: s-resize;
}

.widget-resize-s:hover {
    background: rgba(45, 90, 39, 0.2);
}

.widget-resize-se {
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: se-resize;
    background: transparent;
}

.widget-resize-se:hover {
    background: rgba(45, 90, 39, 0.15);
    border-radius: 0 0 var(--radius-md) 0;
}

.widget-resize-se::after {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #ccc;
    border-bottom: 2px solid #ccc;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dashboard-widget:hover .widget-resize-se::after {
    opacity: 1;
}

/* Widget resizing state */
.dashboard-widget.resizing {
    z-index: 100;
    box-shadow: var(--shadow-lg);
    outline: 2px dashed var(--primary-green);
    outline-offset: 2px;
}

.dashboard-widget.resizing .widget-content {
    pointer-events: none;
    user-select: none;
}

/* Widget dragging state - pozycjonowanie */
.dashboard-widget.dragging {
    opacity: 0.5;
    z-index: 100;
}

.widget-drag-ghost {
    background: rgba(16, 185, 129, 0.2);
    border: 2px dashed #10b981;
    border-radius: 8px;
    pointer-events: none;
    z-index: 100;
    transition: left 0.1s ease, top 0.1s ease;
}

.widget-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    grid-auto-rows: 40px;
    gap: 10px;
    pointer-events: none;
    z-index: 99;
}

.widget-grid-overlay > div {
    background: rgba(16, 185, 129, 0.1);
    border: 1px dashed rgba(16, 185, 129, 0.3);
    border-radius: 4px;
}

/* Add Widget FAB Button */
.add-widget-fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(39, 174, 96, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 900;
    border: none;
}

.add-widget-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(39, 174, 96, 0.5);
}

.add-widget-fab:active {
    transform: scale(0.95);
}

.add-widget-fab i {
    transition: transform 0.3s ease;
}

.add-widget-fab.active i {
    transform: rotate(45deg);
}

/* Widget Picker Modal */
.widget-picker-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
}

.widget-picker-modal.active {
    display: flex;
}

.widget-picker-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.widget-picker-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

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

.widget-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.widget-picker-header h3 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.widget-picker-header h3 i {
    color: var(--primary-green);
}

.widget-picker-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.widget-picker-close:hover {
    background: var(--bg-main);
    color: var(--text-primary);
}

.widget-picker-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.widget-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

/* Widget Picker Item */
.widget-picker-item {
    background: var(--bg-main);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
}

.widget-picker-item:hover {
    border-color: var(--primary-green);
    background: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.widget-picker-item.dragging {
    opacity: 0.5;
    transform: scale(0.9);
}

.widget-picker-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}

.widget-picker-item h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.widget-picker-item p {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.widget-picker-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.widget-picker-footer p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Empty Dashboard State */
.widget-grid-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.widget-grid-empty i {
    font-size: 64px;
    color: #ddd;
    margin-bottom: 20px;
}

.widget-grid-empty h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.widget-grid-empty p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 400px;
}

/* Widget Loading State */
.widget-content.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.widget-content.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Widget-specific styles */
.widget-stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.widget-stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.widget-stat-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 20px;
}

.widget-stat-change.positive {
    background: rgba(39, 174, 96, 0.1);
    color: #27ae60;
}

.widget-stat-change.negative {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

/* Widget Table */
.widget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: auto;
}

.widget-table th {
    padding: 8px 6px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-main);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Sortable headers */
.widget-table th.sortable-header {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.widget-table th.sortable-header:hover {
    background: var(--bg-hover, #f0f0f0);
    color: var(--primary-green, #2d5a27);
}

.widget-table th.sortable-header i {
    margin-left: 2px;
    transition: color 0.15s ease;
}

.widget-table th.sortable-header:hover i {
    color: var(--primary-green, #2d5a27) !important;
}

.widget-table td {
    padding: 8px 6px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-table tr:hover {
    background: var(--bg-main);
}

/* Responsywna tabela - ukrywanie kolumn przy małej szerokości widgetu */
.widget-table-responsive {
    width: 100%;
    overflow-x: auto;
}

/* Dla wąskich widgetów - ukryj niektóre kolumny */
.dashboard-widget[style*="span 2"] .widget-table .hide-narrow,
.dashboard-widget[style*="span 3"] .widget-table .hide-narrow {
    display: none;
}

.dashboard-widget[style*="span 2"] .widget-table .hide-medium,
.dashboard-widget[style*="span 3"] .widget-table .hide-medium,
.dashboard-widget[style*="span 4"] .widget-table .hide-medium {
    display: none;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .widget-size-wide {
        grid-column: span 12;
    }
    
    .widget-size-large {
        grid-column: span 6;
    }
}

@media (max-width: 768px) {
    .widget-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
        padding: 12px;
    }
    
    .dashboard-widget {
        grid-column: span 4 !important;
        grid-row: span 3;
    }
    
    .add-widget-fab {
        left: 20px;
        bottom: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .widget-picker-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .widget-picker-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Widget size selector in settings */
.widget-size-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.widget-size-option {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.widget-size-option:hover,
.widget-size-option.active {
    border-color: var(--primary-green);
    background: rgba(45, 90, 39, 0.1);
    color: var(--primary-green);
}

/* Modern Period Selector for Realizacja widget */
.period-selector-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.period-mode-toggle {
    display: flex;
    background: #f0f2f5;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.period-mode-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #666;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.period-mode-btn:hover {
    color: #333;
}

.period-mode-btn.active {
    background: white;
    color: var(--primary-green, #1abc9c);
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    font-weight: 600;
}

.period-dropdown-wrapper {
    position: relative;
    min-width: 180px;
}

.period-dropdown-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: white;
    border: 1px solid #e0e4e8;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.period-dropdown-btn:hover {
    border-color: var(--primary-green, #1abc9c);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.period-dropdown-btn.open {
    border-color: var(--primary-green, #1abc9c);
    box-shadow: 0 0 0 3px rgba(26, 188, 156, 0.15);
}

.period-dropdown-btn i {
    font-size: 10px;
    color: #999;
    transition: transform 0.2s ease;
}

.period-dropdown-btn.open i {
    transform: rotate(180deg);
}

.period-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e0e4e8;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
}

.period-dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.period-dropdown-item {
    padding: 10px 14px;
    font-size: 13px;
    color: #444;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid #f5f5f5;
}

.period-dropdown-item:last-child {
    border-bottom: none;
}

.period-dropdown-item:hover {
    background: #f8faf9;
    color: var(--primary-green, #1abc9c);
}

.period-dropdown-item.selected {
    background: rgba(26, 188, 156, 0.1);
    color: var(--primary-green, #1abc9c);
    font-weight: 600;
}

.period-dropdown-item.current {
    position: relative;
}

.period-dropdown-item.current::after {
    content: 'teraz';
    position: absolute;
    right: 14px;
    font-size: 10px;
    font-weight: 500;
    color: white;
    background: var(--primary-green, #1abc9c);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ============================================
   Awizo Modal & Notifications
   ============================================ */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}
/* ═══════════════════════════════════════════════ */
/*  Widget Wyceny – mini tabelka cenowa           */
/* ═══════════════════════════════════════════════ */

.wyceny-widget-pricing .ww-ip-stawka,
.wyceny-widget-pricing .ww-ip-rodzaj,
.wyceny-widget-pricing .ww-ip-uwagi,
.wyceny-widget-pricing .ww-ip-logistyk {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    padding: 4px 6px;
}

.wyceny-widget-pricing .ww-ip-stawka {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #2d3748;
}

.wyceny-widget-pricing .ww-ip-rodzaj {
    font-size: 12px;
    color: #5a6c7d;
}

.wyceny-widget-pricing .ww-ip-logistyk {
    font-size: 12px;
    color: #1a4a7a;
}

.ww-ip-row {
    padding: 3px 4px;
}

.ww-ip-row:not(:last-child) {
    border-bottom: 1px dashed #e2e8f0;
}

.ww-uwagi-icon {
    color: #f59e0b;
    font-size: 14px;
    cursor: help;
}

.ww-uwagi-icon:hover {
    color: #d97706;
}

.ww-uwagi-empty {
    color: #cbd5e1;
}